MCPcopy Index your code
hub / github.com/SocketCluster/socketcluster / clone

Function clone

app/public/socketcluster-client.js:7495–7531  ·  view source on GitHub ↗
(val, deep)

Source from the content-addressed store, hash-verified

7493const typeOf = require('kind-of');
7494
7495function clone(val, deep) {
7496 switch (typeOf(val)) {
7497 case 'array':
7498 return val.slice();
7499 case 'object':
7500 return Object.assign({}, val);
7501 case 'date':
7502 return new val.constructor(Number(val));
7503 case 'map':
7504 return new Map(val);
7505 case 'set':
7506 return new Set(val);
7507 case 'buffer':
7508 return cloneBuffer(val);
7509 case 'symbol':
7510 return cloneSymbol(val);
7511 case 'arraybuffer':
7512 return cloneArrayBuffer(val);
7513 case 'float32array':
7514 case 'float64array':
7515 case 'int16array':
7516 case 'int32array':
7517 case 'int8array':
7518 case 'uint16array':
7519 case 'uint32array':
7520 case 'uint8clampedarray':
7521 case 'uint8array':
7522 return cloneTypedArray(val);
7523 case 'regexp':
7524 return cloneRegExp(val);
7525 case 'error':
7526 return Object.create(val);
7527 default: {
7528 return val;
7529 }
7530 }
7531}
7532
7533function cloneRegExp(val) {
7534 const flags = val.flags !== void 0 ? val.flags : (/\w+$/.exec(val) || void 0);

Callers 1

cloneDeepFunction · 0.85

Calls 5

cloneBufferFunction · 0.85
cloneSymbolFunction · 0.85
cloneArrayBufferFunction · 0.85
cloneTypedArrayFunction · 0.85
cloneRegExpFunction · 0.85

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…