Skip to content

Commit

Permalink
Use SYM for *
Browse files Browse the repository at this point in the history
  • Loading branch information
ehmicky committed Feb 27, 2022
1 parent df2e6e6 commit 64e4d98
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 11 deletions.
11 changes: 3 additions & 8 deletions src/config/normalize/lib/star_dot_path/parsing/node.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import { ANY_TOKEN } from './special.js'

// Check if at least one node has some ANY tokens
export const isAnyNodes = function (nodes) {
return nodes.some(isAnyNode)
Expand All @@ -10,12 +12,5 @@ export const isAnyNode = function (node) {

// Check if a token is ANY
export const isAnyToken = function (token) {
return token.type === ANY_TYPE
}

// Create an ANY token
export const createAnyToken = function () {
return { type: ANY_TYPE }
return token === ANY_TOKEN
}

const ANY_TYPE = 'any'
5 changes: 2 additions & 3 deletions src/config/normalize/lib/star_dot_path/parsing/parse.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import { createAnyToken } from './node.js'
import { pathToNodes } from './path.js'
import { ESCAPE, SEPARATOR, ANY } from './special.js'
import { ESCAPE, SEPARATOR, ANY, ANY_TOKEN } from './special.js'

// Parse a query string into an array of nodes.
// This is similar to JSON paths but:
Expand Down Expand Up @@ -74,7 +73,7 @@ export const parse = function (query) {
chars = ''
}

node.push(createAnyToken())
node.push(ANY_TOKEN)
continue
}

Expand Down
2 changes: 2 additions & 0 deletions src/config/normalize/lib/star_dot_path/parsing/special.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,7 @@
export const ESCAPE = '\\'
export const SEPARATOR = '.'
export const ANY = '*'
// Tokens for special characters
export const ANY_TOKEN = Symbol.for('*')
// Matches any special characters
export const SPECIAL_CHARS_REGEXP = /[\\.*]/gu

0 comments on commit 64e4d98

Please sign in to comment.