-
-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathstringify.d.lua
More file actions
135 lines (133 loc) · 2.54 KB
/
Copy pathstringify.d.lua
File metadata and controls
135 lines (133 loc) · 2.54 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
---@meta _
---
---Render Lua values as readable source-like text.
---
---## Usage
---
---```lua
---local stringify = require("mods").stringify
---
---local t = { "first", name = "Ada"}
---
---print(stringify(t))
-----> {
-----> "first",
-----> name = "Ada"
-----> }
---```
---
---Render Lua values as readable source-like text.
---
---
---```lua
---local stringify = require("mods").stringify
---
---local t = {
--- "first",
--- "second",
--- name = "Ada",
--- ok = true,
--- nested = { value = 42 },
---}
---
---print(stringify(t))
-----> {
-----> "first",
-----> "second",
-----> name = "Ada",
-----> nested = {
-----> value = 42
-----> },
-----> ok = true
-----> }
---```
---
---### Key formatting
---
---Strings are quoted and reserved keys use bracket notation.
---
---```lua
---print(stringify({ name = "Ada", ["with space"] = true }))
-----> {
-----> ["with space"] = true,
-----> name = "Ada"
-----> }
---```
---
---### Cycle rendering
---
---Circular references render as `<cycle>`.
---
---```lua
---local t = {}
---t.self = t
---
---print(stringify(t))
-----> {
-----> self = <cycle>
-----> }
---```
---
---## Options
---
---### `omit_array_keys`
---
---Contiguous positive integer keys render as implicit array entries by
---default. Set `omit_array_keys = false` to keep them explicit.
---
---```lua
---print(stringify({ "first", nil, "third" }, { omit_array_keys = false }))
-----> {
-----> [1] = "first",
-----> [3] = "third"
-----> }
---```
---
---### `indent`
---
---`indent` controls the repeated indentation prefix. It defaults to two
---spaces.
---
---```lua
---print(stringify({ a = { b = true } }, { indent = ".." }))
-----> {
-----> a = {
-----> b = true
-----> }
-----> }
---```
---
---### `newline`
---
---`newline` controls the line separator. Use `newline = ""` for inline
---output.
---
---```lua
---print(stringify({ a = 1, b = 2 }, { newline = "" }))
-----> {a=1,b=2}
---```
---
---### `replacer`
---
---`replacer` can transform or remove values before they are rendered.
---
---```lua
---local function replacer(k, v)
--- if k == "secret" then
--- return nil
--- end
--- return v
---end
---
---print(stringify({ name = "Ada", secret = "hidden" }, { replacer = replacer }))
-----> {
-----> name = "Ada"
-----> }
---```
---
---@param value any Lua value to render.
---@param opts? {omit_array_keys?:boolean, indent?:string, newline?:string, replacer?:fun(k,v):(result:any)} Rendering options.
---@return string out Readable string representation.
---@nodiscard
local function stringify(value, opts) end
return stringify