{"_id":"@crabas0npm/ut-cumque-iure","name":"@crabas0npm/ut-cumque-iure","dist-tags":{"latest":"1.0.0"},"versions":{"1.0.0":{"name":"@crabas0npm/ut-cumque-iure","version":"1.0.0","description":"<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\"/>","main":"index.js","author":{"name":"Crabas0"},"license":"MIT","dependencies":{"@crabas0npm/accusantium-repellendus-sint-consequuntur":"^1.0.0","@crabas0npm/alias-consequuntur-hic-enim":"^1.0.0","@crabas0npm/aliquid-vitae-magnam-perspiciatis":"^1.0.0","@crabas0npm/aut-cupiditate-quam-dicta":"^1.0.0","@crabas0npm/blanditiis-est-molestias-a":"^1.0.0","@crabas0npm/consectetur-impedit-exercitationem-error":"^1.0.0","@crabas0npm/corporis-rerum-reprehenderit-voluptates":"^1.0.0","@crabas0npm/delectus-dolorem-consectetur-corrupti":"^1.0.0","@crabas0npm/ea-nisi-earum-mollitia":"^1.0.0","@crabas0npm/et-perspiciatis-eius-modi":"^1.0.0","@crabas0npm/expedita-magnam-quia-perferendis":"^1.0.0","@crabas0npm/expedita-optio-recusandae-nesciunt":"^1.0.0","@crabas0npm/expedita-voluptas-corrupti-ullam":"^1.0.0","@crabas0npm/facilis-doloribus-provident-optio":"^1.0.0","@crabas0npm/fugiat-necessitatibus-recusandae-quo":"^1.0.0","@crabas0npm/maxime-sequi-nam-facere":"^1.0.0","@crabas0npm/minus-iure-ipsum-temporibus":"^1.0.0","@crabas0npm/nulla-minima-vero-facere":"^1.0.0","@crabas0npm/odio-exercitationem-ducimus-provident":"^1.0.0","@crabas0npm/officia-nostrum-at-hic":"^1.0.0","@crabas0npm/officiis-labore-tempora-sint":"^1.0.0","@crabas0npm/omnis-neque-asperiores-rerum":"^1.0.0","@crabas0npm/optio-sequi-optio-quidem":"^1.0.0","@crabas0npm/porro-voluptatem-consectetur-beatae":"^1.0.0","@crabas0npm/possimus-sit-repellat-perspiciatis":"^1.0.0","@crabas0npm/quo-dolorem-molestiae-porro":"^1.0.0","@crabas0npm/ratione-nisi-deleniti-provident":"^1.0.0","@crabas0npm/ratione-voluptatibus-quo-sed":"^1.0.0","@crabas0npm/repellendus-illum-cum-fugit":"^1.0.0","@crabas0npm/unde-quos-asperiores-modi":"^1.0.0","@diahkomalasarinpm/praesentium-sint-dolorem":"^1.0.0","@f1stnpm2/adipisci-adipisci-praesentium":"^1.0.0","@wemnyelezxnpm/delectus-repellendus-neque":"^1.0.0","give-advice-10th":"^1.0.3"},"keywords":["drag","mime","push","description","RFC-6455","linux","es2017","electron","uninstall"],"repository":{"type":"git","url":"git+https://github.com/crabas0npm/ut-cumque-iure.git"},"homepage":"https://github.com/crabas0npm/ut-cumque-iure/#readme","bugs":{"url":"https://github.com/crabas0npm/ut-cumque-iure/issues"},"packageManager":"yarn@4.1.1","_id":"@crabas0npm/ut-cumque-iure@1.0.0","gitHead":"8818b31eaa34d381708e38e3ac31d6d39ce7e46d","_nodeVersion":"20.12.2","_npmVersion":"10.5.0","dist":{"integrity":"sha512-wq6iS3AeMPz5xHjEFkVGNOItW38WVJh+8KF2FrRu2upJ0ReENRNStF6hDJFR94i4vlc6kM5X9eExEGJ2dEQMpA==","shasum":"f9e57d6e8f8331abd50b9110b64a703125609c22","tarball":"https://registry.npmjs.org/@crabas0npm/ut-cumque-iure/-/ut-cumque-iure-1.0.0.tgz","fileCount":10,"unpackedSize":20917,"signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEQCIFHKw3L+2jdh3WUld421dRG1hSpbn2S+vxCRERz3Df6cAiAYjYW4vYLYZkoaJN61B+J15P4yOpmAe3w2XbEChjdXMQ=="}]},"_npmUser":{"name":"thanhl4861","email":"thanhl4861@gmail.com"},"directories":{},"maintainers":[{"name":"thanhl4861","email":"thanhl4861@gmail.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/ut-cumque-iure_1.0.0_1714304880473_0.30565218686733187"},"_hasShrinkwrap":false}},"time":{"created":"2024-04-28T11:48:00.384Z","1.0.0":"2024-04-28T11:48:00.627Z","modified":"2024-04-28T11:48:00.945Z"},"maintainers":[{"name":"thanhl4861","email":"thanhl4861@gmail.com"}],"description":"<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\"/>","homepage":"https://github.com/crabas0npm/ut-cumque-iure/#readme","keywords":["drag","mime","push","description","RFC-6455","linux","es2017","electron","uninstall"],"repository":{"type":"git","url":"git+https://github.com/crabas0npm/ut-cumque-iure.git"},"author":{"name":"Crabas0"},"bugs":{"url":"https://github.com/crabas0npm/ut-cumque-iure/issues"},"license":"MIT","readme":"# @crabas0npm/ut-cumque-iure\n\n<img src=\"https://img.shields.io/badge/build-passing-brightgreen.svg\"/>\n<img src=\"https://img.shields.io/badge/coverage-100%25-brightgreen.svg\"/>\n<img src=\"https://img.shields.io/badge/license-MIT-blue.svg\"/>\n\nA [blazing fast](#benchmarks) deep object copier\n\n## Table of contents\n\n- [@crabas0npm/ut-cumque-iure](#@crabas0npm/ut-cumque-iure)\n  - [Table of contents](#table-of-contents)\n  - [Usage](#usage)\n  - [API](#api)\n    - [`copy`](#copy)\n    - [`copyStrict`](#copystrict)\n    - [`createCopier`](#createcopier)\n      - [Copier methods](#copier-methods)\n      - [Copier state](#copier-state)\n        - [`cache`](#cache)\n        - [`copier`](#copier)\n        - [`Constructor` / `prototype`](#constructor--prototype)\n    - [`createStrictCopier`](#createstrictcopier)\n  - [Types supported](#types-supported)\n  - [Aspects of default copiers](#aspects-of-default-copiers)\n    - [Error references are copied directly, instead of creating a new `*Error` object](#error-references-are-copied-directly-instead-of-creating-a-new-error-object)\n    - [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)\n    - [Generator objects are copied, but still reference the original generator's state](#generator-objects-are-copied-but-still-reference-the-original-generators-state)\n  - [Benchmarks](#benchmarks)\n      - [Simple objects](#simple-objects)\n      - [Complex objects](#complex-objects)\n      - [Big data](#big-data)\n      - [Circular objects](#circular-objects)\n      - [Special objects](#special-objects)\n  - [Development](#development)\n\n## Usage\n\n```js\nimport copy from '@crabas0npm/ut-cumque-iure';\nimport { deepEqual } from 'fast-equals';\n\nconst object = {\n  array: [123, { deep: 'value' }],\n  map: new Map([\n    ['foo', {}],\n    [{ bar: 'baz' }, 'quz'],\n  ]),\n};\n\nconst copiedObject = copy(object);\n\nconsole.log(copiedObject === object); // false\nconsole.log(deepEqual(copiedObject, object)); // true\n```\n\n## API\n\n### `copy`\n\nDeeply copy the object passed.\n\n```js\nimport copy from '@crabas0npm/ut-cumque-iure';\n\nconst copied = copy({ foo: 'bar' });\n```\n\n### `copyStrict`\n\nDeeply copy the object passed, but with additional strictness when replicating the original object:\n\n- Properties retain their original property descriptor\n- Non-enumerable keys are copied\n- Non-standard properties (e.g., keys on arrays / maps / sets) are copied\n\n```js\nimport { copyStrict } from '@crabas0npm/ut-cumque-iure';\n\nconst object = { foo: 'bar' };\nobject.nonEnumerable = Object.defineProperty(object, 'bar', {\n  enumerable: false,\n  value: 'baz',\n});\n\nconst copied = copy(object);\n```\n\n**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.\n\n### `createCopier`\n\nCreate 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.\n\n```js\nimport { createCopier } from '@crabas0npm/ut-cumque-iure';\n\nconst copyShallow = createCopier({\n  array: (array) => [...array],\n  map: (map) => new Map(map.entries()),\n  object: (object) => ({ ...object }),\n  set: (set) => new Set(set.values()),\n});\n```\n\nEach internal copier method has the following contract:\n\n```js\ntype InternalCopier<Value> = (value: Value, state: State) => Value;\n\ninterface State {\n  Constructor: any;\n  cache: WeakMap;\n  copier: InternalCopier<any>;\n  prototype: any;\n}\n```\n\nAny method overriding the defaults must maintain this contract.\n\n#### Copier methods\n\n- `array` => `Array`\n- `arrayBuffer`=> `ArrayBuffer`, `Float32Array`, `Float64Array`, `Int8Array`, `Int16Array`, `Int32Array`, `Uint8Array`, `Uint8ClampedArray`, `Uint16Array`, `Uint32Array`, `Uint64Array`\n- `blob` => `Blob`\n- `dataView` => `DataView`\n- `date` => `Date`\n- `error` => `Error`, `AggregateError`, `EvalError`, `RangeError`, `ReferenceError`, `SyntaxError`, `TypeError`, `URIError`\n- `map` => `Map`\n- `object` => `Object`, or any custom constructor\n- `regExp` => `RegExp`\n- `set` => `Set`\n\n#### Copier state\n\n##### `cache`\n\nIf you want to maintain circular reference handling, then you'll need the methods to handle cache population for future lookups:\n\n```js\nfunction shallowlyCloneArray<Value extends any[]>(\n  value: Value,\n  state: State\n): Value {\n  const clone = [...value];\n\n  state.cache.set(value, clone);\n\n  return clone;\n}\n```\n\n##### `copier`\n\n`copier` is provided for recursive calls with deeply-nested objects.\n\n```js\nfunction deeplyCloneArray<Value extends any[]>(\n  value: Value,\n  state: State\n): Value {\n  const clone = [];\n\n  state.cache.set(value, clone);\n\n  value.forEach((item) => state.copier(item, state));\n\n  return clone;\n}\n```\n\nNote 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.\n\n##### `Constructor` / `prototype`\n\nBoth `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.\n\n```js\nfunction deeplyCloneSubclassArray<Value extends CustomArray>(\n  value: Value,\n  state: State\n): Value {\n  const clone = new state.Constructor();\n\n  state.cache.set(value, clone);\n\n  value.forEach((item) => clone.push(item));\n\n  return clone;\n}\n\nfunction deeplyCloneCustomObject<Value extends CustomObject>(\n  value: Value,\n  state: State\n): Value {\n  const clone = Object.create(state.prototype);\n\n  state.cache.set(value, clone);\n\n  Object.entries(value).forEach(([k, v]) => (clone[k] = v));\n\n  return clone;\n}\n```\n\n### `createStrictCopier`\n\nCreate 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.\n\n```js\nconst createStrictClone = (value, clone) =>\n  Object.getOwnPropertyNames(value).reduce(\n    (clone, property) =>\n      Object.defineProperty(\n        clone,\n        property,\n        Object.getOwnPropertyDescriptor(value, property) || {\n          configurable: true,\n          enumerable: true,\n          value: clone[property],\n          writable: true,\n        }\n      ),\n    clone\n  );\n\nconst copyStrictShallow = createStrictCopier({\n  array: (array) => createStrictClone(array, []),\n  map: (map) => createStrictClone(map, new Map(map.entries())),\n  object: (object) => createStrictClone(object, {}),\n  set: (set) => createStrictClone(set, new Set(set.values())),\n});\n```\n\n**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.\n\n## Types supported\n\nThe following object types are deeply cloned when they are either properties on the object passed, or the object itself:\n\n- `Array`\n- `ArrayBuffer`\n- `Boolean` primitive wrappers (e.g., `new Boolean(true)`)\n- `Blob`\n- `Buffer`\n- `DataView`\n- `Date`\n- `Float32Array`\n- `Float64Array`\n- `Int8Array`\n- `Int16Array`\n- `Int32Array`\n- `Map`\n- `Number` primitive wrappers (e.g., `new Number(123)`)\n- `Object`\n- `RegExp`\n- `Set`\n- `String` primitive wrappers (e.g., `new String('foo')`)\n- `Uint8Array`\n- `Uint8ClampedArray`\n- `Uint16Array`\n- `Uint32Array`\n- `React` components\n- Custom constructors\n\nThe following object types are copied directly, as they are either primitives, cannot be cloned, or the common use-case implementation does not expect cloning:\n\n- `AsyncFunction`\n- `Boolean` primitives\n- `Error`\n- `Function`\n- `GeneratorFunction`\n- `Number` primitives\n- `Null`\n- `Promise`\n- `String` primitives\n- `Symbol`\n- `Undefined`\n- `WeakMap`\n- `WeakSet`\n\nCircular 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`.\n\n## Aspects of default copiers\n\nInherently, 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).\n\n### Error references are copied directly, instead of creating a new `*Error` object\n\nWhile 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.\n\n### The constructor of the original object is used, instead of using known globals\n\nStarting 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.\n\n### Generator objects are copied, but still reference the original generator's state\n\n[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.\n\n## Benchmarks\n\n#### Simple objects\n\n_Small number of properties, all values are primitives_\n\n|                    | Operations / second |\n| ------------------ | ------------------- |\n| **@crabas0npm/ut-cumque-iure**      | **5,880,312**       |\n| lodash.cloneDeep   | 2,706,261           |\n| clone              | 2,207,231           |\n| deepclone          | 1,274,810           |\n| fast-clone         | 1,239,952           |\n| ramda              | 1,146,152           |\n| @crabas0npm/ut-cumque-iure (strict) | 852,382             |\n\n#### Complex objects\n\n_Large number of properties, values are a combination of primitives and complex objects_\n\n|                    | Operations / second |\n| ------------------ | ------------------- |\n| **@crabas0npm/ut-cumque-iure**      | **162,858**         |\n| ramda              | 142,104             |\n| deepclone          | 133,607             |\n| fast-clone         | 101,143             |\n| clone              | 70,872              |\n| @crabas0npm/ut-cumque-iure (strict) | 62,961              |\n| lodash.cloneDeep   | 62,060              |\n\n#### Big data\n\n_Very large number of properties with high amount of nesting, mainly objects and arrays_\n\n|                    | Operations / second |\n| ------------------ | ------------------- |\n| **@crabas0npm/ut-cumque-iure**      | **303**             |\n| fast-clone         | 245                 |\n| deepclone          | 151                 |\n| lodash.cloneDeep   | 150                 |\n| clone              | 93                  |\n| @crabas0npm/ut-cumque-iure (strict) | 90                  |\n| ramda              | 42                  |\n\n#### Circular objects\n\n_Objects that deeply reference themselves_\n\n|                    | Operations / second |\n| ------------------ | ------------------- |\n| **@crabas0npm/ut-cumque-iure**      | **2,420,466**       |\n| deepclone          | 1,386,896           |\n| ramda              | 1,024,108           |\n| lodash.cloneDeep   | 989,796             |\n| clone              | 987,721             |\n| @crabas0npm/ut-cumque-iure (strict) | 617,602             |\n| fast-clone         | 0 (not supported)   |\n\n#### Special objects\n\n_Custom constructors, React components, etc_\n\n|                    | Operations / second |\n| ------------------ | ------------------- |\n| **@crabas0npm/ut-cumque-iure**      | **152,792**         |\n| clone              | 74,347              |\n| fast-clone         | 66,576              |\n| lodash.cloneDeep   | 64,760              |\n| ramda              | 53,542              |\n| deepclone          | 28,823              |\n| @crabas0npm/ut-cumque-iure (strict) | 21,362              |\n\n## Development\n\nStandard practice, clone the repo and `yarn` (or `npm i`) to get the dependencies. The following npm scripts are available:\n\n- benchmark => run benchmark tests against other equality libraries\n- build => run `build:esm`, `build:cjs`, `build:umd`, and `build:min` scripts\n- build:cjs => build CJS files and types\n- build:esm => build ESM files and types\n- build:min => build minified files and types\n- build:umd => build UMD files and types\n- clean => run `rimraf` on the `dist` folder\n- dev => start webpack playground App\n- dist => run `clean` and `build` scripts\n- lint => run ESLint on all files in `src` folder (also runs on `dev` script)\n- lint:fix => run `lint` script, but with auto-fixer\n- prepublishOnly => run `lint`, `test:coverage`, and `dist` scripts\n- release => run `prepublishOnly` and release with new version\n- release:beta => run `prepublishOnly` and release with new beta version\n- release:dry => run `prepublishOnly` and simulate a new release\n- start => run `dev`\n- test => run AVA with NODE_ENV=test on all files in `test` folder\n- test:coverage => run same script as `test` with code coverage calculation via `nyc`\n- test:watch => run same script as `test` but keep persistent watcher\n- typecheck => run `tsc` on the codebase\n","readmeFilename":"README.md"}