sb-mig
Version:
CLI to rule the world. (and handle stuff related to Storyblok CMS)
63 lines (62 loc) • 2.24 kB
TypeScript
/**
* Object transformation utilities
* Pure functions for deep object manipulation
*/
/**
* Recursively extend a field in a nested object
* If the field is an array, appends unique values
* If the field is an object, merges properties
*
* @param obj - The object to search and extend
* @param targetField - The field name to find and extend
* @param newValue - The value(s) to add
* @returns true if field was found and extended, false otherwise
*
* @example
* const obj = { schema: { items: ['a', 'b'] } };
* extendField(obj, 'items', ['c', 'd']);
* // obj.schema.items is now ['a', 'b', 'c', 'd']
*/
export declare const extendField: (obj: any, targetField: string, newValue: any) => boolean;
/**
* Deep transform an object using a transformer specification
* Supports function transformers, nested object transformers, and literal values
*
* @param obj - The source object to transform
* @param transformers - Specification object where:
* - function values: called with current value, result used as new value
* - object values: recursively applied to nested objects
* - other values: used directly as the new value
* @returns New transformed object (original is not mutated)
*
* @example
* const obj = { name: 'hero', count: 5 };
* const result = deepTransform(obj, {
* name: (v) => v.toUpperCase(),
* count: (v) => v * 2,
* });
* // result: { name: 'HERO', count: 10 }
*
* @example
* // Nested transformation
* const obj = { schema: { title: 'old' } };
* const result = deepTransform(obj, {
* schema: { title: 'new' }
* });
* // result: { schema: { title: 'new' } }
*/
export declare function deepTransform(obj: any, transformers: any): any;
/**
* Check if a component has content available as bloks
*
* @param component - Storyblok component schema
* @returns true if component.schema.content is a bloks field with whitelist
*/
export declare const isContentAvailableAsBloks: (component: any) => boolean;
/**
* Check if a component has items available as bloks
*
* @param component - Storyblok component schema
* @returns true if component.schema.items is a bloks field with whitelist
*/
export declare const isItemsAvailableAsBloks: (component: any) => boolean;