lodash-walk-object
Version:
Walk all properties deep in object with lodash help
115 lines (113 loc) • 3.62 kB
TypeScript
// @ts-nocheck
interface Circ {
/**
* Path whose value points to an already visited object.
*/
pathToObj: string;
/**
* Lodash path of the original object.
*/
circuralTargetPath: string | unknown;
}
declare namespace Models {
interface InDBType {
target: object;
path: string;
}
interface Ver {
v: unknown;
p: string;
parent?: Ver;
isGetter?: boolean;
/**
* Active ancestor chain used by breadth-first traversal when
* shared objects should not be treated as circular.
*/
ancestors?: InDBType[];
}
interface StartIteratorOptions {
walkGetters?: boolean;
/**
* When false, every repeated object reference is treated as circular.
*
* When true, only references to objects in the current ancestor chain
* are treated as circular. Shared objects are walked for every path.
*
* @default false
*/
considerSharedObjects?: boolean;
/**
* Circular checking is especially useful for breadth-first traversal.
*/
checkCircural?: boolean;
breadthWalk?: boolean;
include?: string[];
exclude?: string[];
}
interface AdditionalIteratorOptions extends StartIteratorOptions {
skipObject?: () => void;
isGetter?: boolean;
/**
* Breadth walk skips the contents of circular objects.
*/
isCircural?: boolean;
exit?: () => void;
}
interface InternalValues extends AdditionalIteratorOptions {
stack?: InDBType[];
circural?: Circ[];
hasIterator?: boolean;
_valueChanged: boolean;
_skip: boolean;
_exit: boolean;
}
}
type Iterator = (value: unknown, lodashPath: string, changeValueTo: (newValue: unknown) => void, options?: Models.AdditionalIteratorOptions) => void;
type UnknownRecord = Record<PropertyKey, unknown>;
interface PreparedPath {
contextPath: string;
property: string | number;
}
interface PropertyEntry {
key: string;
value: unknown;
isGetter: boolean;
}
declare class Helpers {
static get Walk(): {
Object(json: object, iterator: Iterator, options?: Models.StartIteratorOptions): {
circs: Circ[] | undefined;
};
ObjectBy(property: string, inContext: object, iterator: Iterator, options?: Models.StartIteratorOptions): {
circs: Circ[] | undefined;
};
};
private static createInternalOptions;
private static _walk;
private static walkDepthFirst;
private static walkBreadthFirst;
private static prepareCurrentValue;
private static findChildren;
private static getPropertyEntries;
private static readProperty;
private static appendPath;
private static propertyToPath;
private static shouldSkipPath;
private static normalizeRootArrayPath;
private static isSamePathOrDescendant;
private static isAncestorPath;
private static _changeValue;
private static _prepareParams;
private static get _Helpers();
private static isObjectLike;
}
declare const walk: {
Object: (json: object, iterator: Iterator, options?: Models.StartIteratorOptions) => {
circs: Circ[] | undefined;
};
ObjectBy: (property: string, inContext: object, iterator: Iterator, options?: Models.StartIteratorOptions) => {
circs: Circ[] | undefined;
};
};
export { Helpers, Models, walk };
export type { Circ, Iterator, PreparedPath, PropertyEntry, UnknownRecord };