Skip to content

Commit 3b116d9

Browse files
committed
add release-t config files
1 parent e34065f commit 3b116d9

File tree

7 files changed

+67
-54
lines changed

7 files changed

+67
-54
lines changed

.release-it.beta.json

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
{
2+
"github": {
3+
"release": true
4+
},
5+
"npm": {
6+
"tag": "next"
7+
},
8+
"preReleaseId": "beta"
9+
}

.release-it.json

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
{
2+
"github": {
3+
"release": true,
4+
"tagName": "v${version}"
5+
}
6+
}

README.md

Lines changed: 18 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -8,17 +8,20 @@ A [blazing fast](#benchmarks) deep object copier
88

99
## Table of contents
1010

11-
- [Usage](#usage)
12-
- [Options](#options)
13-
- [isStrict](#isstrict)
14-
- [realm](#realm)
15-
- [Types supported](#types-supported)
16-
- [Benchmarks](#benchmarks)
17-
- [Simple objects](#simple-objects)
18-
- [Complex objects](#complex-objects)
19-
- [Circular objects](#circular-objects)
20-
- [Special objects](#special-objects)
21-
- [Development](#development)
11+
- [fast-copy](#fast-copy)
12+
- [Table of contents](#table-of-contents)
13+
- [Usage](#usage)
14+
- [Options](#options)
15+
- [isStrict](#isstrict)
16+
- [realm](#realm)
17+
- [Types supported](#types-supported)
18+
- [Benchmarks](#benchmarks)
19+
- [Simple objects](#simple-objects)
20+
- [Complex objects](#complex-objects)
21+
- [Big data](#big-data)
22+
- [Circular objects](#circular-objects)
23+
- [Special objects](#special-objects)
24+
- [Development](#development)
2225

2326
## Usage
2427

@@ -205,7 +208,10 @@ Standard practice, clone the repo and `npm i` to get the dependencies. The follo
205208
- dist => run `build` and `build:minified` scripts
206209
- lint => run ESLint on all files in `src` folder (also runs on `dev` script)
207210
- lint:fix => run `lint` script, but with auto-fixer
208-
- prepublish:compile => run `lint`, `test:coverage`, and `dist` scripts
211+
- prepublishOnly => run `lint`, `test:coverage`, and `dist` scripts
212+
- release => run `prepublishOnly` and release with new version
213+
- release:beta => run `prepublishOnly` and release with new beta version
214+
- release:dry => run `prepublishOnly` and simulate a new release
209215
- start => run `dev`
210216
- test => run AVA with NODE_ENV=test on all files in `test` folder
211217
- test:coverage => run same script as `test` with code coverage calculation via `nyc`

index.d.ts

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,4 @@
11
declare namespace FastCopy {
2-
export interface Constructor extends Function {
3-
new (...args: any[]): any;
4-
}
5-
62
// @ts-ignore
73
export type Realm = Window | Global;
84

@@ -12,25 +8,29 @@ declare namespace FastCopy {
128
has: (value: any) => boolean;
139
}
1410

15-
export type Copier = (object: any, cache: Cache) => any;
16-
17-
export type ObjectCloner = (
18-
object: any,
19-
realm: Realm,
20-
handleCopy: Copier,
11+
export type Copier = <ObjectType extends any = any>(
12+
object: ObjectType,
2113
cache: Cache,
22-
) => any;
14+
) => ObjectType;
15+
16+
export type ObjectCloner = (object: any, realm: Realm, handleCopy: Copier, cache: Cache) => any;
2317

2418
export type Options = {
2519
isStrict?: boolean;
2620
realm?: Realm;
2721
};
2822
}
2923

30-
declare function copy<T>(object: T, options?: FastCopy.Options): T;
24+
declare function copy<ObjectType extends any = any>(
25+
object: ObjectType,
26+
options?: FastCopy.Options,
27+
): ObjectType;
3128

3229
declare namespace copy {
33-
function strictCopy<T>(object: T, options?: FastCopy.Options): T;
30+
function strictCopy<ObjectType extends any = any>(
31+
object: ObjectType,
32+
options?: FastCopy.Options,
33+
): ObjectType;
3434
}
3535

3636
export default copy;

package.json

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,10 @@
6363
"lint": "NODE_ENV=test tslint 'src/*.ts'",
6464
"lint:fix": "npm run lint -- --fix",
6565
"prepublish": "if in-publish; then npm run prepublish:compile; fi",
66-
"prepublish:compile": "npm run lint && npm run test:coverage && npm run dist",
66+
"prepublishOnly": "npm run lint && npm run test:coverage && npm run dist",
67+
"release": "release-it",
68+
"release:beta": "release-it --config=.release-it.beta.json",
69+
"release:dry": "release-it --dry-run",
6770
"start": "npm run dev",
6871
"test": "NODE_PATH=. jest",
6972
"test:coverage": "npm run test -- --coverage",

src/fast-copy.d.ts

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,4 @@
11
declare namespace FastCopy {
2-
export interface Constructor extends Function {
3-
new (...args: any[]): any;
4-
}
5-
62
// @ts-ignore
73
export type Realm = Window | Global;
84

@@ -12,23 +8,27 @@ declare namespace FastCopy {
128
has: (value: any) => boolean;
139
}
1410

15-
export type Copier = (object: any, cache: Cache) => any;
16-
17-
export type ObjectCloner = (
18-
object: any,
19-
realm: Realm,
20-
handleCopy: Copier,
11+
export type Copier = <ObjectType extends any = any>(
12+
object: ObjectType,
2113
cache: Cache,
22-
) => any;
14+
) => ObjectType;
15+
16+
export type ObjectCloner = (object: any, realm: Realm, handleCopy: Copier, cache: Cache) => any;
2317

2418
export type Options = {
2519
isStrict?: boolean;
2620
realm?: Realm;
2721
};
2822
}
2923

30-
declare function copy<T>(object: T, options?: FastCopy.Options): T;
24+
declare function copy<ObjectType extends any = any>(
25+
object: ObjectType,
26+
options?: FastCopy.Options,
27+
): ObjectType;
3128

3229
declare namespace copy {
33-
function strictCopy<T>(object: T, options?: FastCopy.Options): T;
30+
function strictCopy<ObjectType extends any = any>(
31+
object: ObjectType,
32+
options?: FastCopy.Options,
33+
): ObjectType;
3434
}

src/index.ts

Lines changed: 4 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,5 @@
11
// utils
2-
import {
3-
createCache,
4-
getObjectCloneLoose,
5-
getObjectCloneStrict,
6-
getRegExpFlags,
7-
} from './utils';
2+
import { createCache, getObjectCloneLoose, getObjectCloneStrict, getRegExpFlags } from './utils';
83

94
const { isArray } = Array;
105

@@ -63,15 +58,12 @@ function copy<T>(object: T, options?: FastCopy.Options): T {
6358
* @param object the object to copy
6459
* @returns the copied object
6560
*/
66-
const handleCopy: FastCopy.Copier = (
67-
object: any,
68-
cache: FastCopy.Cache,
69-
): any => {
61+
const handleCopy: FastCopy.Copier = (object: any, cache: FastCopy.Cache): any => {
7062
if (!object || typeof object !== 'object' || cache.has(object)) {
7163
return object;
7264
}
7365

74-
const Constructor: FastCopy.Constructor = object.constructor;
66+
const { constructor: Constructor } = object;
7567

7668
// plain objects
7769
if (Constructor === realm.Object) {
@@ -108,10 +100,7 @@ function copy<T>(object: T, options?: FastCopy.Options): T {
108100

109101
// regexps
110102
if (object instanceof realm.RegExp) {
111-
clone = new Constructor(
112-
object.source,
113-
object.flags || getRegExpFlags(object),
114-
);
103+
clone = new Constructor(object.source, object.flags || getRegExpFlags(object));
115104

116105
clone.lastIndex = object.lastIndex;
117106

0 commit comments

Comments
 (0)