/** * Represents a single step in a property access path * Can be either a property name or an array index access * @example { type: "property", key: "user" } * @example { type: "index", key: "0" } */ type PathSegment = { type: "property" | "index"; key: string; }; /** * Represents the result of parsing a dot-notation string into path segments * Used internally by the parser to break down property access chains including arrays * @example [{ type: "property", key: "users" }, { type: "index", key: "0" }, { type: "property", key: "name" }] for "users[0].name" */ type PropertyPath = PathSegment[]; /** * Function type that accesses nested properties safely from a record * Returns undefined if any property in the chain is missing or null/undefined * @example * const accessor = createAccessor("user.name"); * const result = accessor(data); // string | undefined */ type PropertyAccessor = (record: Record) => T | undefined; /** * Parser configuration options for customizing dot-notation parsing behavior * Used to modify how the parser handles property paths and edge cases * @example { delimiter: ".", escapeChar: "\\" } */ interface ParserOptions { delimiter?: string; escapeChar?: string; } /** * Parses a dot-notation string with array support into path segments * Handles escaped delimiters, array indices, and validates input format * @param notation - Notation string with dots and brackets (e.g., "users[0].profile.name") * @param options - Parser configuration options * @returns Array of path segments for property and array access * @example * parsePath("user.profile.name") // [{ type: "property", key: "user" }, { type: "property", key: "profile" }, { type: "property", key: "name" }] * parsePath("users[0].name") // [{ type: "property", key: "users" }, { type: "index", key: "0" }, { type: "property", key: "name" }] * parsePath("data\\.file[1]", { escapeChar: "\\" }) // [{ type: "property", key: "data.file" }, { type: "index", key: "1" }] */ declare function parsePath(notation: string, options?: ParserOptions): PropertyPath; /** * Creates an accessor function from a parsed property path with array support * The returned function safely navigates nested objects and arrays using the parsed path * @param path - Array of path segments to access in sequence * @returns Function that takes a record and returns the nested value or undefined * @example * const path = [{ type: "property", key: "users" }, { type: "index", key: "0" }, { type: "property", key: "name" }]; * const accessor = createAccessorFromPath(path); * accessor({ users: [{ name: "John" }] }) // "John" */ declare function createAccessorFromPath(path: PropertyPath): PropertyAccessor; /** * Main parser function that creates an accessor from notation string with array support * Combines path parsing and accessor creation into a single operation * @param notation - Notation string with dots and brackets (e.g., "users[0].profile.name") * @param options - Parser configuration options * @returns Accessor function for the specified property path * @example * const accessor = createAccessor("user.profile.name"); * const name = accessor(userData); // safely gets nested property * * const arrayAccessor = createAccessor("users[0].name"); * const userName = arrayAccessor(data); // safely accesses array elements * * const complexAccessor = createAccessor("items[2].meta\\.data.values[1]", { escapeChar: "\\" }); * const value = complexAccessor(response); // handles escaped dots and nested arrays */ declare function createAccessor(notation: string, options?: ParserOptions): PropertyAccessor; /** * Utility function to test if a property path exists in a record (with array support) * Useful for validation before attempting to access nested properties or array elements * @param notation - Notation string with dots and brackets to test * @param record - Record to test against * @param options - Parser configuration options * @returns Boolean indicating if the complete path exists * @example * hasProperty("user.name", data) // true if data.user.name exists * hasProperty("users[0].name", data) // true if data.users[0].name exists * hasProperty("missing.path", data) // false if any part is undefined */ declare function hasProperty(notation: string, record: Record, options?: ParserOptions): boolean; export { createAccessor, createAccessorFromPath, parsePath, hasProperty, type PropertyAccessor, type PropertyPath, type PathSegment, type ParserOptions, };