Socket
Socket
Sign inDemoInstall

fast-copy

Package Overview
Dependencies
0
Maintainers
1
Versions
36
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 3.0.0-beta.8 to 3.0.0

1

CHANGELOG.md

@@ -12,2 +12,3 @@ # fast-copy CHANGELOG

- `realm` has been removed entirely, as `instanceof` is no longer used internally
- The `FastCopy` namespace in typings has been removed in favor of explicit import of available types

@@ -14,0 +15,0 @@ **Enhancements**

10

package.json

@@ -15,5 +15,5 @@ {

"@types/eslint": "^8.4.6",
"@types/jest": "^29.1.0",
"@types/jest": "^29.1.1",
"@types/lodash": "^4.14.186",
"@types/node": "^18.7.23",
"@types/node": "^18.8.0",
"@types/ramda": "^0.28.15",

@@ -32,3 +32,3 @@ "@types/react": "^18.0.21",

"in-publish": "^2.0.1",
"jest": "^29.1.1",
"jest": "^29.1.2",
"lodash": "^4.17.11",

@@ -39,3 +39,3 @@ "nyc": "^15.1.0",

"react-dom": "^18.2.0",
"release-it": "15.4.1",
"release-it": "15.4.3",
"rollup": "^2.79.1",

@@ -105,3 +105,3 @@ "rollup-plugin-terser": "^7.0.2",

"types": "index.d.ts",
"version": "3.0.0-beta.8"
"version": "3.0.0"
}

@@ -25,5 +25,6 @@ # fast-copy

- [Types supported](#types-supported)
- [Aspects of copying](#aspects-of-copying)
- [Error references are copied over (instead of creating a new `*Error` object)](#error-references-are-copied-over-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)
- [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)

@@ -39,4 +40,4 @@ - [Simple objects](#simple-objects)

```javascript
import { copy } from 'fast-copy';
```js
import copy from 'fast-copy';
import { deepEqual } from 'fast-equals';

@@ -64,3 +65,3 @@

```ts
```js
import copy from 'fast-copy';

@@ -77,5 +78,5 @@

- Non-enumerable keys are copied
- Non-standard properties (e.g., keys on an `Array` object) are copied
- Non-standard properties (e.g., keys on arrays / maps / sets) are copied
```ts
```js
import { copyStrict } from 'fast-copy';

@@ -98,3 +99,3 @@

```ts
```js
import { createCopier } from 'fast-copy';

@@ -112,3 +113,3 @@

```ts
```js
type InternalCopier<Value> = (value: Value, state: State) => Value;

@@ -132,3 +133,3 @@

```ts
```js
function shallowlyCloneArray<Value extends any[]>(

@@ -150,3 +151,3 @@ value: Value,

```ts
```js
function deeplyCloneArray<Value extends any[]>(

@@ -172,3 +173,3 @@ value: Value,

```ts
```js
function deeplyCloneSubclassArray<Value extends CustomArray>(

@@ -205,3 +206,3 @@ value: Value,

```ts
```js
const createStrictClone = (value, clone) =>

@@ -235,12 +236,12 @@ Object.getOwnPropertyNames(value).reduce(

- `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
- `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`

@@ -253,2 +254,3 @@ ## Types supported

- `ArrayBuffer`
- `Boolean` primitive wrappers (e.g., `new Boolean(true)`)
- `Blob`

@@ -264,5 +266,7 @@ - `Buffer`

- `Map`
- `Number` primitive wrappers (e.g., `new Number(123)`)
- `Object`
- `RegExp`
- `Set`
- `String` primitive wrappers (e.g., `new String('foo')`)
- `Uint8Array`

@@ -278,10 +282,10 @@ - `Uint8ClampedArray`

- `AsyncFunction`
- `Boolean`
- `Boolean` primitives
- `Error`
- `Function`
- `GeneratorFunction`
- `Number`
- `Number` primitives
- `Null`
- `Promise`
- `String`
- `String` primitives
- `Symbol`

@@ -294,14 +298,18 @@ - `Undefined`

## Aspects of copying
## 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.
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 over (instead of creating a new `*Error` object)
### 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.
### 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, however because there is the possibility of inaccuracy if the contract differs, it should be noted.
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

@@ -308,0 +316,0 @@

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc