MCPcopy Create free account
hub / github.com/avoidwork/filesize.js / safeClone

Function safeClone

src/filesize.js:238–246  ·  view source on GitHub ↗

* Safely clone an object using structuredClone with JSON fallback. * structuredClone can throw for functions, circular refs, etc.

(value)

Source from the content-addressed store, hash-verified

236 * structuredClone can throw for functions, circular refs, etc.
237 */
238 function safeClone(value) {
239 try {
240 return typeof structuredClone === "function"
241 ? structuredClone(value)
242 : JSON.parse(JSON.stringify(value));
243 } catch {
244 return JSON.parse(JSON.stringify(value));
245 }
246 }
247
248 const cloned = {
249 localeOptions: safeClone(localeOptions),

Callers 1

partialFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected