Skip to content

Commit

Permalink
Rename parse*() to normalize*()
Browse files Browse the repository at this point in the history
  • Loading branch information
ehmicky committed Mar 20, 2022
1 parent 77dec24 commit 9887ea3
Show file tree
Hide file tree
Showing 10 changed files with 25 additions and 22 deletions.
4 changes: 2 additions & 2 deletions src/config/normalize/lib/modify.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { callValueFunc, callUserFunc, getValidateExampleError } from './call.js'
import { resolvePath } from './path.js'
import { transformValue } from './transform.js'
import { getWarnings } from './warn.js'
import { parsePath } from './wild_wild_parser/main.js'
import { normalizePath } from './wild_wild_parser/main.js'
import { has } from './wild_wild_path/main.js'

// Once the initial value has been computed, apply validation and transforms,
Expand Down Expand Up @@ -70,6 +70,6 @@ const renameProp = async function (value, rename, opts) {
return
}

const renamedPath = parsePath(renameReturn)
const renamedPath = normalizePath(renameReturn)
return has(opts.funcOpts.config, renamedPath) ? undefined : renamedPath
}
4 changes: 2 additions & 2 deletions src/config/normalize/lib/opts.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { callUserFunc } from './call.js'
import { getCwd } from './cwd.js'
import { applyMoves } from './move.js'
import { getPrefix, DEFAULT_PREFIX } from './prefix.js'
import { parsePath, serializePath } from './wild_wild_parser/main.js'
import { normalizePath, serializePath } from './wild_wild_parser/main.js'

// Retrieve `opts` passed to most methods.
// `funcOpts` are passed to user-provided functions.
Expand Down Expand Up @@ -53,7 +53,7 @@ const computeParent = async function (opts, moves, parent) {
// By default, there are none.
const appendParentToName = async function (parent, opts) {
const parentA = await callUserFunc(parent, opts)
const parentPath = parsePath(parentA)
const parentPath = normalizePath(parentA)
return [...parentPath, ...opts.funcOpts.originalPath]
}

Expand Down
4 changes: 2 additions & 2 deletions src/config/normalize/lib/rule.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { parseQuery, serializeQuery } from './wild_wild_parser/main.js'
import { normalizeQuery, serializeQuery } from './wild_wild_parser/main.js'
import { get } from './wild_wild_path/main.js'

// Validate and normalize rules.
Expand All @@ -10,7 +10,7 @@ export const normalizeRules = function (rules) {

const parseName = function ({ name, ...rule }) {
const nameQuery = serializeQuery(name)
const namePath = parseQuery(name)
const namePath = normalizeQuery(name)
return { ...rule, nameQuery, namePath }
}

Expand Down
4 changes: 2 additions & 2 deletions src/config/normalize/lib/transform.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import isPlainObj from 'is-plain-obj'
import pReduce from 'p-reduce'

import { callValueFunc } from './call.js'
import { parsePath } from './wild_wild_parser/main.js'
import { normalizePath } from './wild_wild_parser/main.js'

// Apply `transform(value, opts)` which transforms the value set by the user.
// If can also delete it by returning `undefined`.
Expand Down Expand Up @@ -58,7 +58,7 @@ const isTransformMove = function (transformReturn) {
}

const getTransformMove = function ({ value, newProp }) {
const newPropA = parsePath(newProp)
const newPropA = normalizePath(newProp)
return newPropA.length === 0 ? {} : { value, newProp: newPropA }
}

Expand Down
6 changes: 3 additions & 3 deletions src/config/normalize/lib/wild_wild_parser/compare.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { validatePath } from './normalize.js'
import { parseQuery } from './parse.js'
import { normalizeQuery } from './parse.js'
import { getObjectTokenType } from './tokens/main.js'

// Check if two queries are equal.
Expand All @@ -8,8 +8,8 @@ import { getObjectTokenType } from './tokens/main.js'
// - Unions, e.g. `a b` === `b a`
// - Duplicates, e.g. `a a` === `a`
export const isSameQuery = function (queryA, queryB) {
const queryArraysA = parseQuery(queryA)
const queryArraysB = parseQuery(queryB)
const queryArraysA = normalizeQuery(queryA)
const queryArraysB = normalizeQuery(queryB)
return (
queryArraysA.length === queryArraysB.length &&
queryArraysA.every((queryArrayA) =>
Expand Down
2 changes: 1 addition & 1 deletion src/config/normalize/lib/wild_wild_parser/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,6 @@ export {
isSameToken,
isParentPath,
} from './compare.js'
export { parseQuery, parsePath } from './parse.js'
export { normalizeQuery, normalizePath } from './parse.js'
export { serializeQuery, serializePath } from './serialize.js'
export { getTokenType } from './tokens/main.js'
6 changes: 3 additions & 3 deletions src/config/normalize/lib/wild_wild_parser/parse.js
Original file line number Diff line number Diff line change
Expand Up @@ -82,13 +82,13 @@ import { parseQueryString } from './query.js'
// - I.e. query or path syntax errors, or wrong arguments
// - But queries matching nothing do not throw: instead they return nothing
// Parse a path
export const parsePath = function (query) {
const queryArrays = parseQuery(query)
export const normalizePath = function (query) {
const queryArrays = normalizeQuery(query)
return normalizePathShape(queryArrays)
}

// Parse a query string or array
export const parseQuery = function (query) {
export const normalizeQuery = function (query) {
return isQueryString(query)
? safeParseQueryString(query)
: normalizeQueryArrays(query)
Expand Down
6 changes: 3 additions & 3 deletions src/config/normalize/lib/wild_wild_parser/serialize.js
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
import { parseQuery, parsePath } from './parse.js'
import { normalizeQuery, normalizePath } from './parse.js'
import { TOKEN_SEPARATOR, ARRAY_SEPARATOR } from './tokens/escape.js'
import { getObjectTokenType } from './tokens/main.js'

// Inverse of `parseQuery()`
// When passing a query string, it is parsed and re-serialized to validate and
// normalize it.
export const serializeQuery = function (query) {
const queryArrays = parseQuery(query)
const queryArrays = normalizeQuery(query)
return queryArrays.map(serializeQueryArray).join(ARRAY_SEPARATOR)
}

// Inverse of `parsePath()`
export const serializePath = function (query) {
const path = parsePath(query)
const path = normalizePath(query)
return serializeQueryArray(path)
}

Expand Down
4 changes: 2 additions & 2 deletions src/config/normalize/lib/wild_wild_path/iterate/main.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { parseQuery } from '../../wild_wild_parser/main.js'
import { normalizeQuery } from '../../wild_wild_parser/main.js'

import { iterateChildEntries } from './children.js'
import { removeDuplicates } from './duplicate.js'
Expand All @@ -18,7 +18,7 @@ export const iterate = function* (target, query, opts) {
}

const getRootEntries = function (target, query) {
const queryArrays = parseQuery(query)
const queryArrays = normalizeQuery(query)
return queryArrays.map((queryArray) => ({
queryArray,
value: target,
Expand Down
7 changes: 5 additions & 2 deletions src/config/plugin/lib/shared.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
import { parseQuery } from '../../normalize/lib/wild_wild_parser/main.js'
import { normalizeQuery } from '../../normalize/lib/wild_wild_parser/main.js'
import { pick } from '../../normalize/lib/wild_wild_utils/main.js'

// Retrieve top-level properties that are shared with all plugins of a specific
// type. Those are merged with plugin-specific properties.
export const getSharedConfig = function (sharedConfig, item = []) {
const sharedPropNames = [...new Set(item.map(getRuleName))]
const sharedConfigA = pick(sharedConfig, sharedPropNames.flatMap(parseQuery))
const sharedConfigA = pick(
sharedConfig,
sharedPropNames.flatMap(normalizeQuery),
)
return { sharedConfig: sharedConfigA, sharedPropNames }
}

Expand Down

0 comments on commit 9887ea3

Please sign in to comment.