@canard/schema-form
Version:
React-based component library that renders forms based on JSON Schema with plugin system support for validators and UI components
30 lines (29 loc) • 1.06 kB
TypeScript
/**
* Parses a JSON Pointer path string into an array of unescaped segments.
*
* This function takes a path string (e.g., '/foo/bar~1baz'), splits it by the
* child separator ('/'), filters out any empty segments that result from
* leading/trailing or consecutive separators, and then unescapes each segment
* according to RFC 6901 and custom rules.
*
* @example
* ```typescript
* // Standard path
* getPathSegments('/foo/bar') // ['foo', 'bar']
*
* // Path with escaped characters
* getPathSegments('/a~1b/c~0d') // ['a/b', 'c~d']
*
* // Handles leading/trailing/consecutive slashes
* getPathSegments('foo/bar/') // ['foo', 'bar']
* getPathSegments('/foo//bar') // ['foo', 'bar']
*
* // Empty or root path
* getPathSegments('') // null
* getPathSegments('/') // null
* ```
*
* @param path - The JSON Pointer path string to parse.
* @returns An array of unescaped path segments.
*/
export declare const getPathSegments: (path: string) => string[] | null;