Skip to content

Commit

Permalink
Add serializePath()
Browse files Browse the repository at this point in the history
  • Loading branch information
ehmicky committed Mar 13, 2022
1 parent fb5c03b commit 614b157
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/config/normalize/lib/wild_wild_path/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ export {
isSameToken,
isParentPath,
} from './parsing/compare.js'
export { serialize } from './parsing/serialize.js'
export { serialize, serializePath } from './parsing/serialize.js'
export { parse, parsePath } from './parsing/parse.js'
export { remove } from './remove.js'
export { set } from './set.js'
8 changes: 7 additions & 1 deletion src/config/normalize/lib/wild_wild_path/parsing/serialize.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { TOKEN_SEPARATOR, ARRAY_SEPARATOR } from '../tokens/escape.js'
import { getObjectTokenType } from '../tokens/main.js'

import { parse } from './parse.js'
import { parse, parsePath } from './parse.js'

// Inverse of `parse()`
// When passing a query string, it is parsed and re-serialized to validate and
Expand All @@ -11,6 +11,12 @@ export const serialize = function (query) {
return queryArrays.map(serializeQueryArray).join(ARRAY_SEPARATOR)
}

// Inverse of `parsePath()`
export const serializePath = function (query) {
const path = parsePath(query)
return serializeQueryArray(path)
}

const serializeQueryArray = function (queryArray) {
return queryArray.every(isEmptyToken)
? TOKEN_SEPARATOR.repeat(queryArray.length + 1)
Expand Down

0 comments on commit 614b157

Please sign in to comment.