UNPKG

@oaklean/profiler-core

Version:

Part of the @oaklean suite. It provides all basic functions to work with the `.oak` file format. It allows parsing the `.oak` file format as well as tools for analyzing the measurement values. It also provides all necessary capabilities required for prec

106 lines (105 loc) 3.8 kB
export type JSONPath = (string | number)[] | string; /** * Parse a dot-notation path string into a JSONPath array * Examples: * "config.database.host" -> ["config", "database", "host"] * "items.0" -> ["items", 0] * "items[0]" -> ["items", 0] */ export declare function parsePath(pathStr: string): (string | number)[]; /** * Parse a JSONC string into a JavaScript value. * Unlike JSON.parse(), this handles comments and trailing commas. */ export declare function parse<T = unknown>(json: string): T; /** * Get the value at a path in the JSON */ export declare function get(json: string, path: JSONPath): unknown; /** * Check if a path exists in the JSON */ export declare function has(json: string, path: JSONPath): boolean; /** * Get the comment associated with a field at a path. * First checks for a comment above the field, then falls back to a trailing comment. */ export declare function getComment(json: string, path: JSONPath): string | null; /** * Get the trailing comment after a field at a path (on the same line) */ export declare function getTrailingComment(json: string, path: JSONPath): string | null; /** * Set a value at a path in the JSON, optionally with a comment */ export declare function set(json: string, path: JSONPath, value: unknown, comment?: string): string; /** * Remove a field at a path (with associated comment handling) */ export declare function remove(json: string, path: JSONPath): string; /** * Merge changes into JSON (update/add only, never delete) */ export declare function merge(json: string, changes: Record<string, unknown>): string; /** * Replace JSON with changes (delete fields not in changes) */ export declare function replace(json: string, changes: Record<string, unknown>): string; /** * Patch JSON with explicit deletes via undefined */ export declare function patch(json: string, changes: Record<string, unknown>): string; /** * Rename a key while preserving its value and associated comment */ export declare function rename(json: string, path: JSONPath, newKey: string): string; /** * Move a field to a different location */ export declare function move(json: string, fromPath: JSONPath, toPath: JSONPath): string; /** * Set or update a comment above a field */ export declare function setComment(json: string, path: JSONPath, comment: string): string; /** * Set or update a trailing comment after a field (on the same line) */ export declare function setTrailingComment(json: string, path: JSONPath, comment: string): string; /** * Remove the trailing comment after a field */ export declare function removeTrailingComment(json: string, path: JSONPath): string; /** * Remove the comment above a field */ export declare function removeComment(json: string, path: JSONPath): string; export interface SortOptions { /** * Custom comparator for sorting keys. Defaults to alphabetical. */ comparator?: (a: string, b: string) => number; /** * Whether to recursively sort nested objects. Defaults to true. */ deep?: boolean; } /** * Sort object keys while preserving comments */ export declare function sort(json: string, path?: JSONPath, options?: SortOptions): string; /** * Format a JSONC document with consistent indentation. * Preserves comments while normalizing whitespace. */ export declare function format(json: string, options?: { /** Number of spaces per indentation level. Defaults to 2. */ tabSize?: number; /** Use spaces instead of tabs. Defaults to true. */ insertSpaces?: boolean; /** End of line character. Defaults to '\n'. */ eol?: string; }): string; /** * Modify JSON with replace semantics — fields not in changes are deleted */ export declare function modify(json: string, changes: Record<string, unknown>): string;