li18nt
Version:
Locales linter, formatter, sorter and prettifier
30 lines (29 loc) • 1.15 kB
TypeScript
import { JSONObject, PropertyPath } from '@types';
/**
* Parses a property path
* foo.bar[4].xy['test prop'] -> ['foo', 'bar', 4, 'xy', 'test prop']
* @param str
*/
export declare const propertyPath: (str: string) => PropertyPath;
/**
* Checks if the given array contains another array, only works with primitives.
* @param paths
* @param target
*/
export declare const containsDeep: <T extends PropertyPath>(paths: T[], target: T) => boolean;
/**
* Same as containsDeep but only the beginning of the array needs to match the given target
* @param paths
* @param target
*/
export declare const startsWithPattern: <T extends PropertyPath>(paths: T[], target: T) => boolean;
export interface Property<K extends (string | number)> {
key: K;
path: PropertyPath;
}
/**
* Iterates over all properties (including nested ones) of an object
* @param obj Target object
* @param skipArrays Do not list array items (will still include objects in arrays)
*/
export declare function paths<T extends JSONObject, S extends boolean, P = Property<S extends true ? string : (string | number)>>(obj: T, skipArrays?: S): IterableIterator<P>;