Skip to content

Commit

Permalink
Improve serialize()
Browse files Browse the repository at this point in the history
  • Loading branch information
ehmicky committed Mar 20, 2022
1 parent fccb2d4 commit bbb53be
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 10 deletions.
2 changes: 1 addition & 1 deletion src/config/normalize/lib/rule.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ export const normalizeRules = function (rules) {

const parseName = function ({ name, ...rule }) {
const namePath = normalizeQuery(name)
const nameQuery = serializeQuery(name)
const nameQuery = serializeQuery(namePath)
return { ...rule, namePath, nameQuery }
}

Expand Down
16 changes: 7 additions & 9 deletions src/config/normalize/lib/wild_wild_parser/serialize.js
Original file line number Diff line number Diff line change
@@ -1,19 +1,17 @@
import { normalizeQuery, normalizePath } from './normalize.js'
import { TOKEN_SEPARATOR, ARRAY_SEPARATOR } from './tokens/escape.js'
import { getObjectTokenType } from './tokens/main.js'
import { normalizeQueryArrays, normalizeArrayPath } from './validate.js'

// Inverse of `parseQuery()`
// When passing a query string, it is parsed and re-serialized to validate and
// normalize it.
export const serializeQuery = function (query) {
const queryArrays = normalizeQuery(query)
return queryArrays.map(serializeQueryArray).join(ARRAY_SEPARATOR)
export const serializeQuery = function (queryArrays) {
const queryArraysA = normalizeQueryArrays(queryArrays, queryArrays)
return queryArraysA.map(serializeQueryArray).join(ARRAY_SEPARATOR)
}

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

const serializeQueryArray = function (queryArray) {
Expand Down

0 comments on commit bbb53be

Please sign in to comment.