Skip to content

Commit 3e24966

Browse files
committed
Serializer now has better , placements
1 parent f45fae2 commit 3e24966

File tree

1 file changed

+15
-4
lines changed

1 file changed

+15
-4
lines changed

src/serialize.lua

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,12 @@ local function isMetaKey(key, useMetaKeys)
3434
return useMetaKeys and type(key) == "string" and key:match(ignoredKeysPattern)
3535
end
3636

37+
local function insertIfNotEmpty(t, s)
38+
if s and s ~= "" then
39+
table.insert(t, s)
40+
end
41+
end
42+
3743
function serialize.countKeys(t, useMetaKeys)
3844
local numerical = 0
3945
local total = 0
@@ -249,14 +255,19 @@ function serialize.serialize(t, pretty, sortKeys, useMetaKeys, seen, depth, succ
249255
local entryValues = serialize.getEntries(entries, sortKeys)
250256
local bracketedNumberValues = serialize.getEntries(bracketedNumerEntries, sortKeys)
251257

252-
local noKeyConent = table.concat(noKeyEntries, lineSep)
258+
local noKeyContent = table.concat(noKeyEntries, lineSep)
253259
local bracketNumberContent = table.concat(bracketedNumberValues, lineSep)
254260
local keyValueContent = table.concat(entryValues, lineSep)
255261

256-
local noKeyToBracketedSep = #noKeyConent > 0 and lineSep or ""
257-
local bracketToKeySep = #bracketNumberContent > 0 and lineSep or ""
262+
local parts = {}
263+
264+
insertIfNotEmpty(parts, noKeyContent)
265+
insertIfNotEmpty(parts, bracketNumberContent)
266+
insertIfNotEmpty(parts, keyValueContent)
267+
268+
local content = table.concat(parts, lineSep)
258269

259-
return success, "{" .. newline .. noKeyConent .. noKeyToBracketedSep .. bracketNumberContent .. bracketToKeySep .. keyValueContent .. newline .. closingPadding .. "}"
270+
return success, "{" .. newline .. content.. newline .. closingPadding .. "}"
260271
end
261272

262273
function serialize.unserialize(s)

0 commit comments

Comments
 (0)