mirror of
https://github.com/renovatebot/renovate.git
synced 2026-10-24 14:34:21 +00:00
930cf6633c
fix: Additional vi.mock path corrections and prettier formatting
24 lines
576 B
TypeScript
24 lines
576 B
TypeScript
import { klona } from 'klona/json';
|
|
import { logger } from '../logger/index.ts';
|
|
import { quickStringify } from './stringify.ts';
|
|
|
|
/**
|
|
* Creates a deep clone of an object.
|
|
* @param input The object to clone.
|
|
*/
|
|
export function clone<T = unknown>(input: T): T {
|
|
try {
|
|
return klona(input);
|
|
} catch (err) {
|
|
logger.warn({ err }, 'error cloning object');
|
|
const str = quickStringify(input);
|
|
// v8 ignore else -- not easily testable
|
|
if (str) {
|
|
return JSON.parse(str) as T;
|
|
}
|
|
|
|
// istanbul ignore next: not easily testable
|
|
throw err;
|
|
}
|
|
}
|