Path API
Path.parse(...) returns a real Path instance, not just an array of segments. This page focuses on the Path type itself. For syntax, matching behavior, and accessor usage, use the guide pages.
Attributes
In addition to methods like toString() and toArr(), a Path instance also exposes readable structural metadata:
| Property | Meaning |
|---|---|
length | Number of path segments, meaningful for non-match paths |
entire | Full path string or regular expression |
segments | Parsed path segments |
isMatchPattern | Whether this is a match pattern |
isWildMatchPattern | Whether wildcard semantics are involved |
haveRelativePattern | Whether relative-path syntax is present |
haveExcludePattern | Whether exclude patterns are present |
isRegExp | Whether it was created from a regular expression |
tree | Parsed AST |
matchScore | Score from the most recent match |
Example:
const pattern = Path.parse('*(!basic.name,versionTag)')
pattern.isMatchPattern
// true
pattern.haveExcludePattern
// trueInstance methods
toString
Signature
interface toString {
(): string
}Examples: Quick Start / Path instance operations / Convert back to string or array
toArr
Signature
interface toArr {
(): Array<string | number>
}Examples: Quick Start / Path instance operations / Convert back to string or array
concat
Signature
interface concat {
(...args: Pattern[]): Path
}Examples: Quick Start / Path instance operations / Concatenate and slice
slice
Signature
interface slice {
(start?: number, end?: number): Path
}Examples: Quick Start / Path instance operations / Concatenate and slice
parent
Signature
interface parent {
(): Path
}Examples: Quick Start / Path instance operations / Concatenate and slice
push
Signature
interface push {
(...items: Pattern[]): Path
}These methods look array-like, but they return a new Path.
Examples: Quick Start / Path instance operations / Array-like operations
pop
Signature
interface pop {
(): Path
}Examples: Quick Start / Path instance operations / Array-like operations
splice
Signature
interface splice {
(
start: number,
deleteCount?: number,
...items: Array<string | number>
): Path
}Examples: Quick Start / Path instance operations / Array-like operations
forEach
Signature
interface forEach {
(callback: (key: string | number) => any): void
}Examples: Quick Start / Path instance operations / Iterate over segments
map
Signature
interface map {
(callback: (key: string | number) => any): any[]
}Examples: Quick Start / Path instance operations / Iterate over segments
reduce
Signature
interface reduce {
<T>(
callback: (buffer: T, item: string | number, index: number) => T,
initial: T
): T
}Examples: Quick Start / Path instance operations / Iterate over segments
transform
Signature
interface transform {
<T>(regexp: string | RegExp, callback: (...args: string[]) => T): T
}transform filters matching segments and passes them to a callback.
Examples: Matching / transform
includes
Signature
interface includes {
(pattern: Pattern): boolean
}includes checks whether another plain path is a prefix child-path of the current one.
Examples: Matching / includes
matchAliasGroup
Signature
interface matchAliasGroup {
(name: Pattern, alias: Pattern): boolean
}This method is used heavily by core to compare a field name and alias against the same pattern.
Examples: Matching / matchAliasGroup
Static methods
match
Signature
interface match {
(pattern: Pattern): (target: Pattern) => boolean
}Examples: Matching / Path.match
transform
Signature
interface transform {
<T>(
pattern: Pattern,
regexp: string | RegExp,
callback: (...args: string[]) => T
): T
}Examples: Matching / transform
getIn
Signature
interface getIn {
(source: any, pattern: Pattern): any
}Examples: Accessors / getIn
setIn
Signature
interface setIn {
(source: any, pattern: Pattern, value: any): any
}Examples: Accessors / setIn
deleteIn
Signature
interface deleteIn {
(source: any, pattern: Pattern): any
}Examples: Accessors / deleteIn
existIn
Signature
interface existIn {
(source: any, pattern: Pattern, start?: number | Path): boolean
}Examples: Accessors / existIn
ensureIn
Signature
interface ensureIn {
(source: any, pattern: Pattern, defaultValue?: any): any
}Examples: Accessors / ensureIn
Notes
If the current instance is itself a match pattern or regular-expression path, many array-style operations no longer have a deterministic meaning and will throw:
concatslicepopspliceforEachmapreducetransform
Example:
const wildcard = Path.parse('*')
wildcard.concat('a')
// throw ErrorThat is a useful mental model as well: plain paths behave like structured values, while match patterns behave more like compiled rules.