Skip to content

Commit

Permalink
Move files
Browse files Browse the repository at this point in the history
  • Loading branch information
ehmicky committed Mar 6, 2022
1 parent 0922f10 commit 8560a0a
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 11 deletions.
13 changes: 3 additions & 10 deletions src/config/normalize/lib/star_dot_path/parsing/serialize.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import { parse } from './parse.js'
import { isAnyToken } from './tokens/any.js'
import { isIndexToken, serializeIndexToken } from './tokens/array.js'
import { serializePropToken } from './tokens/prop.js'
import { isRegExpToken, serializeRegExpToken } from './tokens/regexp.js'
import { SEPARATOR, ANY, escapeSpecialChars } from './tokens/special.js'
import { SEPARATOR, ANY } from './tokens/special.js'

// Inverse of `parse()`
// When passing a query string, it is parsed and re-serialized to validate and
Expand All @@ -29,13 +30,5 @@ const serializeToken = function (token, index) {
return serializeRegExpToken(token)
}

return serializeStringToken(token, index)
}

const serializeStringToken = function (token, index) {
if (token === '' && index === 0) {
return SEPARATOR
}

return escapeSpecialChars(token)
return serializePropToken(token, index)
}
11 changes: 11 additions & 0 deletions src/config/normalize/lib/star_dot_path/parsing/tokens/prop.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import { SEPARATOR, escapeSpecialChars } from './special.js'

// Check if a token is a property name string
export const isPropToken = function (token) {
return typeof token === 'string'
}

// Serialize a property token into a string
export const serializePropToken = function (token, index) {
return token === '' && index === 0 ? SEPARATOR : escapeSpecialChars(token)
}
3 changes: 2 additions & 1 deletion src/config/normalize/lib/star_dot_path/parsing/validate.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { inspect } from 'util'

import { isAnyToken } from './tokens/any.js'
import { isIndexToken } from './tokens/array.js'
import { isPropToken } from './tokens/prop.js'
import { isRegExpToken } from './tokens/regexp.js'

// Most methods accept both query and path syntaxes.
Expand Down Expand Up @@ -39,7 +40,7 @@ const validateToken = function (token, path) {

const isValidToken = function (token) {
return (
typeof token === 'string' ||
isPropToken(token) ||
isIndexToken(token) ||
isAnyToken(token) ||
isRegExpToken(token)
Expand Down

0 comments on commit 8560a0a

Please sign in to comment.