Skip to content

Commit

Permalink
Renaming
Browse files Browse the repository at this point in the history
  • Loading branch information
ehmicky committed Mar 13, 2022
1 parent 43ddbd6 commit 42fdbe7
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 16 deletions.
16 changes: 8 additions & 8 deletions src/config/normalize/lib/wild_wild_path/get.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,26 +3,26 @@ import { iterate } from './iterate/main.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) {
return [...iterate(target, queryOrPath)]
export const list = function (target, queryOrPaths) {
return [...iterate(target, queryOrPaths)]
}

// 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 = find(target, queryOrPath)
export const get = function (target, queryOrPaths) {
const entry = find(target, queryOrPaths)
return entry === undefined ? undefined : entry.value
}

// Check if a property is not missing according to a query
export const has = function (target, queryOrPath) {
return find(target, queryOrPath) !== undefined
export const has = function (target, queryOrPaths) {
return find(target, queryOrPaths) !== undefined
}

// Find the first non-missing entry
const find = function (target, queryOrPath) {
const find = function (target, queryOrPaths) {
// eslint-disable-next-line fp/no-loops
for (const { value, missing } of iterate(target, queryOrPath)) {
for (const { value, missing } of iterate(target, queryOrPaths)) {
// eslint-disable-next-line max-depth
if (!missing) {
return { value }
Expand Down
4 changes: 2 additions & 2 deletions src/config/normalize/lib/wild_wild_path/parsing/serialize.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ import { parse } from './parse.js'
// Inverse of `parse()`
// When passing a query string, it is parsed and re-serialized to validate and
// normalize it.
export const serialize = function (queryOrPath) {
const paths = parse(queryOrPath)
export const serialize = function (queryOrPaths) {
const paths = parse(queryOrPaths)
return paths.map(serializePath).join(PATH_SEPARATOR)
}

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 @@ -6,8 +6,8 @@ import { handleMissingValue } from './iterate/expand.js'
import { reduceParents, setValue } from './set.js'

// Same as `set()` but removing a value
export const remove = function (target, queryOrPath) {
return reduceParents(target, queryOrPath, removeAnyEntry)
export const remove = function (target, queryOrPaths) {
return reduceParents(target, queryOrPaths, removeAnyEntry)
}

const removeAnyEntry = function (target, path, index) {
Expand Down
8 changes: 4 additions & 4 deletions src/config/normalize/lib/wild_wild_path/set.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,21 +5,21 @@ import { iterate } from './iterate/main.js'
import { parent } from './parsing/compare.js'

// Set a value to one or multiple properties in `target` using a query string.
export const set = function (target, queryOrPath, value) {
return reduceParents(target, queryOrPath, setEntry.bind(undefined, value))
export const set = function (target, queryOrPaths, value) {
return reduceParents(target, queryOrPaths, setEntry.bind(undefined, value))
}

// Modify a target object multiple times for each matched property.
// Ignore properties when one of their ancestors was matched too.
// Uses `iterate()` to keep memory consumption low.
export const reduceParents = function (target, queryOrPath, setFunc) {
export const reduceParents = function (target, queryOrPaths, setFunc) {
// eslint-disable-next-line fp/no-let
let newTarget = target

const paths = []

// eslint-disable-next-line fp/no-loops
for (const { path } of iterate(target, queryOrPath)) {
for (const { path } of iterate(target, queryOrPaths)) {
// eslint-disable-next-line max-depth
if (!parentIsSet(paths, path)) {
// eslint-disable-next-line fp/no-mutating-methods
Expand Down

0 comments on commit 42fdbe7

Please sign in to comment.