Skip to content

Commit

Permalink
Add equals()
Browse files Browse the repository at this point in the history
  • Loading branch information
ehmicky committed Mar 6, 2022
1 parent 03dbd50 commit b0aa8cc
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/config/normalize/lib/star_dot_path/main.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
export { list, get } from './get.js'
export { has } from './has.js'
export { parent } from './parsing/compare.js'
export { equals, parent } from './parsing/compare.js'
export { serialize } from './parsing/serialize.js'
export { parse } from './parsing/parse.js'
export { set, pick, transform } from './set.js'
10 changes: 10 additions & 0 deletions src/config/normalize/lib/star_dot_path/parsing/compare.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,15 @@
import { parse } from './parse.js'

// Check if two queries are equal, after normalization
export const equals = function (queryOrPathA, queryOrPathB) {
const pathA = parse(queryOrPathA)
const pathB = parse(queryOrPathB)
return (
pathA.length === pathB.length &&
pathA.every((tokenA, index) => isSameToken(tokenA, pathB[index]))
)
}

// Check if a query is a parent of another
export const parent = function (parentQueryOrPath, childQueryOrPath) {
const parentPath = parse(parentQueryOrPath)
Expand Down

0 comments on commit b0aa8cc

Please sign in to comment.