jsurl2
Version:
URL friendly JSON-like formatting and parsing
18 lines (17 loc) • 869 B
TypeScript
export type StringifyOptions = {
/** Use short encoding for small strings by dropping optional closing characters */
short?: boolean;
/** Use rich encoding for JS objects like Dates */
rich?: boolean;
};
/** Convert any JS value to a JsUrl2 encoded string */
export declare const stringify: (value: any, options?: StringifyOptions) => string;
export type ParseOptions = {
/** decode URI escapes and remove spaces.
* JsUrl2 doesn't use % or spaces in its encoding so it can safely decode it. */
deURI?: boolean;
};
/** Parse a JsUrl2 encoded string. Also parses JSON. */
export declare const parse: <T>(encoded: string, options?: ParseOptions) => T;
/** Parse a JsUrl2 encoded string, and fall back if it fails. Also parses JSON. */
export declare const tryParse: <T>(encoded: string, fallback?: T | undefined, options?: ParseOptions) => T;