Skip to content

Commit

Permalink
Rename file
Browse files Browse the repository at this point in the history
  • Loading branch information
ehmicky committed Mar 13, 2022
1 parent afda58c commit d98b07f
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 9 deletions.
8 changes: 4 additions & 4 deletions src/config/normalize/lib/wild_wild_path/get.js
Original file line number Diff line number Diff line change
@@ -1,23 +1,23 @@
import { listEntries, normalizeEntry } from './entries.js'
import { iterate, normalizeEntry } from './iterate.js'

// Retrieve all properties in `target` matching a query string.
// Unlike `get|has()` it also return missing entries, letting consumers filter
// them or not.
export const list = function (target, queryOrPath) {
const entries = listEntries(target, queryOrPath)
const entries = iterate(target, queryOrPath)
return entries.map(normalizeEntry)
}

// Retrieve a single property's value in `target` matching a query string.
// Wildcards can be used, but only the first value is returned.
export const get = function (target, queryOrPath) {
const entry = listEntries(target, queryOrPath).find(isExisting)
const entry = iterate(target, queryOrPath).find(isExisting)
return entry === undefined ? undefined : entry.value
}

// Check if a property is not missing according to a query
export const has = function (target, queryOrPath) {
return listEntries(target, queryOrPath).some(isExisting)
return iterate(target, queryOrPath).some(isExisting)
}

const isExisting = function ({ missing }) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { getObjectTokenType } from './tokens/main.js'

// List all values (and their associated path) matching a specific query for
// on specific target value.
export const listEntries = function (target, queryOrPath) {
export const iterate = function (target, queryOrPath) {
const path = parse(queryOrPath)
return path.reduce(listTokenEntries, [
{ value: target, path: [], missing: false },
Expand Down
4 changes: 2 additions & 2 deletions src/config/normalize/lib/wild_wild_path/remove.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@ import omit from 'omit.js'

import { setArray } from '../../../../utils/set.js'

import { listEntries, handleMissingValue } from './entries.js'
import { iterate, handleMissingValue } from './iterate.js'
import { setValue } from './set.js'

// Same as `set()` but removing a value
export const remove = function (target, queryOrPath) {
const entries = listEntries(target, queryOrPath)
const entries = iterate(target, queryOrPath)
return entries.some(hasRootPath)
? undefined
: entries.reduce(
Expand Down
4 changes: 2 additions & 2 deletions src/config/normalize/lib/wild_wild_path/set.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import { setArray } from '../../../../utils/set.js'

import { listEntries, handleMissingValue } from './entries.js'
import { iterate, handleMissingValue } from './iterate.js'

// Set a value to one or multiple properties in `target` using a query string
export const set = function (target, queryOrPath, value) {
const entries = listEntries(target, queryOrPath)
const entries = iterate(target, queryOrPath)
return entries.reduce(
(targetA, entry) => setEntry(targetA, entry.path, value, 0),
target,
Expand Down

0 comments on commit d98b07f

Please sign in to comment.