Skip to content

Commit 52f5898

Browse files
committed
Removed redundant type, added index.d.ts to package.json, added JSDoc
1 parent 2eea215 commit 52f5898

File tree

5 files changed

+47
-35
lines changed

5 files changed

+47
-35
lines changed

dist/index.d.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export default function testDiff(input1:any|object|Array<any>, input2:any|object|Array<any>, deep:boolean):boolean;

dist/index.js

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,12 @@ function testValue(value1, value2) {
77
return true;
88
return false;
99
}
10-
// Returns true if obj1 differs in any way from obj2.
10+
/**
11+
* Returns true if input1 differs in any way from input2. Performs "deep" object/array traversal by default, comparing all reachable values.
12+
* @param {any} input1 A value/object to compare against input2.
13+
* @param {any} input2 A value/object to compare against input1.
14+
* @param {boolean} [deep=true] Set this operand to false to disable traversal and nested comparisons.
15+
*/
1116
export default function testDiff(obj1, obj2, deep) {
1217
if (deep === void 0) { deep = true; }
1318
if ((obj1 === null) || (obj2 === null) || ((typeof obj1) !== "object") || ((typeof obj2) !== "object"))

package.json

Lines changed: 32 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,34 @@
11
{
2-
"name": "js-testdiff",
3-
"type": "module",
4-
"version": "1.0.2",
5-
"description": "The \"testDiff\" deep diff/test function from Differentia.js, ported to TypeScript. Returns true if input 1 differs in any way from input 2. Performs deep object search by default, works OK with circular references.",
6-
"main": "dist/index.js",
7-
"scripts": {
8-
"test": "npm run build",
9-
"build": "tsc src/index.ts src/lib/unitTest.ts --module es6 --lib es6 --outDir dist/ && node test.mjs"
10-
},
11-
"repository": {
12-
"type": "git",
13-
"url": "git+https://github.com/Floofies/js-testdiff.git"
14-
},
15-
"keywords": [
16-
"test",
17-
"diff",
18-
"object",
19-
"comparison",
20-
"compare",
21-
"deep",
22-
"circular"
23-
],
24-
"author": "Dani Glore",
25-
"license": "MIT",
26-
"bugs": {
27-
"url": "https://github.com/Floofies/js-testdiff/issues"
28-
},
29-
"homepage": "https://github.com/Floofies/js-testdiff#readme",
30-
"devDependencies": {
31-
"@types/node": "^18.15.13"
32-
}
2+
"name": "js-testdiff",
3+
"type": "module",
4+
"version": "1.0.2",
5+
"description": "The \"testDiff\" deep diff/test function from Differentia.js, ported to TypeScript. Returns true if input 1 differs in any way from input 2. Performs deep object search by default, works OK with circular references.",
6+
"main": "dist/index.js",
7+
"types": "./dist/index.d.ts",
8+
"scripts": {
9+
"test": "npm run build",
10+
"build": "tsc src/index.ts src/lib/unitTest.ts --module es6 --lib es6 --outDir dist/ && cp src/index.d.ts dist/ && node test.mjs"
11+
},
12+
"repository": {
13+
"type": "git",
14+
"url": "git+https://github.com/Floofies/js-testdiff.git"
15+
},
16+
"keywords": [
17+
"test",
18+
"diff",
19+
"object",
20+
"comparison",
21+
"compare",
22+
"deep",
23+
"circular"
24+
],
25+
"author": "Dani Glore",
26+
"license": "MIT",
27+
"bugs": {
28+
"url": "https://github.com/Floofies/js-testdiff/issues"
29+
},
30+
"homepage": "https://github.com/Floofies/js-testdiff#readme",
31+
"devDependencies": {
32+
"@types/node": "^18.15.13"
33+
}
3334
}

src/index.d.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export default function testDiff(input1:any|object|Array<any>, input2:any|object|Array<any>, deep:boolean):boolean;

src/index.ts

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
type searchObj = any|object|Array<any>;
22
type objPair = {obj1:searchObj, obj2: searchObj};
3-
type Primitive = symbol|boolean|string|number|null|undefined;
4-
function testValue(value1:Primitive, value2:Primitive):boolean {
3+
function testValue(value1:any, value2:any):boolean {
54
if ((typeof value1) !== (typeof value2))
65
return true;
76
if(Number.isNaN(value1) || Number.isNaN(value2))
@@ -10,7 +9,12 @@ function testValue(value1:Primitive, value2:Primitive):boolean {
109
return true;
1110
return false;
1211
}
13-
// Returns true if obj1 differs in any way from obj2.
12+
/**
13+
* Returns true if input1 differs in any way from input2. Performs "deep" object/array traversal by default, comparing all reachable values.
14+
* @param {any} input1 A value/object to compare against input2.
15+
* @param {any} input2 A value/object to compare against input1.
16+
* @param {boolean} [deep=true] Set this operand to false to disable traversal and nested comparisons.
17+
*/
1418
export default function testDiff(obj1:searchObj, obj2:searchObj, deep:boolean = true):boolean {
1519
if((obj1 === null) || (obj2 === null) || ((typeof obj1) !== "object") || ((typeof obj2) !== "object"))
1620
return testValue(obj1, obj2);

0 commit comments

Comments
 (0)