Skip to content

Commit

Permalink
add release-t config files
Browse files Browse the repository at this point in the history
  • Loading branch information
planttheidea committed Nov 2, 2019
1 parent e34065f commit 3b116d9
Show file tree
Hide file tree
Showing 7 changed files with 67 additions and 54 deletions.
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
26 changes: 13 additions & 13 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 @@ -12,25 +8,29 @@ declare namespace FastCopy {
has: (value: any) => boolean;
}

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

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

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;
5 changes: 4 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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
26 changes: 13 additions & 13 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 @@ -12,23 +8,27 @@ declare namespace FastCopy {
has: (value: any) => boolean;
}

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

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

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;
}
19 changes: 4 additions & 15 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 Down Expand Up @@ -108,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

0 comments on commit 3b116d9

Please sign in to comment.