export type CloningPlugin = { /** * - The function id. */ id: string; /** * - A function that accepts an item and returns true if the plugin is responsible for that type. */ canHandle: (value: Value) => boolean; /** * - A function that accepts the item and the cloner instance, returning the cloned version. */ clone: (value: Value, isDeep: boolean, cloner: TinyCloner | typeof TinyCloner) => Value; }; export type TinyClonerOptions = { /** * - If true, the instance will be initialized with a copy of the default plugins and will ignore global defaults during the cloning process. */ isolationMode?: boolean; }; /** * Represents a plugin used by the TinyCloner to identify and clone specific data types. * * @template {any} Value * @typedef {Object} CloningPlugin * @property {string} id - The function id. * @property {(value: Value) => boolean} canHandle - A function that accepts an item and returns true if the plugin is responsible for that type. * @property {(value: Value, isDeep: boolean, cloner: TinyCloner|typeof TinyCloner) => Value} clone - A function that accepts the item and the cloner instance, returning the cloned version. */ /** * @typedef {Object} TinyClonerOptions * @property {boolean} [isolationMode=false] - If true, the instance will be initialized with a copy of the default plugins and will ignore global defaults during the cloning process. */ /** * A class that performs deep cloning using a plugin-based architecture with advanced management capabilities. */ declare class TinyCloner { #private; /** * Indicates whether the instance is operating in isolation mode. * * If `true`, the instance is initialized with a snapshot of the current default plugins * and will strictly use only its own plugins during the cloning process, ignoring * any future changes to the global defaults. * * If `false`, the instance will use its own plugins and will fall back to the * global default plugins if no match is found in the instance. * * @returns {boolean} True if the instance is isolated, false if it uses global fallbacks. */ get isolationMode(): boolean; /** * Gets the global default value for the isDeep parameter. * @returns {boolean} */ static get defaultIsDeep(): boolean; /** * Sets the global default value for the isDeep parameter. * @param {boolean} value - The new default value. * @throws {TypeError} If the value is not a boolean. */ static set defaultIsDeep(value: boolean); /** * Creates an instance of TinyCloner. * * @param {TinyClonerOptions} [options={ isolationMode: false }] - Configuration options for the cloner instance. */ constructor(options?: TinyClonerOptions); /** * Creates a default plugin specifically designed to handle plain JavaScript objects. * @param {string} id - The function id. * @returns {CloningPlugin>} A plugin object configured for object cloning. */ static _createObjectPlugin(id: string): CloningPlugin>; /** * Validates that a plugin object adheres to the required CloningPlugin interface. * * @template {any} T * @param {CloningPlugin} plugin - The plugin object to validate. * @throws {TypeError} If the plugin does not implement the required 'canHandle' and 'clone' methods. */ static validatePlugin(plugin: CloningPlugin): void; /** * @returns {CloningPlugin[]} A deep copy of the current default plugins array. */ static get plugins(): CloningPlugin[]; /** * @returns {number} The total number of default plugins registered. */ static get size(): number; /** * @returns {string[]} An array containing the unique IDs of all default plugins. */ static get ids(): string[]; /** * @param {CloningPlugin[]} newPlugins - An array of plugins to replace the current ones. * @throws {TypeError} If the input is not an array or if plugins do not implement the required interface. */ static set plugins(newPlugins: CloningPlugin[]); /** * Adds a new plugin to the default plugins registry at a specified position. * * @param {CloningPlugin} plugin - The plugin to add. * @param {'start' | 'end' | 'index'} [position='start'] - The position where the plugin should be inserted. * @param {number} [index=0] - The specific index to use if position is set to 'index'. * @throws {TypeError} If the plugin is invalid, the position is unrecognized, or index is not a valid integer. */ static addPlugin(plugin: CloningPlugin, position?: 'start' | 'end' | 'index', index?: number): void; /** * Checks if a default plugin with the specified ID exists. * * @param {string} id - The ID of the plugin to search for. * @returns {boolean} True if the plugin exists, false otherwise. * @throws {TypeError} If the id is not a string. */ static hasPlugin(id: string): boolean; /** * Removes a default plugin from the registry by its ID. * * @param {string} id - The ID of the plugin to remove. * @returns {boolean} True if a plugin was removed, false if the plugin was not found. * @throws {TypeError} If the id is not a string. */ static removePlugin(id: string): boolean; /** * Removes default plugins that satisfy the provided predicate. * @param {(plugin: CloningPlugin) => boolean} predicate - A function that returns true for plugins to be removed. */ static filterPlugins(predicate: (plugin: CloningPlugin) => boolean): void; /** * Updates a default plugin at a specific index. * @param {number} index - The index of the plugin to update. * @param {CloningPlugin} plugin - The new plugin configuration. * @throws {RangeError} If the index is out of bounds. */ static updatePlugin(index: number, plugin: CloningPlugin): void; /** * Reorders the default plugins array. * @param {((a: CloningPlugin, b: CloningPlugin) => number)} [compareFn] - The function to make the new order of plugins. */ static reorderPlugins(compareFn?: ((a: CloningPlugin, b: CloningPlugin) => number)): void; /** * @returns {number} The total number of plugins registered in this specific instance. */ get size(): number; /** * @returns {string[]} An array containing the unique IDs of all plugins in this instance. */ get ids(): string[]; /** * @returns {CloningPlugin[]} A deep copy of the instance's plugins. */ get plugins(): CloningPlugin[]; /** * @param {CloningPlugin[]} newPlugins - An array of plugins to replace the current ones. * @throws {TypeError} If the input is not an array or if plugins do not implement the required interface. */ set plugins(newPlugins: CloningPlugin[]); /** * Adds a new plugin to the instance at a specified position. * * @param {CloningPlugin} plugin - The plugin to add. * @param {'start' | 'end' | 'index'} [position='start'] - The position where the plugin should be inserted. * @param {number} [index=0] - The specific index to use if position is set to 'index'. * @throws {TypeError} If the plugin is invalid, the position is unrecognized, or index is not a valid integer. */ addPlugin(plugin: CloningPlugin, position?: 'start' | 'end' | 'index', index?: number): void; /** * Checks if a plugin with the specified ID exists in this instance. * * @param {string} id - The ID of the plugin to search for. * @returns {boolean} True if the plugin exists, false otherwise. * @throws {TypeError} If the id is not a string. */ hasPlugin(id: string): boolean; /** * Removes a plugin from this instance by its ID. * * @param {string} id - The ID of the plugin to remove. * @returns {boolean} True if a plugin was removed, false if the plugin was not found. * @throws {TypeError} If the id is not a string. */ removePlugin(id: string): boolean; /** * Removes instance plugins that satisfy the provided predicate. * @param {(plugin: CloningPlugin) => boolean} predicate - A function that returns true for plugins to be removed. */ filterPlugins(predicate: (plugin: CloningPlugin) => boolean): void; /** * Updates an instance plugin at a specific index. * @param {number} index - The index of the plugin to update. * @param {CloningPlugin} plugin - The new plugin configuration. * @throws {RangeError} If the index is out of bounds. */ updatePlugin(index: number, plugin: CloningPlugin): void; /** * Reorders the instance's plugins array. * @param {((a: CloningPlugin, b: CloningPlugin) => number)} [compareFn] - The function to make the new order of plugins. */ reorderPlugins(compareFn?: ((a: CloningPlugin, b: CloningPlugin) => number)): void; /** * Performs the cloning operation on the provided item. * * @template {any} Value * @param {Value} item - The item to be cloned. * @param {boolean} [isDeep=true] - Whether to perform a deep clone (true) or a shallow clone (false). * @returns {Value} The cloned version of the input item. */ static clone(item: Value, isDeep?: boolean): Value; /** * Performs the cloning operation on the provided item. * * @template {any} Value * @param {Value} item - The item to be cloned. * @param {boolean} [isDeep=true] - Whether to perform a deep clone (true) or a shallow clone (false). * @returns {Value} The cloned version of the input item. */ clone(item: Value, isDeep?: boolean): Value; } export default TinyCloner; //# sourceMappingURL=TinyCloner.d.mts.map