2
2
3
3
local singleComment = " singleComment"
4
4
local multiComment = " multiComment"
5
+ --- @return " "
5
6
local stripWithoutWhitespace = function ()
6
7
return " "
7
8
end
8
9
10
+ --- @param str string
11
+ --- @param from ? integer
12
+ --- @param to ? integer
13
+ --- @return string
9
14
local function slice (str , from , to )
10
15
from = from or 1
11
16
to = to or # str
12
17
return str :sub (from , to )
13
18
end
14
19
20
+ --- @param str string
21
+ --- @param from ? integer
22
+ --- @param to ? integer
23
+ --- @return string , integer count
15
24
local stripWithWhitespace = function (str , from , to )
16
25
return slice (str , from , to ):gsub (" %S" , " " )
17
26
end
18
27
28
+ --- @param jsonString string
29
+ --- @param quotePosition integer
30
+ --- @return boolean
19
31
local isEscaped = function (jsonString , quotePosition )
20
32
local index = quotePosition - 1
21
33
local backslashCount = 0
@@ -27,13 +39,14 @@ local isEscaped = function(jsonString, quotePosition)
27
39
return backslashCount % 2 == 1 and true or false
28
40
end
29
41
42
+ --- @class PlenaryJson
30
43
local M = {}
31
44
32
45
-- Strips any json comments from a json string.
33
46
-- The resulting string can then be used by `vim.fn.json_decode`
34
47
--
35
48
--- @param jsonString string
36
- --- @param options table
49
+ --- @param options ? { whitespace ?: boolean }
37
50
--- * whitespace:
38
51
--- - defaults to true
39
52
--- - when true, comments will be replaced by whitespace
@@ -43,6 +56,7 @@ function M.json_strip_comments(jsonString, options)
43
56
local strip = options .whitespace == false and stripWithoutWhitespace or stripWithWhitespace
44
57
45
58
local insideString = false
59
+ --- @type " multiComment" | " singleComment" | false
46
60
local insideComment = false
47
61
local offset = 1
48
62
local result = " "
0 commit comments