import { zTag } from '../internal/zTag.js'; import type { Primitive } from './isPrimitive.js'; import type { Distribute } from '../internal/types/distribute.js'; import type { Int, List } from '../internal/types/tools/index.js'; type Escape< S extends string | number, TQuoteType extends 'single' | 'double' = 'single', > = `${S}` extends `${infer L}${infer R}` ? L extends (TQuoteType extends 'single' ? "'" : '"') ? `\\${L}${Escape}` : L extends '\\' ? `\\\\${Escape}` : `${L}${Escape}` : S; type Alphabet = | 'a' | 'b' | 'c' | 'd' | 'e' | 'f' | 'g' | 'h' | 'i' | 'j' | 'k' | 'l' | 'm' | 'n' | 'o' | 'p' | 'q' | 'r' | 's' | 't' | 'u' | 'v' | 'w' | 'x' | 'y' | 'z' | 'A' | 'B' | 'C' | 'D' | 'E' | 'F' | 'G' | 'H' | 'I' | 'J' | 'K' | 'L' | 'M' | 'N' | 'O' | 'P' | 'Q' | 'R' | 'S' | 'T' | 'U' | 'V' | 'W' | 'X' | 'Y' | 'Z'; type IsIdentifierName = `${S}` extends `${infer L}${infer R}` ? L extends Alphabet ? _IsIdentifierName : L extends '_' ? _IsIdentifierName : L extends '$' ? _IsIdentifierName : false : true; type _IsIdentifierName = `${S}` extends `${infer L}${infer R}` ? L extends ' ' | '\t' | '\n' | '\r' | '\v' | '\f' ? false : L extends `${number}` ? _IsIdentifierName : L extends '_' ? _IsIdentifierName : L extends '$' ? _IsIdentifierName : L extends Alphabet ? _IsIdentifierName : false : true; type ValueOf = T[keyof T]; type ArrayKeys = keyof []; type ParsePath = _ParsePath; type _ParsePath< S extends string, TPrev extends string = '', TPrevChar extends string = '', TInString extends boolean = false, TStringQuote extends "'" | '"' = "'", TResult extends readonly string[] = [], > = S extends `${infer L}${infer R}` ? TInString extends true ? L extends '\\' ? TPrevChar extends '\\' ? _ParsePath : _ParsePath : L extends TStringQuote ? TPrevChar extends '\\' ? _ParsePath : _ParsePath> : _ParsePath : L extends "'" | '"' ? TPrevChar extends '[' ? _ParsePath : _ParsePath> : L extends '[' ? _ParsePath> : L extends ']' ? TPrevChar extends "'" | '"' ? _ParsePath : _ParsePath> : L extends '.' ? _ParsePath> : _ParsePath : AppendPrev; type AppendPrev = S extends '' ? AS : [...AS, S]; export type BasePath = _BasePath[0]> extends `.${infer R}` ? R : _BasePath[0]>; type _BasePath = __BasePath[0]>; type __BasePath = O extends readonly Primitive[] ? number extends O['length'] ? `[${number}]` : undefined extends _BasePathOfObjectLike ? Exclude<_BasePathOfObjectLike, undefined> : _BasePathOfObjectLike : O extends object ? undefined extends _BasePathOfObjectLike ? Exclude<_BasePathOfObjectLike, undefined> : _BasePathOfObjectLike : ''; type _BasePathOfObjectLike = ValueOf<{ [P in keyof O as P extends string | number ? O extends readonly unknown[] ? number extends O['length'] ? P extends Exclude ? never : P : P extends ArrayKeys ? never : P : P : never]: P extends string | number ? `${P}` extends `${number}` ? `[${P}]` | `[${P}]${_BasePath}` : P extends string ? IsIdentifierName

extends true ? `.${P}` | `.${P}${_BasePath}` : `['${Escape

}']` | `['${Escape

}']${_BasePath}` : never : never; }>; export type BasePathArray = _BasePathArray[0]>; type _BasePathArray = __BasePathArray[0]>; type __BasePathArray = O extends object ? undefined extends _BasePathArrayOfObjectLike ? Exclude<_BasePathArrayOfObjectLike, undefined> : _BasePathArrayOfObjectLike : readonly []; type _BasePathArrayOfObjectLike = ValueOf<{ [P in keyof O as P extends string | number ? O extends readonly unknown[] ? number extends O['length'] ? P extends Exclude ? never : P : P extends ArrayKeys ? never : P : P : never]: P extends string | number ? `${P}` extends `${number}` ? readonly [`${P}`] | readonly [`${P}`, ..._BasePathArray] : P extends string ? readonly [P] | readonly [P, ..._BasePathArray] : readonly [] : readonly []; }>; export type OmitByPath = _OmitByPath< Distribute<[O]>[0], P extends string ? ParsePath

: P extends readonly string[] ? P : never >; type _Omit = T extends readonly unknown[] ? number extends T['length'] ? T : K extends keyof T ? K extends `${number}` ? List.DropIndex> : T : T : K extends keyof T ? Omit : T; type _OmitByPath = P extends readonly [infer L] ? L extends keyof O ? _Omit : O : P extends readonly [infer L, ...infer R] ? undefined extends O ? L extends keyof Exclude ? | (_Omit, L> & { [K in L]: _OmitByPath[L], R>; }) | undefined : O : L extends keyof O ? _Omit & { [K in L]: _OmitByPath; } : O : never; export type GetByPath = _GetByPath< Distribute<[O]>[0], P extends string ? ParsePath

: P extends readonly string[] ? P : never >; type _GetByPath = P extends readonly [] ? O : P extends readonly [infer L, ...infer R] ? undefined extends O ? __GetByPath, L, R> | undefined : __GetByPath : undefined; type __GetByPath< O, L, R extends readonly unknown[], > = O extends readonly unknown[] ? `${number}` extends L ? _GetByPath | undefined : L extends `${number}` ? number extends O['length'] ? _GetByPath | undefined : L extends keyof O ? _GetByPath : undefined : L extends keyof O ? _GetByPath : undefined : L extends keyof O ? _GetByPath : undefined; type PathExtension

= ( value: P extends BasePath | BasePathArray ? GetByPath : never, ) => (o: O) => boolean; type PathExtensionW

= ( value: P extends BasePath | BasePathArray ? unknown : never, ) => (o: O) => boolean; type PathExtensions

= { /** * Returns `true` if the value of the path satisfies the predicate. * @param pred The predicate to satisfy. * * @example * ```typescript * const objs = [{ a: { b: [1, 2, 3] } }, { a: { b: [4, 5, 6] } }]; * objs.filter(path('a.b[0]').satisfies((value) => value > 1)); // => [{ a: { b: [4, 5, 6] } }] * ``` */ satisfies: ( pred: P extends BasePath | BasePathArray ? (value: GetByPath) => boolean : never, ) => (o: O) => boolean; /** * Returns `true` if the value of the path is equal to the given value (using `===`). * @param value The value to compare to. * * @example * ```typescript * const objs = [{ a: { b: [1, 2, 3] } }, { a: { b: [4, 5, 6] } }]; * objs.filter(path('a.b[0]').eq(1)); // => [{ a: { b: [1, 2, 3] } }] * ``` */ eq: PathExtension

; /** * Returns `true` if the value of the path is equal to the given value (using `===`). * * It is the same as `eq` but the value is not checked at compile time. * The `W` postfix stands for "wide". * @param value The value to compare to. * * @example * ```typescript * const objs = [{ a: { b: [1, 2, 3] } }, { a: { b: [4, 5, 6] } }]; * objs.filter(path('a.b[0]').eqW(1)); // => [{ a: { b: [1, 2, 3] } }] * ``` */ eqW: PathExtensionW

; /** * Returns `true` if the value of the path is not equal to the given value (using `!==`). * @param value The value to compare to. * * @example * ```typescript * const objs = [{ a: { b: [1, 2, 3] } }, { a: { b: [4, 5, 6] } }]; * objs.filter(path('a.b[0]').notEq(1)); // => [{ a: { b: [4, 5, 6] } }] * ``` */ notEq: PathExtension

; /** * Returns `true` if the value of the path is not equal to the given value (using `!==`). * * It is the same as `notEq` but the value is not checked at compile time. * The `W` postfix stands for "wide". * @param value The value to compare to. * * @example * ```typescript * const objs = [{ a: { b: [1, 2, 3] } }, { a: { b: [4, 5, 6] } }]; * objs.filter(path('a.b[0]').notEqW(1)); // => [{ a: { b: [4, 5, 6] } }] * ``` */ notEqW: PathExtensionW

; /** * Returns `true` if the value of the path is loosely equal to the given value (using `==`). * @param value The value to compare to. * * @example * ```typescript * const objs = [{ a: { b: [1, 2, 3] } }, { a: { b: ['1', '2', '3'] } }]; * objs.filter(path('a.b[0]').looselyEq(1)); // => [{ a: { b: [1, 2, 3] } }, { a: { b: ['1', '2', '3'] } }] * ``` */ looselyEq: PathExtension

; /** * Returns `true` if the value of the path is loosely equal to the given value (using `==`). * * It is the same as `looselyEq` but the value is not checked at compile time. * The `W` postfix stands for "wide". * @param value The value to compare to. * * @example * ```typescript * const objs = [{ a: { b: [1, 2, 3] } }, { a: { b: ['1', '2', '3'] } }]; * objs.filter(path('a.b[0]').looselyEqW(1)); // => [{ a: { b: [1, 2, 3] } }, { a: { b: ['1', '2', '3'] } }] * ``` */ looselyEqW: PathExtensionW

; /** * Returns `true` if the value of the path is not loosely equal to the given value (using `!=`). * @param value The value to compare to. * * @example * ```typescript * const objs = [{ a: { b: [1, 2, 3] } }, { a: { b: ['1', '2', '3'] } }]; * objs.filter(path('a.b[0]').notLooselyEq(1)); // => [] * ``` */ notLooselyEq: PathExtension

; /** * Returns `true` if the value of the path is not loosely equal to the given value (using `!=`). * * It is the same as `notLooselyEq` but the value is not checked at compile time. * The `W` postfix stands for "wide". * @param value The value to compare to. * * @example * ```typescript * const objs = [{ a: { b: [1, 2, 3] } }, { a: { b: ['1', '2', '3'] } }]; * objs.filter(path('a.b[0]').notLooselyEqW(1)); // => [] * ``` */ notLooselyEqW: PathExtensionW

; /** * Returns `true` if the value of the path is equal to the given value (using `equals`). * @param value The value to compare to. * * @example * ```typescript * const objs = [{ a: { b: [1, 2, 3] } }, { a: { b: ['1', '2', '3'] } }]; * objs.filter(path('a.b').equals([1, 2, 3])); // => [{ a: { b: [1, 2, 3] } }] * ``` * * @see {@link equals} */ equals: PathExtension

; /** * Returns `true` if the value of the path is equal to the given value (using `equals`). * * It is the same as `equals` but the value is not checked at compile time. * The `W` postfix stands for "wide". * @param value The value to compare to. * * @example * ```typescript * const objs = [{ a: { b: [1, 2, 3] } }, { a: { b: ['1', '2', '3'] } }]; * objs.filter(path('a.b').equalsW([1, 2, 3])); // => [{ a: { b: [1, 2, 3] } }] * ``` * * @see {@link equals} */ equalsW: PathExtensionW

; /** * Returns `true` if the value of the path is not equal to the given value (using `equals`). * @param value The value to compare to. * * @example * ```typescript * const objs = [{ a: { b: [1, 2, 3] } }, { a: { b: ['1', '2', '3'] } }]; * objs.filter(path('a.b').notEquals([1, 2, 3])); // => [{ a: { b: ['1', '2', '3'] } }] * ``` * * @see {@link equals} */ notEquals: PathExtension

; /** * Returns `true` if the value of the path is not equal to the given value (using `equals`). * * It is the same as `notEquals` but the value is not checked at compile time. * The `W` postfix stands for "wide". * @param value The value to compare to. * * @example * ```typescript * const objs = [{ a: { b: [1, 2, 3] } }, { a: { b: ['1', '2', '3'] } }]; * objs.filter(path('a.b').notEqualsW([1, 2, 3])); // => [{ a: { b: ['1', '2', '3'] } }] * ``` * * @see {@link equals} */ notEqualsW: PathExtensionW

; /** * Returns `true` if the value of the path is greater than the given value (using `is`). * @param value The value to compare to. * * @example * ```typescript * const objs = [{ a: { b: [0, 2, 3] } }, { a: { b: [-0, 5, 6] } } * objs.filter(path('a.b[0]').is(-0)); // => [{ a: { b: [-0, 5, 6] } }] * ``` * * @see {@link is} */ is: PathExtension

; /** * Returns `true` if the value of the path is greater than the given value (using `is`). * * It is the same as `is` but the value is not checked at compile time. * The `W` postfix stands for "wide". * @param value The value to compare to. * * @example * ```typescript * const objs = [{ a: { b: [0, 2, 3] } }, { a: { b: [-0, 5, 6] } } * objs.filter(path('a.b[0]').isW(-0)); // => [{ a: { b: [-0, 5, 6] } }] * ``` * * @see {@link is} */ isW: PathExtensionW

; /** * Returns `true` if the value of the path is not equal to the given value (using `is`). * @param value The value to compare to. * * @example * ```typescript * const objs = [{ a: { b: [0, 2, 3] } }, { a: { b: [-0, 5, 6] } } * objs.filter(path('a.b[0]').isNot(-0)); // => [{ a: { b: [0, 2, 3] } }] * ``` * * @see {@link is} */ isNot: PathExtension

; /** * Returns `true` if the value of the path is not equal to the given value (using `is`). * * It is the same as `isNot` but the value is not checked at compile time. * The `W` postfix stands for "wide". * @param value The value to compare to. * * @example * ```typescript * const objs = [{ a: { b: [0, 2, 3] } }, { a: { b: [-0, 5, 6] } } * objs.filter(path('a.b[0]').isNotW(-0)); // => [{ a: { b: [0, 2, 3] } }] * ``` * * @see {@link is} */ isNotW: PathExtensionW

; /** * Returns `true` if the value of the path is greater than the given value (using `>`). * @param value The value to compare to. * * @example * ```typescript * const objs = [{ a: { b: [1, 2, 3] } }, { a: { b: [4, 5, 6] } } * objs.filter(path('a.b[0]').gt(1)); // => [{ a: { b: [4, 5, 6] } }] * ``` */ gt: PathExtension

; /** * Returns `true` if the value of the path is greater than the given value (using `>`). * * It is the same as `gt` but the value is not checked at compile time. * The `W` postfix stands for "wide". * @param value The value to compare to. * * @example * ```typescript * const objs = [{ a: { b: [1, 2, 3] } }, { a: { b: [4, 5, 6] } } * objs.filter(path('a.b[0]').gtW(1)); // => [{ a: { b: [4, 5, 6] } }] * ``` */ gtW: PathExtensionW

; /** * Returns `true` if the value of the path is greater than or equal to the given value (using `>=`). * @param value The value to compare to. * * @example * ```typescript * const objs = [{ a: { b: [1, 2, 3] } }, { a: { b: [4, 5, 6] } } * objs.filter(path('a.b[0]').gte(1)); // => [{ a: { b: [1, 2, 3] } }, { a: { b: [4, 5, 6] } }] * ``` */ gte: PathExtension

; /** * Returns `true` if the value of the path is greater than or equal to the given value (using `>=`). * * It is the same as `gte` but the value is not checked at compile time. * The `W` postfix stands for "wide". * @param value The value to compare to. * * @example * ```typescript * const objs = [{ a: { b: [1, 2, 3] } }, { a: { b: [4, 5, 6] } } * objs.filter(path('a.b[0]').gteW(1)); // => [{ a: { b: [1, 2, 3] } }, { a: { b: [4, 5, 6] } }] * ``` */ gteW: PathExtensionW

; /** * Returns `true` if the value of the path is less than the given value (using `<`). * @param value The value to compare to. * * @example * ```typescript * const objs = [{ a: { b: [1, 2, 3] } }, { a: { b: [4, 5, 6] } } * objs.filter(path('a.b[0]').lt(4)); // => [{ a: { b: [1, 2, 3] } }] * ``` */ lt: PathExtension

; /** * Returns `true` if the value of the path is less than the given value (using `<`). * * It is the same as `lt` but the value is not checked at compile time. * The `W` postfix stands for "wide". * @param value The value to compare to. * * @example * ```typescript * const objs = [{ a: { b: [1, 2, 3] } }, { a: { b: [4, 5, 6] } } * objs.filter(path('a.b[0]').ltW(4)); // => [{ a: { b: [1, 2, 3] } }] * ``` */ ltW: PathExtensionW

; /** * Returns `true` if the value of the path is less than or equal to the given value (using `<=`). * @param value The value to compare to. * * @example * ```typescript * const objs = [{ a: { b: [1, 2, 3] } }, { a: { b: [4, 5, 6] } } * objs.filter(path('a.b[0]').lte(4)); // => [{ a: { b: [1, 2, 3] } }, { a: { b: [4, 5, 6] } }] * ``` */ lte: PathExtension

; /** * Returns `true` if the value of the path is less than or equal to the given value (using `<=`). * * It is the same as `lte` but the value is not checked at compile time. * The `W` postfix stands for "wide". * @param value The value to compare to. * * @example * ```typescript * const objs = [{ a: { b: [1, 2, 3] } }, { a: { b: [4, 5, 6] } } * objs.filter(path('a.b[0]').lteW(4)); // => [{ a: { b: [1, 2, 3] } }, { a: { b: [4, 5, 6] } }] * ``` */ lteW: PathExtensionW

; }; /** * Returns a function that when given an object returns the value of the specified path. * * The function also has a number of extensions that can be used to compare the value of the path. * @param path The path to get, can be either a string or an array of strings. * * @example * ```typescript * const obj = { a: { b: [1, 2, 3] } }; * const objs = [{ a: { b: [1, 2, 3] } }, { a: { b: [4, 5, 6] } }]; * objs.map(path('a.b[0]')); // => [1, 4] * objs.map(path(['a', 'b', '0'])); // => [1, 4] * path('a.b[0]')(obj); // => 1 * path(['a', 'b', '0'])(obj); // => 1 * ``` * * @example * ```typescript * const objs = [{ a: { b: [1, 2, 3] } }, { a: { b: [4, 5, 6] } }]; * objs.filter(path('a.b[0]').eq(1)); // => [{ a: { b: [1, 2, 3] } }] * objs.filter(path(['a', 'b', '0']).eq(1)); // => [{ a: { b: [1, 2, 3] } }] * ``` */ export type PathFn = (( o: O, ) => P extends BasePath | BasePathArray ? GetByPath : undefined) & PathExtensions

& { [zTag]: 'Path'; }; /** * Returns a function that when given an object returns the value of the specified path. * * The function also has a number of extensions that can be used to compare the value of the path. * @param path The path to get, can be either a string or an array of strings. * * @example * ```typescript * const obj = { a: { b: [1, 2, 3] } }; * const objs = [{ a: { b: [1, 2, 3] } }, { a: { b: [4, 5, 6] } }]; * objs.map(path('a.b[0]')); // => [1, 4] * objs.map(path(['a', 'b', '0'])); // => [1, 4] * path('a.b[0]')(obj); // => 1 * path(['a', 'b', '0'])(obj); // => 1 * ``` * * @example * ```typescript * const objs = [{ a: { b: [1, 2, 3] } }, { a: { b: [4, 5, 6] } }]; * objs.filter(path('a.b[0]').eq(1)); // => [{ a: { b: [1, 2, 3] } }] * objs.filter(path(['a', 'b', '0']).eq(1)); // => [{ a: { b: [1, 2, 3] } }] * ``` */ declare const path: < const O extends object, const P extends object extends O ? string | readonly string[] : | BasePath | __BasePathArray< ((O extends any ? [O] : never)[0] extends infer T ? T extends (O extends any ? [O] : never)[0] ? T extends any ? [T] : never : never : never)[0] >, >( path: P, ) => PathFn; export default path; //# sourceMappingURL=path.d.ts.map