@fluidframework/core-utils 2.0.0-internal.2.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.eslintrc.js +26 -0
- package/.mocharc.js +13 -0
- package/LICENSE +21 -0
- package/README.md +9 -0
- package/api-extractor.json +4 -0
- package/dist/compare.d.ts +14 -0
- package/dist/compare.d.ts.map +1 -0
- package/dist/compare.js +26 -0
- package/dist/compare.js.map +1 -0
- package/dist/index.d.ts +6 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +10 -0
- package/dist/index.js.map +1 -0
- package/lib/compare.d.ts +14 -0
- package/lib/compare.d.ts.map +1 -0
- package/lib/compare.js +22 -0
- package/lib/compare.js.map +1 -0
- package/lib/index.d.ts +6 -0
- package/lib/index.d.ts.map +1 -0
- package/lib/index.js +6 -0
- package/lib/index.js.map +1 -0
- package/package.json +92 -0
- package/prettier.config.cjs +8 -0
- package/src/compare.ts +31 -0
- package/src/index.ts +6 -0
- package/tsconfig.esnext.json +7 -0
- package/tsconfig.json +10 -0
package/.eslintrc.js
ADDED
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
/*!
|
|
2
|
+
* Copyright (c) Microsoft Corporation and contributors. All rights reserved.
|
|
3
|
+
* Licensed under the MIT License.
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
module.exports = {
|
|
7
|
+
extends: [require.resolve("@fluidframework/eslint-config-fluid/minimal"), "prettier"],
|
|
8
|
+
|
|
9
|
+
parserOptions: {
|
|
10
|
+
project: ["./tsconfig.json", "./src/test/tsconfig.json"],
|
|
11
|
+
},
|
|
12
|
+
rules: {
|
|
13
|
+
// This library is used in the browser, so we don't want dependencies on most node libraries.
|
|
14
|
+
"import/no-nodejs-modules": ["error", { allow: ["events"] }],
|
|
15
|
+
},
|
|
16
|
+
overrides: [
|
|
17
|
+
{
|
|
18
|
+
// Rules only for test files
|
|
19
|
+
files: ["*.spec.ts", "src/test/**"],
|
|
20
|
+
rules: {
|
|
21
|
+
// Test files are run in node only so additional node libraries can be used.
|
|
22
|
+
"import/no-nodejs-modules": ["error", { allow: ["assert", "events"] }],
|
|
23
|
+
},
|
|
24
|
+
},
|
|
25
|
+
],
|
|
26
|
+
};
|
package/.mocharc.js
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
/*!
|
|
2
|
+
* Copyright (c) Microsoft Corporation and contributors. All rights reserved.
|
|
3
|
+
* Licensed under the MIT License.
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
"use strict";
|
|
7
|
+
|
|
8
|
+
const getFluidTestMochaConfig = require("@fluidframework/mocha-test-setup/mocharc-common");
|
|
9
|
+
|
|
10
|
+
const packageDir = __dirname;
|
|
11
|
+
const config = getFluidTestMochaConfig(packageDir, ["source-map-support/register"]);
|
|
12
|
+
config.spec = "dist/test";
|
|
13
|
+
module.exports = config;
|
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
Copyright (c) Microsoft Corporation and contributors. All rights reserved.
|
|
2
|
+
|
|
3
|
+
MIT License
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED *AS IS*, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
# @fluidframework/core-utils
|
|
2
|
+
|
|
3
|
+
Fluid agnostic utility functions with zero-dependencies
|
|
4
|
+
|
|
5
|
+
## Trademark
|
|
6
|
+
|
|
7
|
+
This project may contain Microsoft trademarks or logos for Microsoft projects, products, or services. Use of these trademarks
|
|
8
|
+
or logos must follow Microsoft's [Trademark & Brand Guidelines](https://www.microsoft.com/en-us/legal/intellectualproperty/trademarks/usage/general).
|
|
9
|
+
Use of Microsoft trademarks or logos in modified versions of this project must not cause confusion or imply Microsoft sponsorship.
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
/*!
|
|
2
|
+
* Copyright (c) Microsoft Corporation and contributors. All rights reserved.
|
|
3
|
+
* Licensed under the MIT License.
|
|
4
|
+
*/
|
|
5
|
+
/**
|
|
6
|
+
* Compare two arrays. Returns true if their elements are equivalent and in the same order.
|
|
7
|
+
*
|
|
8
|
+
* @param left - The first array to compare
|
|
9
|
+
* @param right - The second array to compare
|
|
10
|
+
* @param comparator - The function used to check if two `T`s are equivalent.
|
|
11
|
+
* Defaults to `Object.is()` equality (a shallow compare where NaN = NaN and -0 ≠ 0)
|
|
12
|
+
*/
|
|
13
|
+
export declare const compareArrays: <T>(left: readonly T[], right: readonly T[], comparator?: (leftItem: T, rightItem: T, index: number) => boolean) => boolean;
|
|
14
|
+
//# sourceMappingURL=compare.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"compare.d.ts","sourceRoot":"","sources":["../src/compare.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH;;;;;;;GAOG;AACH,eAAO,MAAM,aAAa,+FAGsB,MAAM,KAAK,OAAO,KAI/D,OAUF,CAAC"}
|
package/dist/compare.js
ADDED
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/*!
|
|
3
|
+
* Copyright (c) Microsoft Corporation and contributors. All rights reserved.
|
|
4
|
+
* Licensed under the MIT License.
|
|
5
|
+
*/
|
|
6
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
7
|
+
exports.compareArrays = void 0;
|
|
8
|
+
/**
|
|
9
|
+
* Compare two arrays. Returns true if their elements are equivalent and in the same order.
|
|
10
|
+
*
|
|
11
|
+
* @param left - The first array to compare
|
|
12
|
+
* @param right - The second array to compare
|
|
13
|
+
* @param comparator - The function used to check if two `T`s are equivalent.
|
|
14
|
+
* Defaults to `Object.is()` equality (a shallow compare where NaN = NaN and -0 ≠ 0)
|
|
15
|
+
*/
|
|
16
|
+
const compareArrays = (left, right, comparator = (leftItem, rightItem) => Object.is(leftItem, rightItem)) => {
|
|
17
|
+
// PERF: 'for-loop' and 'Array.every()' tied.
|
|
18
|
+
// '===' and 'Object.is()' tied.
|
|
19
|
+
// Trivial acceptance adds no measurable overhead.
|
|
20
|
+
// 30% penalty vs. baseline for exported function [node 14 x64].
|
|
21
|
+
return (left === right || // Trivial acceptance: 'left' and 'right' are the same instance
|
|
22
|
+
(left.length === right.length && // Trivial rejection: 'left' and 'right' are different lengths
|
|
23
|
+
left.every((leftItem, index) => comparator(leftItem, right[index], index))));
|
|
24
|
+
};
|
|
25
|
+
exports.compareArrays = compareArrays;
|
|
26
|
+
//# sourceMappingURL=compare.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"compare.js","sourceRoot":"","sources":["../src/compare.ts"],"names":[],"mappings":";AAAA;;;GAGG;;;AAEH;;;;;;;GAOG;AACI,MAAM,aAAa,GAAG,CAC5B,IAAkB,EAClB,KAAmB,EACnB,aAAoE,CACnE,QAAW,EACX,SAAY,EACX,EAAE,CAAC,MAAM,CAAC,EAAE,CAAC,QAAQ,EAAE,SAAS,CAAC,EACzB,EAAE;IACZ,6CAA6C;IAC7C,sCAAsC;IACtC,wDAAwD;IACxD,sEAAsE;IACtE,OAAO,CACN,IAAI,KAAK,KAAK,IAAI,+DAA+D;QACjF,CAAC,IAAI,CAAC,MAAM,KAAK,KAAK,CAAC,MAAM,IAAI,8DAA8D;YAC9F,IAAI,CAAC,KAAK,CAAC,CAAC,QAAQ,EAAE,KAAK,EAAE,EAAE,CAAC,UAAU,CAAC,QAAQ,EAAE,KAAK,CAAC,KAAK,CAAC,EAAE,KAAK,CAAC,CAAC,CAAC,CAC5E,CAAC;AACH,CAAC,CAAC;AAjBW,QAAA,aAAa,iBAiBxB","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\n/**\n * Compare two arrays. Returns true if their elements are equivalent and in the same order.\n *\n * @param left - The first array to compare\n * @param right - The second array to compare\n * @param comparator - The function used to check if two `T`s are equivalent.\n * Defaults to `Object.is()` equality (a shallow compare where NaN = NaN and -0 ≠ 0)\n */\nexport const compareArrays = <T>(\n\tleft: readonly T[],\n\tright: readonly T[],\n\tcomparator: (leftItem: T, rightItem: T, index: number) => boolean = (\n\t\tleftItem: T,\n\t\trightItem: T,\n\t) => Object.is(leftItem, rightItem),\n): boolean => {\n\t// PERF: 'for-loop' and 'Array.every()' tied.\n\t// '===' and 'Object.is()' tied.\n\t// Trivial acceptance adds no measurable overhead.\n\t// 30% penalty vs. baseline for exported function [node 14 x64].\n\treturn (\n\t\tleft === right || // Trivial acceptance: 'left' and 'right' are the same instance\n\t\t(left.length === right.length && // Trivial rejection: 'left' and 'right' are different lengths\n\t\t\tleft.every((leftItem, index) => comparator(leftItem, right[index], index)))\n\t);\n};\n"]}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAAE,aAAa,EAAE,MAAM,WAAW,CAAC"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/*!
|
|
3
|
+
* Copyright (c) Microsoft Corporation and contributors. All rights reserved.
|
|
4
|
+
* Licensed under the MIT License.
|
|
5
|
+
*/
|
|
6
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
7
|
+
exports.compareArrays = void 0;
|
|
8
|
+
var compare_1 = require("./compare");
|
|
9
|
+
Object.defineProperty(exports, "compareArrays", { enumerable: true, get: function () { return compare_1.compareArrays; } });
|
|
10
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";AAAA;;;GAGG;;;AAEH,qCAA0C;AAAjC,wGAAA,aAAa,OAAA","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\nexport { compareArrays } from \"./compare\";\n"]}
|
package/lib/compare.d.ts
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
/*!
|
|
2
|
+
* Copyright (c) Microsoft Corporation and contributors. All rights reserved.
|
|
3
|
+
* Licensed under the MIT License.
|
|
4
|
+
*/
|
|
5
|
+
/**
|
|
6
|
+
* Compare two arrays. Returns true if their elements are equivalent and in the same order.
|
|
7
|
+
*
|
|
8
|
+
* @param left - The first array to compare
|
|
9
|
+
* @param right - The second array to compare
|
|
10
|
+
* @param comparator - The function used to check if two `T`s are equivalent.
|
|
11
|
+
* Defaults to `Object.is()` equality (a shallow compare where NaN = NaN and -0 ≠ 0)
|
|
12
|
+
*/
|
|
13
|
+
export declare const compareArrays: <T>(left: readonly T[], right: readonly T[], comparator?: (leftItem: T, rightItem: T, index: number) => boolean) => boolean;
|
|
14
|
+
//# sourceMappingURL=compare.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"compare.d.ts","sourceRoot":"","sources":["../src/compare.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH;;;;;;;GAOG;AACH,eAAO,MAAM,aAAa,+FAGsB,MAAM,KAAK,OAAO,KAI/D,OAUF,CAAC"}
|
package/lib/compare.js
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
/*!
|
|
2
|
+
* Copyright (c) Microsoft Corporation and contributors. All rights reserved.
|
|
3
|
+
* Licensed under the MIT License.
|
|
4
|
+
*/
|
|
5
|
+
/**
|
|
6
|
+
* Compare two arrays. Returns true if their elements are equivalent and in the same order.
|
|
7
|
+
*
|
|
8
|
+
* @param left - The first array to compare
|
|
9
|
+
* @param right - The second array to compare
|
|
10
|
+
* @param comparator - The function used to check if two `T`s are equivalent.
|
|
11
|
+
* Defaults to `Object.is()` equality (a shallow compare where NaN = NaN and -0 ≠ 0)
|
|
12
|
+
*/
|
|
13
|
+
export const compareArrays = (left, right, comparator = (leftItem, rightItem) => Object.is(leftItem, rightItem)) => {
|
|
14
|
+
// PERF: 'for-loop' and 'Array.every()' tied.
|
|
15
|
+
// '===' and 'Object.is()' tied.
|
|
16
|
+
// Trivial acceptance adds no measurable overhead.
|
|
17
|
+
// 30% penalty vs. baseline for exported function [node 14 x64].
|
|
18
|
+
return (left === right || // Trivial acceptance: 'left' and 'right' are the same instance
|
|
19
|
+
(left.length === right.length && // Trivial rejection: 'left' and 'right' are different lengths
|
|
20
|
+
left.every((leftItem, index) => comparator(leftItem, right[index], index))));
|
|
21
|
+
};
|
|
22
|
+
//# sourceMappingURL=compare.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"compare.js","sourceRoot":"","sources":["../src/compare.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH;;;;;;;GAOG;AACH,MAAM,CAAC,MAAM,aAAa,GAAG,CAC5B,IAAkB,EAClB,KAAmB,EACnB,aAAoE,CACnE,QAAW,EACX,SAAY,EACX,EAAE,CAAC,MAAM,CAAC,EAAE,CAAC,QAAQ,EAAE,SAAS,CAAC,EACzB,EAAE;IACZ,6CAA6C;IAC7C,sCAAsC;IACtC,wDAAwD;IACxD,sEAAsE;IACtE,OAAO,CACN,IAAI,KAAK,KAAK,IAAI,+DAA+D;QACjF,CAAC,IAAI,CAAC,MAAM,KAAK,KAAK,CAAC,MAAM,IAAI,8DAA8D;YAC9F,IAAI,CAAC,KAAK,CAAC,CAAC,QAAQ,EAAE,KAAK,EAAE,EAAE,CAAC,UAAU,CAAC,QAAQ,EAAE,KAAK,CAAC,KAAK,CAAC,EAAE,KAAK,CAAC,CAAC,CAAC,CAC5E,CAAC;AACH,CAAC,CAAC","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\n/**\n * Compare two arrays. Returns true if their elements are equivalent and in the same order.\n *\n * @param left - The first array to compare\n * @param right - The second array to compare\n * @param comparator - The function used to check if two `T`s are equivalent.\n * Defaults to `Object.is()` equality (a shallow compare where NaN = NaN and -0 ≠ 0)\n */\nexport const compareArrays = <T>(\n\tleft: readonly T[],\n\tright: readonly T[],\n\tcomparator: (leftItem: T, rightItem: T, index: number) => boolean = (\n\t\tleftItem: T,\n\t\trightItem: T,\n\t) => Object.is(leftItem, rightItem),\n): boolean => {\n\t// PERF: 'for-loop' and 'Array.every()' tied.\n\t// '===' and 'Object.is()' tied.\n\t// Trivial acceptance adds no measurable overhead.\n\t// 30% penalty vs. baseline for exported function [node 14 x64].\n\treturn (\n\t\tleft === right || // Trivial acceptance: 'left' and 'right' are the same instance\n\t\t(left.length === right.length && // Trivial rejection: 'left' and 'right' are different lengths\n\t\t\tleft.every((leftItem, index) => comparator(leftItem, right[index], index)))\n\t);\n};\n"]}
|
package/lib/index.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAAE,aAAa,EAAE,MAAM,WAAW,CAAC"}
|
package/lib/index.js
ADDED
package/lib/index.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAAE,aAAa,EAAE,MAAM,WAAW,CAAC","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\nexport { compareArrays } from \"./compare\";\n"]}
|
package/package.json
ADDED
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@fluidframework/core-utils",
|
|
3
|
+
"version": "2.0.0-internal.2.4.0",
|
|
4
|
+
"description": "Fluid agnostic utility functions with zero-dependencies",
|
|
5
|
+
"homepage": "https://fluidframework.com",
|
|
6
|
+
"repository": {
|
|
7
|
+
"type": "git",
|
|
8
|
+
"url": "https://github.com/microsoft/FluidFramework.git",
|
|
9
|
+
"directory": "packages/common/core-utils"
|
|
10
|
+
},
|
|
11
|
+
"license": "MIT",
|
|
12
|
+
"author": "Microsoft and contributors",
|
|
13
|
+
"sideEffects": false,
|
|
14
|
+
"main": "dist/index.js",
|
|
15
|
+
"module": "lib/index.js",
|
|
16
|
+
"types": "dist/index.d.ts",
|
|
17
|
+
"scripts": {
|
|
18
|
+
"bench": "mocha --timeout 999999 --perfMode --parentProcess --fgrep @Benchmark --reporter \"../../../node_modules/@fluid-tools/benchmark/dist/MochaReporter.js\"",
|
|
19
|
+
"bench:profile": "mocha --v8-prof --timeout 999999 --perfMode --fgrep @Benchmark --reporter \"../../../node_modules/@fluid-tools/benchmark/dist/MochaReporter.js\" && node --prof-process isolate-0x*-v8.log > profile.txt && rm isolate-0x*-v8.log && cat profile.txt",
|
|
20
|
+
"build": "concurrently npm:build:compile npm:lint && npm run build:docs",
|
|
21
|
+
"build:commonjs": "npm run tsc && npm run typetests:gen && npm run build:test",
|
|
22
|
+
"build:compile": "concurrently npm:build:commonjs npm:build:esnext",
|
|
23
|
+
"build:docs": "api-extractor run --local --typescript-compiler-folder ../../../node_modules/typescript && copyfiles -u 1 ./_api-extractor-temp/doc-models/* ../../../_api-extractor-temp/",
|
|
24
|
+
"build:esnext": "tsc --project ./tsconfig.esnext.json",
|
|
25
|
+
"build:full": "npm run build",
|
|
26
|
+
"build:full:compile": "npm run build:compile",
|
|
27
|
+
"build:test": "tsc --project ./src/test/tsconfig.json",
|
|
28
|
+
"ci:build:docs": "api-extractor run --typescript-compiler-folder ../../../node_modules/typescript && copyfiles -u 1 ./_api-extractor-temp/* ../../../_api-extractor-temp/",
|
|
29
|
+
"clean": "rimraf dist lib *.tsbuildinfo *.build.log",
|
|
30
|
+
"eslint": "eslint --format stylish src",
|
|
31
|
+
"eslint:fix": "eslint --format stylish src --fix --fix-type problem,suggestion,layout",
|
|
32
|
+
"format": "npm run prettier:fix",
|
|
33
|
+
"lint": "npm run eslint",
|
|
34
|
+
"lint:fix": "npm run eslint:fix",
|
|
35
|
+
"prettier": "prettier --check . --ignore-path ../../../.prettierignore",
|
|
36
|
+
"prettier:fix": "prettier --write . --ignore-path ../../../.prettierignore",
|
|
37
|
+
"test": "npm run test:mocha",
|
|
38
|
+
"test:benchmark:report": "mocha --node-option unhandled-rejections=strict,expose-gc --exit --perfMode --fgrep @Benchmark --reporter @fluid-tools/benchmark/dist/MochaReporter.js --timeout 60000",
|
|
39
|
+
"test:coverage": "nyc npm test -- --reporter xunit --reporter-option output=nyc/junit-report.xml",
|
|
40
|
+
"test:mocha": "mocha",
|
|
41
|
+
"test:mocha:verbose": "cross-env FLUID_TEST_VERBOSE=1 npm run test:mocha",
|
|
42
|
+
"tsc": "tsc",
|
|
43
|
+
"typetests:gen": "flub generate typetests --generate --dir .",
|
|
44
|
+
"typetests:prepare": "flub generate typetests --prepare --dir . --pin"
|
|
45
|
+
},
|
|
46
|
+
"nyc": {
|
|
47
|
+
"all": true,
|
|
48
|
+
"cache-dir": "nyc/.cache",
|
|
49
|
+
"exclude": [
|
|
50
|
+
"src/test/**/*.ts",
|
|
51
|
+
"dist/test/**/*.js"
|
|
52
|
+
],
|
|
53
|
+
"exclude-after-remap": false,
|
|
54
|
+
"include": [
|
|
55
|
+
"src/**/*.ts",
|
|
56
|
+
"dist/**/*.js"
|
|
57
|
+
],
|
|
58
|
+
"report-dir": "nyc/report",
|
|
59
|
+
"reporter": [
|
|
60
|
+
"cobertura",
|
|
61
|
+
"html",
|
|
62
|
+
"text"
|
|
63
|
+
],
|
|
64
|
+
"temp-directory": "nyc/.nyc_output"
|
|
65
|
+
},
|
|
66
|
+
"devDependencies": {
|
|
67
|
+
"@fluid-tools/benchmark": "^0.45.0",
|
|
68
|
+
"@fluid-tools/build-cli": "^0.8.0",
|
|
69
|
+
"@fluidframework/build-common": "^1.1.0",
|
|
70
|
+
"@fluidframework/build-tools": "^0.8.0",
|
|
71
|
+
"@fluidframework/eslint-config-fluid": "^2.0.0",
|
|
72
|
+
"@fluidframework/mocha-test-setup": ">=2.0.0-internal.2.4.0 <2.0.0-internal.3.0.0",
|
|
73
|
+
"@microsoft/api-extractor": "^7.22.2",
|
|
74
|
+
"@rushstack/eslint-config": "^2.5.1",
|
|
75
|
+
"@types/mocha": "^9.1.1",
|
|
76
|
+
"@types/node": "^14.18.36",
|
|
77
|
+
"concurrently": "^6.2.0",
|
|
78
|
+
"copyfiles": "^2.4.1",
|
|
79
|
+
"cross-env": "^7.0.2",
|
|
80
|
+
"eslint": "~8.6.0",
|
|
81
|
+
"eslint-config-prettier": "~8.5.0",
|
|
82
|
+
"mocha": "^10.0.0",
|
|
83
|
+
"nyc": "^15.0.0",
|
|
84
|
+
"prettier": "~2.6.2",
|
|
85
|
+
"rimraf": "^2.6.2",
|
|
86
|
+
"source-map-support": "^0.5.16",
|
|
87
|
+
"typescript": "~4.5.5"
|
|
88
|
+
},
|
|
89
|
+
"typeValidation": {
|
|
90
|
+
"disabled": true
|
|
91
|
+
}
|
|
92
|
+
}
|
package/src/compare.ts
ADDED
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
/*!
|
|
2
|
+
* Copyright (c) Microsoft Corporation and contributors. All rights reserved.
|
|
3
|
+
* Licensed under the MIT License.
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Compare two arrays. Returns true if their elements are equivalent and in the same order.
|
|
8
|
+
*
|
|
9
|
+
* @param left - The first array to compare
|
|
10
|
+
* @param right - The second array to compare
|
|
11
|
+
* @param comparator - The function used to check if two `T`s are equivalent.
|
|
12
|
+
* Defaults to `Object.is()` equality (a shallow compare where NaN = NaN and -0 ≠ 0)
|
|
13
|
+
*/
|
|
14
|
+
export const compareArrays = <T>(
|
|
15
|
+
left: readonly T[],
|
|
16
|
+
right: readonly T[],
|
|
17
|
+
comparator: (leftItem: T, rightItem: T, index: number) => boolean = (
|
|
18
|
+
leftItem: T,
|
|
19
|
+
rightItem: T,
|
|
20
|
+
) => Object.is(leftItem, rightItem),
|
|
21
|
+
): boolean => {
|
|
22
|
+
// PERF: 'for-loop' and 'Array.every()' tied.
|
|
23
|
+
// '===' and 'Object.is()' tied.
|
|
24
|
+
// Trivial acceptance adds no measurable overhead.
|
|
25
|
+
// 30% penalty vs. baseline for exported function [node 14 x64].
|
|
26
|
+
return (
|
|
27
|
+
left === right || // Trivial acceptance: 'left' and 'right' are the same instance
|
|
28
|
+
(left.length === right.length && // Trivial rejection: 'left' and 'right' are different lengths
|
|
29
|
+
left.every((leftItem, index) => comparator(leftItem, right[index], index)))
|
|
30
|
+
);
|
|
31
|
+
};
|
package/src/index.ts
ADDED