import { ParseError, Replacer, Result, Reviver, StringifyError } from './types.js'; /** * @happyvertical/json * * High-performance JSON parsing and serialization with Rust SIMD acceleration * and automatic fallback to native JavaScript. * * @example * ```typescript * import { parse, stringify, clone } from '@happyvertical/json'; * * // Drop-in replacements for JSON.parse/stringify * const data = parse('{"key": "value"}'); * const json = stringify(data); * * // Deep clone (optimized) * const copy = clone(data); * * // Safe variants (don't throw) * const result = safeParse(maybeInvalidJson); * if (result.success) { * console.log(result.value); * } else { * console.error(result.error.message); * } * ``` * * @example * ```typescript * import { JSONFactory } from '@happyvertical/json'; * * // Create adapter with specific options * const json = JSONFactory.create({ adapter: 'sonic', fallback: true }); * * // Check adapter info * console.log(json.name); // 'sonic' or 'native' * console.log(json.isNative); // false if using Rust * ``` * * @packageDocumentation */ export { createSonicAdapter, isSonicAvailable, NativeAdapter, nativeAdapter, SonicAdapter, } from './adapters/index.js'; export { createAdapter, getDefaultAdapter, JSONFactory } from './factory.js'; export type { AdapterInfo, AdapterType, JSONAdapter, JSONOptions, ParseError, Replacer, Result, Reviver, StringifyError, } from './types.js'; /** * Parse a JSON string into a JavaScript value * * Drop-in replacement for JSON.parse with optional SIMD acceleration. * * @param text - The JSON string to parse * @param reviver - Optional function to transform values during parsing * @returns The parsed JavaScript value * @throws {SyntaxError} If the input is not valid JSON * * @example * ```typescript * const data = parse('{"name": "Alice", "age": 30}'); * console.log(data.name); // "Alice" * ``` */ export declare function parse(text: string, reviver?: Reviver): T; /** * Convert a JavaScript value to a JSON string * * Drop-in replacement for JSON.stringify with optional SIMD acceleration. * * @param value - The value to stringify * @param replacer - Optional function or array to filter/transform values * @param space - Number of spaces for indentation (0-10) or string * @returns The JSON string * @throws {TypeError} If the value contains circular references or BigInt * * @example * ```typescript * const json = stringify({ name: "Alice", age: 30 }); * console.log(json); // '{"name":"Alice","age":30}' * * // With pretty printing * const pretty = stringify(data, null, 2); * ``` */ export declare function stringify(value: unknown, replacer?: Replacer, space?: number | string): string; /** * Deep clone a value via JSON round-trip * * Optimized alternative to JSON.parse(JSON.stringify(value)). * Note: Only clones JSON-serializable values (no functions, symbols, etc). * * @param value - The value to clone * @returns A deep clone of the value * * @example * ```typescript * const original = { nested: { deep: [1, 2, 3] } }; * const copy = clone(original); * copy.nested.deep.push(4); * console.log(original.nested.deep); // [1, 2, 3] - unchanged * ``` */ export declare function clone(value: T): T; /** * Parse a JSON string without throwing on errors * * Returns a Result type with either the parsed value or error details. * * @param text - The JSON string to parse * @returns A Result object with either the parsed value or error details * * @example * ```typescript * const result = safeParse(userInput); * if (result.success) { * console.log(result.value.name); * } else { * console.error(`Parse error at line ${result.error.line}: ${result.error.message}`); * } * ``` */ export declare function safeParse(text: string): Result; /** * Stringify a value without throwing on errors * * Returns a Result type with either the JSON string or error details. * * @param value - The value to stringify * @returns A Result object with either the JSON string or error details * * @example * ```typescript * const result = safeStringify(data); * if (result.success) { * console.log(result.value); * } else { * console.error(`Stringify error: ${result.error.message}`); * } * ``` */ export declare function safeStringify(value: unknown): Result; /** * Check if a string is valid JSON without parsing * * Faster than try/catch with parse() when you only need validation. * * @param text - The string to validate * @returns true if the string is valid JSON * * @example * ```typescript * if (isValid(userInput)) { * const data = parse(userInput); * } * ``` */ export declare function isValid(text: string): boolean; /** * Get information about the current JSON adapter * * @returns Adapter information including name, version, and SIMD status * * @example * ```typescript * const info = getAdapterInfo(); * console.log(`Using ${info.name} adapter`); * console.log(`SIMD enabled: ${info.simdEnabled}`); * ``` */ export declare function getAdapterInfo(): import('./types.js').AdapterInfo; /** * Check if SIMD-accelerated parsing is available * * @returns true if the Rust SIMD adapter is loaded * * @example * ```typescript * if (isSIMDAvailable()) { * console.log('Using SIMD-accelerated JSON parsing'); * } * ``` */ export declare function isSIMDAvailable(): boolean; //# sourceMappingURL=index.d.ts.map