22
33local singleComment = " singleComment"
44local multiComment = " multiComment"
5+ --- @return " "
56local stripWithoutWhitespace = function ()
67 return " "
78end
89
10+ --- @param str string
11+ --- @param from ? integer
12+ --- @param to ? integer
13+ --- @return string
914local function slice (str , from , to )
1015 from = from or 1
1116 to = to or # str
1217 return str :sub (from , to )
1318end
1419
20+ --- @param str string
21+ --- @param from ? integer
22+ --- @param to ? integer
23+ --- @return string , integer count
1524local stripWithWhitespace = function (str , from , to )
1625 return slice (str , from , to ):gsub (" %S" , " " )
1726end
1827
28+ --- @param jsonString string
29+ --- @param quotePosition integer
30+ --- @return boolean
1931local isEscaped = function (jsonString , quotePosition )
2032 local index = quotePosition - 1
2133 local backslashCount = 0
@@ -27,13 +39,14 @@ local isEscaped = function(jsonString, quotePosition)
2739 return backslashCount % 2 == 1 and true or false
2840end
2941
42+ --- @class PlenaryJson
3043local M = {}
3144
3245-- Strips any json comments from a json string.
3346-- The resulting string can then be used by `vim.fn.json_decode`
3447--
3548--- @param jsonString string
36- --- @param options table
49+ --- @param options ? { whitespace ?: boolean }
3750--- * whitespace:
3851--- - defaults to true
3952--- - when true, comments will be replaced by whitespace
@@ -43,6 +56,7 @@ function M.json_strip_comments(jsonString, options)
4356 local strip = options .whitespace == false and stripWithoutWhitespace or stripWithWhitespace
4457
4558 local insideString = false
59+ --- @type " multiComment" | " singleComment" | false
4660 local insideComment = false
4761 local offset = 1
4862 local result = " "
0 commit comments