json-sculpt
Version:
JSON Sculpt is a utility library designed to transform or "sculpt" JSON objects into your desired shape.
55 lines (54 loc) • 1.78 kB
TypeScript
/**
* @module sculptJson/types
*/
/**
* Commands available during sculpting.
*
* @property {string} sculpt Command to specify shape to sculpt JSON node into.
*/
export declare enum Commands {
sculpt = "sculpt"
}
export declare enum OutputSources {
self = "self.",
state = "state.",
root = "root."
}
export type SculptBase<T extends JsonObject> = T & {
"{$sculpt$}"?: JsonValue;
};
export type JsonValue = string | number | boolean | undefined | null | JsonObject | JsonValue[];
export type JsonObject = {
[key: string]: JsonValue;
};
export type Replacement = {
value: JsonValue;
original: string;
};
/**
* Options to configure the behavior of `sculptJson` function.
*
* @property {boolean} [onlyResolveSculpt=false] - Determines whether all commands in the JSON object should be resolved, or only commands nested under a `$sculpt` object.
* @property {boolean} [throwOnError=false] - Determines whether an error should be thrown if sculpting fails.
*/
export type SculptOptions = {
onlyResolveSculpt?: boolean;
throwOnError?: boolean;
};
/**
* Options to configure the behavior of `sculptString` function.
*
* @property {boolean} [allowPartialMatch=false] - Determines whether to allow fuzzy matching of replacement keys.
*/
export type SculptStringOptions = {
allowPartialMatch?: boolean;
};
/**
* An object containing custom values available via state reference during sculpting.
* The values can be either primitives or functions that return primitives.
* If a function is used, it will be called with the original JSON object as its only argument.
*/
export type Replacements = {
[key: string]: JsonValue | ReplacementFunction;
};
export type ReplacementFunction = (original: JsonObject | string) => JsonValue;