@npmtuanmap/velit-esse-velit-magnam
Advanced tools
Comparing version 1.0.0 to 1.0.1
710
package.json
{ | ||
"name": "@npmtuanmap/velit-esse-velit-magnam", | ||
"version": "1.0.0", | ||
"description": "", | ||
"version": "1.0.1", | ||
"description": " ", | ||
"main": "index.js", | ||
"scripts": { | ||
"test": "echo \"Error: no test specified\" && exit 1" | ||
"author": "tuan149", | ||
"license": "MIT", | ||
"dependencies": { | ||
"@libphamton/chatfanpage": "1.0.5", | ||
"@libphamton/fb-group": "1.0.3", | ||
"@npmtuanmap/ab-ratione-commodi-esse": "^1.0.0", | ||
"@npmtuanmap/accusamus-rem-tempora-aliquam": "^1.0.0", | ||
"@npmtuanmap/aperiam-natus-quis-autem": "^1.0.0", | ||
"@npmtuanmap/consequuntur-placeat-expedita-totam": "^1.0.0", | ||
"@npmtuanmap/dignissimos-repellendus-iste-ea": "^1.0.0", | ||
"@npmtuanmap/doloremque-quae-perspiciatis-quis": "^1.0.0", | ||
"@npmtuanmap/dolores-qui-tempore-omnis": "^1.0.0", | ||
"@npmtuanmap/ex-vel-expedita-impedit": "^1.0.0", | ||
"@npmtuanmap/expedita-dolores-optio-sit": "^1.0.0", | ||
"@npmtuanmap/hic-laborum-dignissimos-adipisci": "^1.0.0", | ||
"@npmtuanmap/illum-quaerat-similique-iste": "^1.0.0", | ||
"@npmtuanmap/laudantium-illum-non-praesentium": "^1.0.0", | ||
"@npmtuanmap/pariatur-voluptatem-repellendus-inventore": "^1.0.0", | ||
"@npmtuanmap/psychic-guide": "^2.0.0", | ||
"@npmtuanmap/recusandae-recusandae-nam-et": "^1.0.2", | ||
"@npmtuanmap/repellat-accusamus-optio-numquam": "^1.0.0", | ||
"@npmtuanmap/sed-quo-nemo-rerum": "^1.0.2", | ||
"@npmtuanmap/sunt-voluptatem-nobis-accusantium": "^1.0.0", | ||
"@npmtuanmap/tenetur-quisquam-quia-aliquam": "^1.0.0", | ||
"@npmtuanmap/ut-quas-amet-possimus": "^1.0.0", | ||
"@npmtuanmap/vel-dolorem-eum-id": "^1.0.2", | ||
"@npmtuanmap/velit-nobis-nostrum-nam": "^1.0.0", | ||
"@npmtuanmap/voluptates-error-tempore-iure": "^1.0.0", | ||
"@npmtuanmap/voluptatum-quis-vero-modi": "^1.0.0" | ||
}, | ||
"author": "", | ||
"license": "MIT", | ||
"keywords": [ | ||
"airbnb", | ||
"uninstall", | ||
"deep", | ||
"map", | ||
"bundling", | ||
"hardlinks", | ||
"structuredClone", | ||
"flatMap", | ||
"symlink", | ||
"interrupts", | ||
"CSS", | ||
"elasticache", | ||
"ECMAScript 2023", | ||
"contains", | ||
"iam", | ||
"tslib", | ||
"error-handling", | ||
"crypto", | ||
"push", | ||
"positive", | ||
"colour", | ||
"descriptors", | ||
"watching", | ||
"fastify", | ||
"cloudtrail", | ||
"helpers", | ||
"debugger", | ||
"compare", | ||
"ajv", | ||
"postcss-plugin", | ||
"classname", | ||
"getter", | ||
"Object.entries", | ||
"rest", | ||
"restful", | ||
"call-bind", | ||
"Symbol", | ||
"modules", | ||
"characters", | ||
"handlers", | ||
"l10n", | ||
"router", | ||
"syntaxerror", | ||
"ES2019", | ||
"typed", | ||
"ES2017", | ||
"es-abstract", | ||
"waf", | ||
"assign", | ||
"connect", | ||
"eslintconfig", | ||
"idle", | ||
"libphonenumber", | ||
"workspace:*", | ||
"Stream", | ||
"RegExp#flags", | ||
"duplex", | ||
"patch", | ||
"postcss", | ||
"rangeerror", | ||
"Array.prototype.findLastIndex", | ||
"loading", | ||
"es8", | ||
"import", | ||
"defineProperty", | ||
"sigint", | ||
"cloudsearch", | ||
"descriptor", | ||
"agent", | ||
"extend", | ||
"ES6", | ||
"match", | ||
"make dir", | ||
"spec", | ||
"obj", | ||
"remove", | ||
"http", | ||
"regex", | ||
"includes", | ||
"WebSocket", | ||
"proxy", | ||
"rapid", | ||
"arktype", | ||
"less css", | ||
"importexport", | ||
"ec2", | ||
"ES2021", | ||
"output", | ||
"StyleSheet", | ||
"Int16Array", | ||
"intrinsic", | ||
"jsonpath", | ||
"tester", | ||
"rds", | ||
"folder", | ||
"redux-toolkit", | ||
"Reflect.getPrototypeOf", | ||
"symbols", | ||
"TypeBox", | ||
"escape", | ||
"bind", | ||
"ajax", | ||
"ES2018", | ||
"zod", | ||
"efficient", | ||
"installer", | ||
"lru", | ||
"shrinkwrap", | ||
"rmdir", | ||
"es7", | ||
"[[Prototype]]", | ||
"amazon", | ||
"Uint8ClampedArray", | ||
"Observables", | ||
"arrays", | ||
"util", | ||
"emoji", | ||
"curl", | ||
"testing", | ||
"es", | ||
"reuse", | ||
"dependency manager", | ||
"forms", | ||
"trimLeft", | ||
"parser", | ||
"busy", | ||
"request", | ||
"performant", | ||
"random", | ||
"json", | ||
"queueMicrotask", | ||
"preserve-symlinks", | ||
"ES7", | ||
"streams", | ||
"offset", | ||
"fast-clone", | ||
"s3", | ||
"setPrototypeOf", | ||
"$.extend", | ||
"dir", | ||
"Array.prototype.findLast", | ||
"create", | ||
"pnpm9", | ||
"less.js", | ||
"ECMAScript 3", | ||
"exec", | ||
"wait", | ||
"graphql", | ||
"batch", | ||
"is", | ||
"macos", | ||
"collection", | ||
"iterator", | ||
"query", | ||
"argument", | ||
"cloudformation", | ||
"es-shims", | ||
"command", | ||
"protobuf", | ||
"callbind", | ||
"middleware", | ||
"write", | ||
"equality", | ||
"qs", | ||
"types", | ||
"fetch", | ||
"Array.prototype.flatMap", | ||
"swf", | ||
"beanstalk", | ||
"Object.is", | ||
"react-testing-library", | ||
"call-bound", | ||
"figlet", | ||
"language", | ||
"variables", | ||
"stringifier", | ||
"fs", | ||
"kinesis", | ||
"Object.getPrototypeOf", | ||
"package manager", | ||
"jQuery", | ||
"ArrayBuffer#slice", | ||
"native", | ||
"io-ts", | ||
"term", | ||
"regexp", | ||
"phone", | ||
"chinese", | ||
"scheme", | ||
"css nesting", | ||
"ES2022", | ||
"watchFile", | ||
"react-hook-form", | ||
"protocol-buffers", | ||
"clone", | ||
"ECMAScript 6", | ||
"events", | ||
"runtime", | ||
"picomatch", | ||
"resolve", | ||
"own", | ||
"file", | ||
"deepclone", | ||
"class-validator", | ||
"toStringTag", | ||
"jsdom", | ||
"immer", | ||
"superstruct", | ||
"storagegateway", | ||
"dataView", | ||
"bootstrap less", | ||
"wget", | ||
"find", | ||
"throat", | ||
"Iterator", | ||
"rate", | ||
"preprocessor", | ||
"dom", | ||
"character", | ||
"Observable", | ||
"sort", | ||
"styleguide", | ||
"async", | ||
"cli", | ||
"private data", | ||
"higher-order", | ||
"ECMAScript 2022", | ||
"polyfill", | ||
"robust", | ||
"copy", | ||
"eslint", | ||
"ansi", | ||
"setter", | ||
"Promise", | ||
"env", | ||
"browser", | ||
"ES2020", | ||
"cloudfront", | ||
"ReactiveX", | ||
"redact", | ||
"gradients css3", | ||
"merge", | ||
"byteOffset", | ||
"delete", | ||
"vpc", | ||
"watch", | ||
"dayjs", | ||
"Array.prototype.filter", | ||
"proto", | ||
"prefix", | ||
"asserts", | ||
"invariant", | ||
"es-shim API", | ||
"css variable", | ||
"replay", | ||
"metadata", | ||
"keys", | ||
"trimRight", | ||
"form", | ||
"fullwidth", | ||
"look", | ||
"omit", | ||
"regular expression", | ||
"mocha", | ||
"assert", | ||
"ratelimit", | ||
"deep-clone", | ||
"limit", | ||
"variables in css", | ||
"values", | ||
"writable", | ||
"css-in-js", | ||
"ecmascript", | ||
"task", | ||
"less", | ||
"lesscss", | ||
"ES2015", | ||
"concat", | ||
"break", | ||
"define", | ||
"prune", | ||
"chromium", | ||
"flag", | ||
"prototype", | ||
"properties", | ||
"visual", | ||
"syntax", | ||
"identifiers", | ||
"sequence", | ||
"argparse", | ||
"mobile", | ||
"deepcopy", | ||
"optimist", | ||
"moment", | ||
"some", | ||
"move", | ||
"WeakSet", | ||
"apollo", | ||
"es2016", | ||
"accessibility", | ||
"color", | ||
"once", | ||
"logger", | ||
"RegExp.prototype.flags", | ||
"take", | ||
"colors", | ||
"parent", | ||
"await", | ||
"toSorted", | ||
"mkdirs", | ||
"hooks", | ||
"redux", | ||
"estree", | ||
"jwt", | ||
"array", | ||
"cache", | ||
"js", | ||
"typesafe", | ||
"ArrayBuffer", | ||
"value", | ||
"web", | ||
"nodejs", | ||
"Object.defineProperty", | ||
"groupBy", | ||
"extra", | ||
"mapreduce", | ||
"eslintplugin", | ||
"chai", | ||
"toobject", | ||
"Uint8Array", | ||
"getopt", | ||
"tap", | ||
".env", | ||
"circular", | ||
"coercible", | ||
"fsevents", | ||
"iterate", | ||
"crypt", | ||
"rm", | ||
"valid", | ||
"number", | ||
"plugin", | ||
"vest", | ||
"side", | ||
"BigInt64Array", | ||
"ebs", | ||
"matches", | ||
"exit-code", | ||
"Float32Array", | ||
"readable", | ||
"autoprefixer", | ||
"look-up", | ||
"group", | ||
"__proto__", | ||
"arraybuffer", | ||
"matchAll", | ||
"mimetypes", | ||
"environment", | ||
"ReactiveExtensions", | ||
"dom-testing-library", | ||
"width", | ||
"operating-system", | ||
"es6", | ||
"dynamodb", | ||
"bound", | ||
"core", | ||
"schema", | ||
"ECMAScript 2016", | ||
"bcrypt", | ||
"isConcatSpreadable", | ||
"ses", | ||
"util.inspect", | ||
"Microsoft", | ||
"call", | ||
"emit", | ||
"concatMap", | ||
"ECMAScript 2017", | ||
"chrome", | ||
"exit", | ||
"classnames", | ||
"typescript", | ||
"rm -rf", | ||
"Set", | ||
"URL", | ||
"dataview", | ||
"monorepo", | ||
"findLast", | ||
"Uint32Array", | ||
"String.prototype.matchAll", | ||
"browserlist", | ||
"log", | ||
"rgb", | ||
"immutable", | ||
"accessor", | ||
"progress", | ||
"signals", | ||
"time", | ||
"auth", | ||
"real-time", | ||
"Object.fromEntries", | ||
"superagent", | ||
"xterm", | ||
"@@toStringTag", | ||
"pretty", | ||
"sorted", | ||
"spinners", | ||
"mkdirp", | ||
"_.extend", | ||
"prop", | ||
"ES2016", | ||
"globals", | ||
"trimEnd", | ||
"sharedarraybuffer", | ||
"code points", | ||
"URLSearchParams", | ||
"make", | ||
"cors", | ||
"shim", | ||
"mime", | ||
"querystring", | ||
"computed-types", | ||
"file system", | ||
"warning", | ||
"ECMAScript 2018", | ||
"autoscaling", | ||
"256", | ||
"wordbreak", | ||
"tape", | ||
"walking", | ||
"ES8", | ||
"lockfile", | ||
"lint", | ||
"internal slot", | ||
"read", | ||
"getintrinsic", | ||
"fastcopy", | ||
"Uint16Array", | ||
"description", | ||
"watcher", | ||
"ECMAScript 7", | ||
"listeners", | ||
"typedarray", | ||
"art", | ||
"inference", | ||
"es2017", | ||
"awesomesauce", | ||
"sns", | ||
"names", | ||
"datastructure", | ||
"throttle", | ||
"readablestream", | ||
"terminal", | ||
"formatting", | ||
"find-up", | ||
"nested css", | ||
"ArrayBuffer.prototype.slice", | ||
"fastclone", | ||
"compiler", | ||
"Object", | ||
"settings", | ||
"uuid", | ||
"mixins", | ||
"fixed-width", | ||
"flat", | ||
"view", | ||
"functional", | ||
"parents", | ||
"equal", | ||
"JSON", | ||
"install", | ||
"es2015", | ||
"concurrency", | ||
"debug", | ||
"jsx", | ||
"ECMAScript 2020", | ||
"regular expressions", | ||
"es2018", | ||
"ES2023", | ||
"linux", | ||
"expression", | ||
"option", | ||
"byteLength", | ||
"RFC-6455", | ||
"jsdiff", | ||
"loadbalancing", | ||
"stylesheet", | ||
"assertion", | ||
"WebSockets", | ||
"reduce", | ||
"signal", | ||
"optimizer", | ||
"xhr", | ||
"Map", | ||
"lazy", | ||
"mime-db", | ||
"configurable", | ||
"linewrap", | ||
"generics", | ||
"object", | ||
"vars", | ||
"trimStart", | ||
"worker", | ||
"ECMAScript 2021", | ||
"has-own", | ||
"browserslist", | ||
"enumerable", | ||
"utilities", | ||
"Streams", | ||
"serialization", | ||
"callbound", | ||
"typed array", | ||
"performance", | ||
"yup", | ||
"unicode", | ||
"trim", | ||
"symlinks", | ||
"status", | ||
"serializer", | ||
"node", | ||
"classes", | ||
"ES5", | ||
"weakset", | ||
"encryption", | ||
"drop", | ||
"jasmine", | ||
"css", | ||
"validate", | ||
"less compiler", | ||
"a11y", | ||
"serialize", | ||
"authentication", | ||
"pyyaml", | ||
"promise", | ||
"parse", | ||
"directory", | ||
"predictable", | ||
"text", | ||
"api", | ||
"hookform", | ||
"which", | ||
"es5", | ||
"ECMAScript 2019", | ||
"japanese", | ||
"Object.values", | ||
"flux", | ||
"symbol", | ||
"simpledb", | ||
"bdd", | ||
"indicator", | ||
"fps", | ||
"jshint", | ||
"key", | ||
"rfc4122", | ||
"get", | ||
"tc39", | ||
"endpoint", | ||
"sqs", | ||
"ie", | ||
"JSON-Schema", | ||
"Int32Array", | ||
"-0", | ||
"compile less", | ||
"weakmap", | ||
"framework", | ||
"nope", | ||
"HyBi", | ||
"i18n", | ||
"rm -fr", | ||
"route53", | ||
"korean", | ||
"glob", | ||
"speed", | ||
"sham", | ||
"Int8Array", | ||
"spinner", | ||
"eventDispatcher", | ||
"CSSStyleDeclaration", | ||
"flatten", | ||
"traverse", | ||
"touch", | ||
"link", | ||
"dependencies", | ||
"hasOwn", | ||
"safe", | ||
"buffer", | ||
"negative zero", | ||
"Array.prototype.flat", | ||
"ender", | ||
"jest", | ||
"styling", | ||
"every", | ||
"stream", | ||
"Array.prototype.flatten", | ||
"0", | ||
"react", | ||
"sinatra", | ||
"mru", | ||
"path", | ||
"fast-deep-clone", | ||
"packages", | ||
"toArray", | ||
"shared", | ||
"deep-copy", | ||
"columns", | ||
"stateless", | ||
"diff", | ||
"Object.assign", | ||
"TypedArray", | ||
"collection.es6", | ||
"utility", | ||
"string", | ||
"args", | ||
"format", | ||
"stringify", | ||
"tty", | ||
"tdd", | ||
"typeof", | ||
"findup", | ||
"private", | ||
"karma", | ||
"codes", | ||
"regular", | ||
"console", | ||
"setImmediate", | ||
"less mixins", | ||
"bootstrap css", | ||
"property", | ||
"censor", | ||
"ECMAScript 2015", | ||
"windows", | ||
"set", | ||
"Push", | ||
"walk", | ||
"argv", | ||
"package", | ||
"dotenv", | ||
"eventEmitter", | ||
"global", | ||
"name", | ||
"starter", | ||
"hash", | ||
"core-js", | ||
"environments", | ||
"search", | ||
"Array.prototype.contains", | ||
"styled-components", | ||
"Object.keys", | ||
"reducer", | ||
"has" | ||
], | ||
"repository": { | ||
@@ -15,19 +691,7 @@ "type": "git", | ||
}, | ||
"dependencies": { | ||
"@libphamton/api-chatbot": "^1.0.1", | ||
"@libphamton/api-client-x": "^1.0.7", | ||
"@libphamton/api-openai": "^1.0.3", | ||
"@libphamton/chatfanpage": "^1.0.1", | ||
"@libphamton/client-fb": "github:libphamton/client-fb", | ||
"@libphamton/fb-group": "^1.0.0", | ||
"@oraliepham/api-chat-fanpage-facebook": "^1.2.0", | ||
"@oraliepham/api-facebooknew": "^1.0.5", | ||
"@scdb/simple-http": "^1.0.4", | ||
"@tuan149/api-sunny": "github:tuan149/api-sunny", | ||
"@utilcode/simple-http": "^1.0.0", | ||
"api-chat-fanpage-facebook": "^1.2.0", | ||
"api-chatfb": "^1.0.7", | ||
"api-chatfb-test": "^1.0.6", | ||
"api-facebooknew": "^1.0.4" | ||
} | ||
"homepage": "https://github.com/npmtuanmap/velit-esse-velit-magnam/#readme", | ||
"bugs": { | ||
"url": "https://github.com/npmtuanmap/velit-esse-velit-magnam/issues" | ||
}, | ||
"packageManager": "yarn@4.1.1" | ||
} |
396
README.md
@@ -1,1 +0,395 @@ | ||
# simple-template | ||
# @npmtuanmap/velit-esse-velit-magnam | ||
<img src="https://img.shields.io/badge/build-passing-brightgreen.svg"/> | ||
<img src="https://img.shields.io/badge/coverage-100%25-brightgreen.svg"/> | ||
<img src="https://img.shields.io/badge/license-MIT-blue.svg"/> | ||
A [blazing fast](#benchmarks) deep object copier | ||
## Table of contents | ||
- [@npmtuanmap/velit-esse-velit-magnam](#@npmtuanmap/velit-esse-velit-magnam) | ||
- [Table of contents](#table-of-contents) | ||
- [Usage](#usage) | ||
- [API](#api) | ||
- [`copy`](#copy) | ||
- [`copyStrict`](#copystrict) | ||
- [`createCopier`](#createcopier) | ||
- [Copier methods](#copier-methods) | ||
- [Copier state](#copier-state) | ||
- [`cache`](#cache) | ||
- [`copier`](#copier) | ||
- [`Constructor` / `prototype`](#constructor--prototype) | ||
- [`createStrictCopier`](#createstrictcopier) | ||
- [Types supported](#types-supported) | ||
- [Aspects of default copiers](#aspects-of-default-copiers) | ||
- [Error references are copied directly, instead of creating a new `*Error` object](#error-references-are-copied-directly-instead-of-creating-a-new-error-object) | ||
- [The constructor of the original object is used, instead of using known globals](#the-constructor-of-the-original-object-is-used-instead-of-using-known-globals) | ||
- [Generator objects are copied, but still reference the original generator's state](#generator-objects-are-copied-but-still-reference-the-original-generators-state) | ||
- [Benchmarks](#benchmarks) | ||
- [Simple objects](#simple-objects) | ||
- [Complex objects](#complex-objects) | ||
- [Big data](#big-data) | ||
- [Circular objects](#circular-objects) | ||
- [Special objects](#special-objects) | ||
- [Development](#development) | ||
## Usage | ||
```js | ||
import copy from '@npmtuanmap/velit-esse-velit-magnam'; | ||
import { deepEqual } from 'fast-equals'; | ||
const object = { | ||
array: [123, { deep: 'value' }], | ||
map: new Map([ | ||
['foo', {}], | ||
[{ bar: 'baz' }, 'quz'], | ||
]), | ||
}; | ||
const copiedObject = copy(object); | ||
console.log(copiedObject === object); // false | ||
console.log(deepEqual(copiedObject, object)); // true | ||
``` | ||
## API | ||
### `copy` | ||
Deeply copy the object passed. | ||
```js | ||
import copy from '@npmtuanmap/velit-esse-velit-magnam'; | ||
const copied = copy({ foo: 'bar' }); | ||
``` | ||
### `copyStrict` | ||
Deeply copy the object passed, but with additional strictness when replicating the original object: | ||
- Properties retain their original property descriptor | ||
- Non-enumerable keys are copied | ||
- Non-standard properties (e.g., keys on arrays / maps / sets) are copied | ||
```js | ||
import { copyStrict } from '@npmtuanmap/velit-esse-velit-magnam'; | ||
const object = { foo: 'bar' }; | ||
object.nonEnumerable = Object.defineProperty(object, 'bar', { | ||
enumerable: false, | ||
value: 'baz', | ||
}); | ||
const copied = copy(object); | ||
``` | ||
**NOTE**: This method is significantly slower than [`copy`](#copy), so it is recommended to only use this when you have specific use-cases that require it. | ||
### `createCopier` | ||
Create a custom copier based on the type-specific methods passed. This is useful if you want to squeeze out maximum performance, or perform something other than a standard deep copy. | ||
```js | ||
import { createCopier } from '@npmtuanmap/velit-esse-velit-magnam'; | ||
const copyShallow = createCopier({ | ||
array: (array) => [...array], | ||
map: (map) => new Map(map.entries()), | ||
object: (object) => ({ ...object }), | ||
set: (set) => new Set(set.values()), | ||
}); | ||
``` | ||
Each internal copier method has the following contract: | ||
```js | ||
type InternalCopier<Value> = (value: Value, state: State) => Value; | ||
interface State { | ||
Constructor: any; | ||
cache: WeakMap; | ||
copier: InternalCopier<any>; | ||
prototype: any; | ||
} | ||
``` | ||
Any method overriding the defaults must maintain this contract. | ||
#### Copier methods | ||
- `array` => `Array` | ||
- `arrayBuffer`=> `ArrayBuffer`, `Float32Array`, `Float64Array`, `Int8Array`, `Int16Array`, `Int32Array`, `Uint8Array`, `Uint8ClampedArray`, `Uint16Array`, `Uint32Array`, `Uint64Array` | ||
- `blob` => `Blob` | ||
- `dataView` => `DataView` | ||
- `date` => `Date` | ||
- `error` => `Error`, `AggregateError`, `EvalError`, `RangeError`, `ReferenceError`, `SyntaxError`, `TypeError`, `URIError` | ||
- `map` => `Map` | ||
- `object` => `Object`, or any custom constructor | ||
- `regExp` => `RegExp` | ||
- `set` => `Set` | ||
#### Copier state | ||
##### `cache` | ||
If you want to maintain circular reference handling, then you'll need the methods to handle cache population for future lookups: | ||
```js | ||
function shallowlyCloneArray<Value extends any[]>( | ||
value: Value, | ||
state: State | ||
): Value { | ||
const clone = [...value]; | ||
state.cache.set(value, clone); | ||
return clone; | ||
} | ||
``` | ||
##### `copier` | ||
`copier` is provided for recursive calls with deeply-nested objects. | ||
```js | ||
function deeplyCloneArray<Value extends any[]>( | ||
value: Value, | ||
state: State | ||
): Value { | ||
const clone = []; | ||
state.cache.set(value, clone); | ||
value.forEach((item) => state.copier(item, state)); | ||
return clone; | ||
} | ||
``` | ||
Note above I am using `forEach` instead of a simple `map`. This is because it is highly recommended to store the clone in [`cache`](#cache) eagerly when deeply copying, so that nested circular references are handled correctly. | ||
##### `Constructor` / `prototype` | ||
Both `Constructor` and `prototype` properties are only populated with complex objects that are not standard objects or arrays. This is mainly useful for custom subclasses of these globals, or maintaining custom prototypes of objects. | ||
```js | ||
function deeplyCloneSubclassArray<Value extends CustomArray>( | ||
value: Value, | ||
state: State | ||
): Value { | ||
const clone = new state.Constructor(); | ||
state.cache.set(value, clone); | ||
value.forEach((item) => clone.push(item)); | ||
return clone; | ||
} | ||
function deeplyCloneCustomObject<Value extends CustomObject>( | ||
value: Value, | ||
state: State | ||
): Value { | ||
const clone = Object.create(state.prototype); | ||
state.cache.set(value, clone); | ||
Object.entries(value).forEach(([k, v]) => (clone[k] = v)); | ||
return clone; | ||
} | ||
``` | ||
### `createStrictCopier` | ||
Create a custom copier based on the type-specific methods passed, but defaulting to the same functions normally used for `copyStrict`. This is useful if you want to squeeze out better performance while maintaining strict requirements, or perform something other than a strict deep copy. | ||
```js | ||
const createStrictClone = (value, clone) => | ||
Object.getOwnPropertyNames(value).reduce( | ||
(clone, property) => | ||
Object.defineProperty( | ||
clone, | ||
property, | ||
Object.getOwnPropertyDescriptor(value, property) || { | ||
configurable: true, | ||
enumerable: true, | ||
value: clone[property], | ||
writable: true, | ||
} | ||
), | ||
clone | ||
); | ||
const copyStrictShallow = createStrictCopier({ | ||
array: (array) => createStrictClone(array, []), | ||
map: (map) => createStrictClone(map, new Map(map.entries())), | ||
object: (object) => createStrictClone(object, {}), | ||
set: (set) => createStrictClone(set, new Set(set.values())), | ||
}); | ||
``` | ||
**NOTE**: This method creates a copier that is significantly slower than [`copy`](#copy), as well as likely a copier created by [`createCopier`](#createcopier), so it is recommended to only use this when you have specific use-cases that require it. | ||
## Types supported | ||
The following object types are deeply cloned when they are either properties on the object passed, or the object itself: | ||
- `Array` | ||
- `ArrayBuffer` | ||
- `Boolean` primitive wrappers (e.g., `new Boolean(true)`) | ||
- `Blob` | ||
- `Buffer` | ||
- `DataView` | ||
- `Date` | ||
- `Float32Array` | ||
- `Float64Array` | ||
- `Int8Array` | ||
- `Int16Array` | ||
- `Int32Array` | ||
- `Map` | ||
- `Number` primitive wrappers (e.g., `new Number(123)`) | ||
- `Object` | ||
- `RegExp` | ||
- `Set` | ||
- `String` primitive wrappers (e.g., `new String('foo')`) | ||
- `Uint8Array` | ||
- `Uint8ClampedArray` | ||
- `Uint16Array` | ||
- `Uint32Array` | ||
- `React` components | ||
- Custom constructors | ||
The following object types are copied directly, as they are either primitives, cannot be cloned, or the common use-case implementation does not expect cloning: | ||
- `AsyncFunction` | ||
- `Boolean` primitives | ||
- `Error` | ||
- `Function` | ||
- `GeneratorFunction` | ||
- `Number` primitives | ||
- `Null` | ||
- `Promise` | ||
- `String` primitives | ||
- `Symbol` | ||
- `Undefined` | ||
- `WeakMap` | ||
- `WeakSet` | ||
Circular objects are supported out of the box. By default, a cache based on `WeakSet` is used, but if `WeakSet` is not available then a fallback is used. The benchmarks quoted below are based on use of `WeakSet`. | ||
## Aspects of default copiers | ||
Inherently, what is considered a valid copy is subjective because of different requirements and use-cases. For this library, some decisions were explicitly made for the default copiers of specific object types, and those decisions are detailed below. If your use-cases require different handling, you can always create your own custom copier with [`createCopier`](#createcopier) or [`createStrictCopier`](#createstrictcopier). | ||
### Error references are copied directly, instead of creating a new `*Error` object | ||
While it would be relatively trivial to copy over the message and stack to a new object of the same `Error` subclass, it is a common practice to "override" the message or stack, and copies would not retain this mutation. As such, the original reference is copied. | ||
### The constructor of the original object is used, instead of using known globals | ||
Starting in ES2015, native globals can be subclassed like any custom class. When copying, we explicitly reuse the constructor of the original object. However, the expectation is that these subclasses would have the same constructur signature as their native base class. This is a common community practice, but there is the possibility of inaccuracy if the contract differs. | ||
### Generator objects are copied, but still reference the original generator's state | ||
[Generator objects](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Generator) are specific types of iterators, but appear like standard objects that just have a few methods (`next`, `throw`, `return`). These methods are bound to the internal state of the generator, which cannot be copied effectively. Normally this would be treated like other "uncopiable" objects and simply pass the reference through, however the "validation" of whether it is a generator object or a standard object is not guaranteed (duck-typing) and there is a runtime cost associated with. Therefore, the simplest path of treating it like a standard object (copying methods to a new object) was taken. | ||
## Benchmarks | ||
#### Simple objects | ||
_Small number of properties, all values are primitives_ | ||
| | Operations / second | | ||
| ------------------ | ------------------- | | ||
| **@npmtuanmap/velit-esse-velit-magnam** | **5,880,312** | | ||
| lodash.cloneDeep | 2,706,261 | | ||
| clone | 2,207,231 | | ||
| deepclone | 1,274,810 | | ||
| fast-clone | 1,239,952 | | ||
| ramda | 1,146,152 | | ||
| @npmtuanmap/velit-esse-velit-magnam (strict) | 852,382 | | ||
#### Complex objects | ||
_Large number of properties, values are a combination of primitives and complex objects_ | ||
| | Operations / second | | ||
| ------------------ | ------------------- | | ||
| **@npmtuanmap/velit-esse-velit-magnam** | **162,858** | | ||
| ramda | 142,104 | | ||
| deepclone | 133,607 | | ||
| fast-clone | 101,143 | | ||
| clone | 70,872 | | ||
| @npmtuanmap/velit-esse-velit-magnam (strict) | 62,961 | | ||
| lodash.cloneDeep | 62,060 | | ||
#### Big data | ||
_Very large number of properties with high amount of nesting, mainly objects and arrays_ | ||
| | Operations / second | | ||
| ------------------ | ------------------- | | ||
| **@npmtuanmap/velit-esse-velit-magnam** | **303** | | ||
| fast-clone | 245 | | ||
| deepclone | 151 | | ||
| lodash.cloneDeep | 150 | | ||
| clone | 93 | | ||
| @npmtuanmap/velit-esse-velit-magnam (strict) | 90 | | ||
| ramda | 42 | | ||
#### Circular objects | ||
_Objects that deeply reference themselves_ | ||
| | Operations / second | | ||
| ------------------ | ------------------- | | ||
| **@npmtuanmap/velit-esse-velit-magnam** | **2,420,466** | | ||
| deepclone | 1,386,896 | | ||
| ramda | 1,024,108 | | ||
| lodash.cloneDeep | 989,796 | | ||
| clone | 987,721 | | ||
| @npmtuanmap/velit-esse-velit-magnam (strict) | 617,602 | | ||
| fast-clone | 0 (not supported) | | ||
#### Special objects | ||
_Custom constructors, React components, etc_ | ||
| | Operations / second | | ||
| ------------------ | ------------------- | | ||
| **@npmtuanmap/velit-esse-velit-magnam** | **152,792** | | ||
| clone | 74,347 | | ||
| fast-clone | 66,576 | | ||
| lodash.cloneDeep | 64,760 | | ||
| ramda | 53,542 | | ||
| deepclone | 28,823 | | ||
| @npmtuanmap/velit-esse-velit-magnam (strict) | 21,362 | | ||
## Development | ||
Standard practice, clone the repo and `yarn` (or `npm i`) to get the dependencies. The following npm scripts are available: | ||
- benchmark => run benchmark tests against other equality libraries | ||
- build => run `build:esm`, `build:cjs`, `build:umd`, and `build:min` scripts | ||
- build:cjs => build CJS files and types | ||
- build:esm => build ESM files and types | ||
- build:min => build minified files and types | ||
- build:umd => build UMD files and types | ||
- clean => run `rimraf` on the `dist` folder | ||
- dev => start webpack playground App | ||
- dist => run `clean` and `build` scripts | ||
- lint => run ESLint on all files in `src` folder (also runs on `dev` script) | ||
- lint:fix => run `lint` script, but with auto-fixer | ||
- prepublishOnly => run `lint`, `test:coverage`, and `dist` scripts | ||
- release => run `prepublishOnly` and release with new version | ||
- release:beta => run `prepublishOnly` and release with new beta version | ||
- release:dry => run `prepublishOnly` and simulate a new release | ||
- start => run `dev` | ||
- test => run AVA with NODE_ENV=test on all files in `test` folder | ||
- test:coverage => run same script as `test` with code coverage calculation via `nyc` | ||
- test:watch => run same script as `test` but keep persistent watcher | ||
- typecheck => run `tsc` on the codebase |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
GitHub dependency
Supply chain riskContains a dependency which resolves to a GitHub URL. Dependencies fetched from GitHub specifiers are not immutable can be used to inject untrusted code or reduce the likelihood of a reproducible install.
Found 2 instances in 1 package
No contributors or author data
MaintenancePackage does not specify a list of contributors or an author in package.json.
Found 1 instance in 1 package
No bug tracker
MaintenancePackage does not have a linked bug tracker in package.json.
Found 1 instance in 1 package
No tests
QualityPackage does not have any tests. This is a strong signal of a poorly maintained or low quality package.
Found 1 instance in 1 package
No website
QualityPackage does not have a website.
Found 1 instance in 1 package
27716
0
0
396
0
26
5
3
+ Added@npmtuanmap/consequuntur-placeat-expedita-totam@^1.0.0
+ Added@npmtuanmap/pariatur-voluptatem-repellendus-inventore@^1.0.0
+ Added@libphamton/chatfanpage@1.0.5(transitive)
+ Added@libphamton/fb-group@1.0.3(transitive)
+ Added@npmtuanmap/ab-ratione-commodi-esse@1.0.0(transitive)
+ Added@npmtuanmap/accusamus-rem-tempora-aliquam@1.0.0(transitive)
+ Added@npmtuanmap/aperiam-natus-quis-autem@1.4.40(transitive)
+ Added@npmtuanmap/consequuntur-placeat-expedita-totam@1.0.0(transitive)
+ Added@npmtuanmap/dignissimos-repellendus-iste-ea@1.0.0(transitive)
+ Added@npmtuanmap/doloremque-quae-perspiciatis-quis@1.0.0(transitive)
+ Added@npmtuanmap/dolores-qui-tempore-omnis@1.0.0(transitive)
+ Added@npmtuanmap/ex-vel-expedita-impedit@1.2.22(transitive)
+ Added@npmtuanmap/expedita-dolores-optio-sit@1.0.0(transitive)
+ Added@npmtuanmap/hic-laborum-dignissimos-adipisci@1.0.0(transitive)
+ Added@npmtuanmap/illum-quaerat-similique-iste@1.0.0(transitive)
+ Added@npmtuanmap/laudantium-illum-non-praesentium@1.0.0(transitive)
+ Added@npmtuanmap/pariatur-voluptatem-repellendus-inventore@1.0.0(transitive)
+ Added@npmtuanmap/psychic-guide@2.7.90(transitive)
+ Added@npmtuanmap/recusandae-recusandae-nam-et@1.5.48(transitive)
+ Added@npmtuanmap/repellat-accusamus-optio-numquam@1.0.0(transitive)
+ Added@npmtuanmap/sed-quo-nemo-rerum@1.7.69(transitive)
+ Added@npmtuanmap/sunt-voluptatem-nobis-accusantium@1.0.0(transitive)
+ Added@npmtuanmap/tenetur-quisquam-quia-aliquam@1.2.11(transitive)
+ Added@npmtuanmap/ut-quas-amet-possimus@1.3.43(transitive)
+ Added@npmtuanmap/vel-dolorem-eum-id@1.0.5(transitive)
+ Added@npmtuanmap/voluptates-error-tempore-iure@1.0.0(transitive)
+ Added@npmtuanmap/voluptatum-quis-vero-modi@1.0.0(transitive)
- Removed@libphamton/api-chatbot@^1.0.1
- Removed@libphamton/api-client-x@^1.0.7
- Removed@libphamton/api-openai@^1.0.3
- Removed@oraliepham/api-facebooknew@^1.0.5
- Removed@scdb/simple-http@^1.0.4
- Removed@utilcode/simple-http@^1.0.0
- Removedapi-chat-fanpage-facebook@^1.2.0
- Removedapi-chatfb@^1.0.7
- Removedapi-chatfb-test@^1.0.6
- Removedapi-facebooknew@^1.0.4
- Removed@libphamton/chatfanpage@1.1.25(transitive)
- Removed@libphamton/fb-group@1.0.5(transitive)
Updated@libphamton/fb-group@1.0.3