paseto-ts
Version:
PASETO v4 (encrypt, decrypt, sign & verify) in TypeScript
34 lines (33 loc) • 1.72 kB
TypeScript
/**
* Get the depth of a JSON string.
* @param {string} data JSON string
* @returns {number} Depth of the JSON string
* @see https://github.com/paseto-standard/paseto-spec/blob/master/docs/02-Implementation-Guide/01-Payload-Processing.md#enforcing-maximum-depth-without-parsing-the-json-string
*/
export declare function getJsonDepth(data: string): number;
/**
* Split the string based on the number of `":` pairs without a preceding
* backslash, then return the number of pieces it was broken into.
* @param {string} json JSON string
* @returns {number} Number of keys in the JSON string
* @see https://github.com/paseto-standard/paseto-spec/blob/master/docs/02-Implementation-Guide/01-Payload-Processing.md#enforcing-maximum-key-count-without-parsing-the-json-string
*/
export declare function countKeys(json: string): number;
/**
* Assert that a JSON string is within the maximum depth and key count
* @param {string} json JSON string
* @param {number} maxDepth Maximum depth of the JSON string
* @param {number} maxKeys Maximum number of keys in the JSON string
* @returns {boolean} true if the JSON string is valid, false otherwise
* @see https://github.com/paseto-standard/paseto-spec/blob/master/docs/02-Implementation-Guide/01-Payload-Processing.md#enforcing-maximum-depth-without-parsing-the-json-string
*/
export declare function assertJsonStringSize(json: string, { maxDepth, maxKeys }: {
maxDepth: number;
maxKeys: number;
}): boolean;
/**
* Returns possible JSON object or string
* @param {string | Uint8Array} json Possible JSON string
* @returns {string | object} JSON object or string
*/
export declare function returnPossibleJson(json?: string | Uint8Array): string | object;