/** * Returned by `PropertyPath` for valid paths. */ interface PathAccessorFactory { /** Returns target's property by searching for the configured property path. */ (target: unknown): PathAccessor; /** Whether the path was invalid or not. */ invalid?: boolean; } /** Path accessors are generated by the function returned from `PropertyPath(...)`. */ interface PathAccessor { /** Returns true if the path or the target are invalid. */ readonly invalid: boolean; /** Returns true if the accessor's target has this property. */ exists(): boolean; /** Returns the value associated with this accessor. */ get(): unknown; /** Set the value associated with this accessor. */ set(value: unknown): void; /** Attempt to fix the current path. */ fix(fixCallback?: (last: any, parts: (string | symbol)[], i: number) => void): PathAccessor; } /** * Parses a complex property path expression like "coordinate.x" * in order to access the properties in target objects. * * @param path the target path, e.g. "a.b.name" * @returns a path function which produces accessors. * @example * ``` * import PropertyPath from "apprt-core/PropertyPath"; * * let path = PropertyPath("a.b.name"); * * // parser errors are reported by "invalid" property * if(path.invalid){ * ... * } * * let target = { * a: { * b: { * name: "test" * } * } * }; * * let accessor = path(target); * accessor.invalid // -> false, but true if path is not accessible in target * accessor.exists() // -> true, b hasOwnProperty name * accessor.get() //-> "test" * accessor.set("new val") // -> changes target.a.b.name to "new val", will throw an error if property is not accessible * ``` */ declare function PropertyPath(path?: string | symbol): PathAccessorFactory; export { PropertyPath, PropertyPath as default }; export type { PathAccessor, PathAccessorFactory };