Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update dependencies 20191102 #23

Merged
merged 5 commits into from
Nov 2, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions .release-it.beta.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"github": {
"release": true
},
"npm": {
"tag": "next"
},
"preReleaseId": "beta"
}
6 changes: 6 additions & 0 deletions .release-it.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"github": {
"release": true,
"tagName": "v${version}"
}
}
30 changes: 18 additions & 12 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,17 +8,20 @@ A [blazing fast](#benchmarks) deep object copier

## Table of contents

- [Usage](#usage)
- [Options](#options)
- [isStrict](#isstrict)
- [realm](#realm)
- [Types supported](#types-supported)
- [Benchmarks](#benchmarks)
- [Simple objects](#simple-objects)
- [Complex objects](#complex-objects)
- [Circular objects](#circular-objects)
- [Special objects](#special-objects)
- [Development](#development)
- [fast-copy](#fast-copy)
- [Table of contents](#table-of-contents)
- [Usage](#usage)
- [Options](#options)
- [isStrict](#isstrict)
- [realm](#realm)
- [Types supported](#types-supported)
- [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

Expand Down Expand Up @@ -205,7 +208,10 @@ Standard practice, clone the repo and `npm i` to get the dependencies. The follo
- dist => run `build` and `build:minified` scripts
- lint => run ESLint on all files in `src` folder (also runs on `dev` script)
- lint:fix => run `lint` script, but with auto-fixer
- prepublish:compile => run `lint`, `test:coverage`, and `dist` scripts
- 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`
Expand Down
21 changes: 9 additions & 12 deletions index.d.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,4 @@
declare namespace FastCopy {
export interface Constructor extends Function {
new (...args: any[]): any;
}

// @ts-ignore
export type Realm = Window | Global;

Expand All @@ -14,23 +10,24 @@ declare namespace FastCopy {

export type Copier = (object: any, cache: Cache) => any;

export type ObjectCloner = (
object: any,
realm: Realm,
handleCopy: Copier,
cache: Cache,
) => any;
export type ObjectCloner = (object: any, realm: Realm, handleCopy: Copier, cache: Cache) => any;

export type Options = {
isStrict?: boolean;
realm?: Realm;
};
}

declare function copy<T>(object: T, options?: FastCopy.Options): T;
declare function copy<ObjectType extends any = any>(
object: ObjectType,
options?: FastCopy.Options,
): ObjectType;

declare namespace copy {
function strictCopy<T>(object: T, options?: FastCopy.Options): T;
function strictCopy<ObjectType extends any = any>(
object: ObjectType,
options?: FastCopy.Options,
): ObjectType;
}

export default copy;
47 changes: 25 additions & 22 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@
},
"description": "A blazing fast deep object copier",
"devDependencies": {
"@types/jest": "^24.0.4",
"@types/lodash": "^4.14.121",
"@types/node": "^11.9.3",
"@types/ramda": "^0.25.50",
"@types/react": "^16.8.3",
"@types/jest": "^24.0.21",
"@types/lodash": "^4.14.144",
"@types/node": "^12.12.5",
"@types/ramda": "^0.26.33",
"@types/react": "^16.9.11",
"benchee": "^1.0.3",
"cli-table2": "^0.2.0",
"clone": "^2.1.2",
Expand All @@ -19,25 +19,25 @@
"fast-deepclone": "^1.0.1",
"html-webpack-plugin": "^3.2.0",
"in-publish": "^2.0.0",
"jest": "^24.1.0",
"jest": "^24.9.0",
"lodash": "^4.17.11",
"nyc": "^13.2.0",
"nyc": "^14.1.1",
"ramda": "^0.26.1",
"react": "^16.8.1",
"react-dom": "^16.8.1",
"rollup": "^1.1.0",
"rollup-plugin-node-resolve": "^4.0.0",
"rollup-plugin-terser": "^4.0.4",
"rollup-plugin-typescript2": "^0.19.2",
"ts-jest": "^23.10.4",
"ts-loader": "^5.3.3",
"tslint": "^5.11.0",
"tslint-config-airbnb": "^5.11.0",
"react": "^16.11.0",
"react-dom": "^16.11.0",
"rollup": "^1.26.3",
"rollup-plugin-node-resolve": "^5.2.0",
"rollup-plugin-terser": "^5.1.2",
"rollup-plugin-typescript2": "^0.24.3",
"ts-jest": "^24.1.0",
"ts-loader": "^6.2.1",
"tslint": "^5.20.0",
"tslint-config-airbnb": "^5.11.2",
"tslint-loader": "^3.5.4",
"typescript": "^3.3.3",
"webpack": "^4.29.3",
"webpack-cli": "^3.2.3",
"webpack-dev-server": "^3.1.5"
"typescript": "^3.6.4",
"webpack": "^4.41.2",
"webpack-cli": "^3.3.10",
"webpack-dev-server": "^3.9.0"
},
"homepage": "https://github.com/planttheidea/fast-copy#readme",
"keywords": [
Expand All @@ -63,7 +63,10 @@
"lint": "NODE_ENV=test tslint 'src/*.ts'",
"lint:fix": "npm run lint -- --fix",
"prepublish": "if in-publish; then npm run prepublish:compile; fi",
"prepublish:compile": "npm run lint && npm run test:coverage && npm run dist",
"prepublishOnly": "npm run lint && npm run test:coverage && npm run dist",
"release": "release-it",
"release:beta": "release-it --config=.release-it.beta.json",
"release:dry": "release-it --dry-run",
"start": "npm run dev",
"test": "NODE_PATH=. jest",
"test:coverage": "npm run test -- --coverage",
Expand Down
40 changes: 19 additions & 21 deletions rollup.config.js
Original file line number Diff line number Diff line change
@@ -1,38 +1,36 @@
import resolve from "rollup-plugin-node-resolve";
import { terser } from "rollup-plugin-terser";
import typescript from "rollup-plugin-typescript2";
import resolve from 'rollup-plugin-node-resolve';
import { terser } from 'rollup-plugin-terser';
import typescript from 'rollup-plugin-typescript2';

import pkg from "./package.json";
import pkg from './package.json';

const EXTERNALS = [
...Object.keys(pkg.dependencies || {}),
...Object.keys(pkg.peerDependencies || {})
...Object.keys(pkg.peerDependencies || {}),
];

const UMD_CONFIG = {
external: EXTERNALS,
input: "src/index.ts",
input: 'src/index.ts',
output: {
file: pkg.browser,
format: "umd",
format: 'umd',
globals: EXTERNALS.reduce((globals, name) => {
globals[name] = name;

return globals;
}, {}),
name: pkg.name,
sourcemap: true
sourcemap: true,
},
plugins: [
resolve({
browser: true,
main: true,
module: true
mainFields: ['module', 'browser', 'main'],
}),
typescript({
typescript: require("typescript")
})
]
typescript: require('typescript'),
}),
],
};

const FORMATTED_CONFIG = {
Expand All @@ -41,24 +39,24 @@ const FORMATTED_CONFIG = {
{
...UMD_CONFIG.output,
file: pkg.main,
format: "cjs"
format: 'cjs',
},
{
...UMD_CONFIG.output,
file: pkg.module,
format: "es"
}
]
format: 'es',
},
],
};

const MINIFIED_CONFIG = {
...UMD_CONFIG,
output: {
...UMD_CONFIG.output,
file: pkg.browser.replace(".js", ".min.js"),
sourcemap: false
file: pkg.browser.replace('.js', '.min.js'),
sourcemap: false,
},
plugins: [...UMD_CONFIG.plugins, terser()]
plugins: [...UMD_CONFIG.plugins, terser()],
};

export default [UMD_CONFIG, FORMATTED_CONFIG, MINIFIED_CONFIG];
21 changes: 9 additions & 12 deletions src/fast-copy.d.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,4 @@
declare namespace FastCopy {
export interface Constructor extends Function {
new (...args: any[]): any;
}

// @ts-ignore
export type Realm = Window | Global;

Expand All @@ -14,21 +10,22 @@ declare namespace FastCopy {

export type Copier = (object: any, cache: Cache) => any;

export type ObjectCloner = (
object: any,
realm: Realm,
handleCopy: Copier,
cache: Cache,
) => any;
export type ObjectCloner = (object: any, realm: Realm, handleCopy: Copier, cache: Cache) => any;

export type Options = {
isStrict?: boolean;
realm?: Realm;
};
}

declare function copy<T>(object: T, options?: FastCopy.Options): T;
declare function copy<ObjectType extends any = any>(
object: ObjectType,
options?: FastCopy.Options,
): ObjectType;

declare namespace copy {
function strictCopy<T>(object: T, options?: FastCopy.Options): T;
function strictCopy<ObjectType extends any = any>(
object: ObjectType,
options?: FastCopy.Options,
): ObjectType;
}
25 changes: 8 additions & 17 deletions src/index.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,5 @@
// utils
import {
createCache,
getObjectCloneLoose,
getObjectCloneStrict,
getRegExpFlags,
} from './utils';
import { createCache, getObjectCloneLoose, getObjectCloneStrict, getRegExpFlags } from './utils';

const { isArray } = Array;

Expand Down Expand Up @@ -63,15 +58,12 @@ function copy<T>(object: T, options?: FastCopy.Options): T {
* @param object the object to copy
* @returns the copied object
*/
const handleCopy: FastCopy.Copier = (
object: any,
cache: FastCopy.Cache,
): any => {
const handleCopy: FastCopy.Copier = (object: any, cache: FastCopy.Cache): any => {
if (!object || typeof object !== 'object' || cache.has(object)) {
return object;
}

const Constructor: FastCopy.Constructor = object.constructor;
const { constructor: Constructor } = object;

// plain objects
if (Constructor === realm.Object) {
Expand All @@ -83,16 +75,18 @@ function copy<T>(object: T, options?: FastCopy.Options): T {
let clone: any;
// arrays
if (isArray(object)) {
const objectLength = object.length;
cache.add(object);

// if strict, include non-standard properties
if (isStrict) {
return getObjectCloneStrict(object, realm, handleCopy, cache);
}

const { length } = object;

clone = new Constructor();
for (let index: number = 0; index < objectLength; index++) {

for (let index: number = 0; index < length; index++) {
clone[index] = handleCopy(object[index], cache);
}

Expand All @@ -106,10 +100,7 @@ function copy<T>(object: T, options?: FastCopy.Options): T {

// regexps
if (object instanceof realm.RegExp) {
clone = new Constructor(
object.source,
object.flags || getRegExpFlags(object),
);
clone = new Constructor(object.source, object.flags || getRegExpFlags(object));

clone.lastIndex = object.lastIndex;

Expand Down
Loading