json-sculpt
Version:
JSON Sculpt is a utility library designed to transform or "sculpt" JSON objects into your desired shape.
37 lines (36 loc) • 1.67 kB
TypeScript
import { JsonObject, JsonValue, SculptOptions, Replacements as Replacements, SculptStringOptions } from "../types";
/**
* Sculpts a JSON object into desired shape
*
* @template T - Type of resulting object
* @param json - JSON object to be sculpted
* @param {Replacements} [replacements={}] - An object containing custom values to use during sculpting.
* @param {SculptOptions} options - Options for sculpting
* @returns Sculpted JSON object
*
* @example
* const data = {
* name: "Brennan",
* age: 30,
* $sculpt: {
* description: "{{this.name}} is {{this.age}} years old",
* }
* };
*
* const sculptedData = sculptJson<{ name: string, age: number }>(data);
*
* console.log(sculptedData); // { description: "Brennan is 30 years old" }
*/
export declare const sculptJson: <T extends JsonValue = JsonValue>(json: JsonObject, replacements?: Replacements, options?: SculptOptions) => T;
/**
* Sculpts a string by replacing all {{}}-enclosed keys with matching values from a replacement object.
* If a key is not found in the state object, the original {{}}-enclosed key is left in the string.
*
* @param {string} template The string to sculpt.
* @param {Replacements} replacements The replacement object containing values to replace {{}}-enclosed keys.
* @param {SculptStringOptions} options - Options for sculpting
* @return {string} The sculpted string.
*/
export declare function sculptString(template: string, replacements?: Replacements, options?: SculptStringOptions): string;
export declare const getOutput: (str: string) => [] | RegExpMatchArray;
export declare const findCommandValue: (obj: JsonValue, command: string) => any[];