Skip to content

Commit

Permalink
Improve serialization
Browse files Browse the repository at this point in the history
  • Loading branch information
ehmicky committed Mar 6, 2022
1 parent 9734db3 commit 9990acd
Showing 1 changed file with 13 additions and 3 deletions.
16 changes: 13 additions & 3 deletions src/config/normalize/lib/wild_wild_path/parsing/serialize.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { TOKEN_SEPARATOR } from '../tokens/escape.js'
import { TOKEN_SEPARATOR, PATH_SEPARATOR } from '../tokens/escape.js'
import { getObjectTokenType } from '../tokens/main.js'

import { parse } from './parse.js'
Expand All @@ -7,8 +7,18 @@ import { parse } from './parse.js'
// When passing a query string, it is parsed and re-serialized to validate and
// normalize it.
export const serialize = function (queryOrPath) {
const path = parse(queryOrPath)
return path.map(serializeToken).join(TOKEN_SEPARATOR)
const paths = parse(queryOrPath)
return paths.map(serializePath).join(PATH_SEPARATOR)
}

const serializePath = function (path) {
return path.every(isEmptyToken)
? TOKEN_SEPARATOR.repeat(path.length + 1)
: path.map(serializeToken).join(TOKEN_SEPARATOR)
}

const isEmptyToken = function (token) {
return token === ''
}

const serializeToken = function (token, index) {
Expand Down

0 comments on commit 9990acd

Please sign in to comment.