Fclone
Clone objects by dropping circular references
Install / Use
/learn @soyuka/FcloneREADME
FClone
Clone objects by dropping circular references
This module clones a Javascript object in safe mode (eg: drops circular values) recursively. Circular values are replaced with a string: '[Circular]'.
Ideas from tracker1/safe-clone-deep. I improved the workflow a bit by:
- refactoring the code (complete rewrite)
- fixing node 6+
- micro optimizations
- use of
Array.isArrayandBuffer.isBuffer
Node 0.10 compatible, distributed files are translated to es2015.
Installation
npm install fclone
# or
bower install fclone
Usage
const fclone = require('fclone');
let a = {c: 'hello'};
a.b = a;
let o = fclone(a);
console.log(o);
// outputs: { c: 'hello', b: '[Circular]' }
//JSON.stringify is now safe
console.log(JSON.stringify(o));
Benchmarks
Some benchs:
# Clone
fclone (not a string) x 14,121 ops/sec ±0.75% (89 runs sampled)
clone (not a string) x 9,293 ops/sec ±0.93% (90 runs sampled)
deepcopy (not a string) x 5,375 ops/sec ±0.73% (92 runs sampled)
rfdc x 12,786 ops/sec ±1.31% (91 runs sampled)
# Stringify
fclone + json.stringify x 8,289 ops/sec ±0.74% (90 runs sampled)
fast-safe-stringify x 8,241 ops/sec ±0.48% (92 runs sampled)
util.inspect (outputs a string) x 2,115 ops/sec ±0.84% (89 runs sampled)
jsan x 5,090 ops/sec ±0.65% (92 runs sampled)
circularjson x 4,471 ops/sec ±0.67% (92 runs sampled)
json-stringify-safe x 7,150 ops/sec ±0.97% (91 runs sampled)
Fastest is fclone (not a string)
Related Skills
node-connect
347.2kDiagnose OpenClaw node connection and pairing failures for Android, iOS, and macOS companion apps
frontend-design
108.0kCreate distinctive, production-grade frontend interfaces with high design quality. Use this skill when the user asks to build web components, pages, or applications. Generates creative, polished code that avoids generic AI aesthetics.
openai-whisper-api
347.2kTranscribe audio via OpenAI Audio Transcriptions API (Whisper).
qqbot-media
347.2kQQBot 富媒体收发能力。使用 <qqmedia> 标签,系统根据文件扩展名自动识别类型(图片/语音/视频/文件)。
