util.d.ts 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738
  1. import type { Path } from './types';
  2. /**
  3. * Un-escapes a JSON pointer path component.
  4. */
  5. export declare function unescapeComponent(component: string): string;
  6. /**
  7. * Escapes a JSON pointer path component.
  8. */
  9. export declare function escapeComponent(component: string): string;
  10. /**
  11. * Convert JSON pointer like "/foo/bar" to array like ["", "foo", "bar"], while
  12. * also un-escaping reserved characters.
  13. */
  14. export declare function parseJsonPointer(pointer: string): Path;
  15. /**
  16. * Escape and format a path array like ["", "foo", "bar"] to JSON pointer
  17. * like "/foo/bar".
  18. */
  19. export declare function formatJsonPointer(path: Path): string;
  20. export declare const toPath: (pointer: string | Path) => Path;
  21. /**
  22. * Returns true if `parent` contains `child` path, false otherwise.
  23. */
  24. export declare function isChild(parent: Path, child: Path): boolean;
  25. export declare function isPathEqual(p1: Path, p2: Path): boolean;
  26. /**
  27. * Returns true if JSON Pointer points to root value, false otherwise.
  28. */
  29. export declare const isRoot: (path: Path) => boolean;
  30. /**
  31. * Returns parent path, e.g. for ['foo', 'bar', 'baz'] returns ['foo', 'bar'].
  32. */
  33. export declare function parent(path: Path): Path;
  34. /**
  35. * Check if path component can be a valid array index.
  36. */
  37. export declare function isValidIndex(index: string | number): boolean;
  38. export declare const isInteger: (str: string) => boolean;