UNPKG

json-logic-engine

Version:

Construct complex rules with JSON & process them.

30 lines (29 loc) 1.15 kB
/** * Splits a path string into an array of parts; lightly memoized. * It will reset the entire cache after 2048 paths, this could be improved * by implementing an LRU cache or something, but I'm trying to keep * this library fairly dep free, and the code not too cumbersome. * * Memoizing the splitPath function can be seen as cheating, but I think it's likely * that a lot of the same paths will be used for logic, so it's a good optimization. * * @param {string} str * @returns {string[]} */ export function splitPathMemoized(str: string): string[]; /** * Splits a path string into an array of parts. * * @example splitPath('a.b.c') // ['a', 'b', 'c'] * @example splitPath('a\\.b.c') // ['a.b', 'c'] * @example splitPath('a\\\\.b.c') // ['a\\', 'b', 'c'] * @example splitPath('a\\\\\\.b.c') // ['a\\.b', 'c'] * @example splitPath('hello') // ['hello'] * @example splitPath('hello\\') // ['hello\\'] * @example splitPath('hello\\\\') // ['hello\\'] * * @param {string} str * @param {string} separator * @returns {string[]} */ export function splitPath(str: string, separator?: string, escape?: string, up?: string): string[];