@snups/rjsf-utils
Version:
Utility functions for @snups/rjsf-core
31 lines (30 loc) • 1.63 kB
TypeScript
import { RJSFSchema, StrictRJSFSchema } from './types.js';
/** Hashes a string using the algorithm based on Java's hashing function.
* JS has no built-in hashing function, so rolling our own
* based on Java's hashing fn:
* http://www.java2s.com/example/nodejs-utility-method/string-hash/hashcode-4dc2b.html
*
* @param string - The string for which to get the hash
* @returns - The resulting hash of the string in hex format
*/
export declare function hashString(string: string): string;
/** Stringifies an `object`, sorts object fields in consistent order before stringifying it.
*
* @param object - The object for which the sorted stringify is desired
* @returns - The stringified object with keys sorted in a consistent order
*/
export declare function sortedJSONStringify(object: unknown): string;
/** Stringifies an `object` and returns the hash of the resulting string. Sorts object fields
* in consistent order before stringify to prevent different hash ids for the same object.
*
* @param object - The object for which the hash is desired
* @returns - The string obtained from the hash of the stringified object
*/
export declare function hashObject(object: unknown): string;
/** Stringifies the schema and returns the hash of the resulting string. Sorts schema fields
* in consistent order before stringify to prevent different hash ids for the same schema.
*
* @param schema - The schema for which the hash is desired
* @returns - The string obtained from the hash of the stringified schema
*/
export default function hashForSchema<S extends StrictRJSFSchema = RJSFSchema>(schema: S): string;