@fluidframework/core-utils 2.0.0-dev-rc.1.0.0.224419

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.
Files changed (111) hide show
  1. package/.eslintrc.js +36 -0
  2. package/.mocharc.js +13 -0
  3. package/CHANGELOG.md +81 -0
  4. package/LICENSE +21 -0
  5. package/README.md +75 -0
  6. package/api-extractor-lint.json +4 -0
  7. package/api-extractor.json +4 -0
  8. package/api-report/core-utils.api.md +147 -0
  9. package/dist/assert.d.ts +17 -0
  10. package/dist/assert.d.ts.map +1 -0
  11. package/dist/assert.js +25 -0
  12. package/dist/assert.js.map +1 -0
  13. package/dist/compare.d.ts +16 -0
  14. package/dist/compare.d.ts.map +1 -0
  15. package/dist/compare.js +28 -0
  16. package/dist/compare.js.map +1 -0
  17. package/dist/core-utils-alpha.d.ts +191 -0
  18. package/dist/core-utils-beta.d.ts +41 -0
  19. package/dist/core-utils-public.d.ts +41 -0
  20. package/dist/core-utils-untrimmed.d.ts +414 -0
  21. package/dist/delay.d.ts +11 -0
  22. package/dist/delay.d.ts.map +1 -0
  23. package/dist/delay.js +15 -0
  24. package/dist/delay.js.map +1 -0
  25. package/dist/heap.d.ts +86 -0
  26. package/dist/heap.d.ts.map +1 -0
  27. package/dist/heap.js +144 -0
  28. package/dist/heap.js.map +1 -0
  29. package/dist/index.d.ts +14 -0
  30. package/dist/index.d.ts.map +1 -0
  31. package/dist/index.js +30 -0
  32. package/dist/index.js.map +1 -0
  33. package/dist/lazy.d.ts +44 -0
  34. package/dist/lazy.d.ts.map +1 -0
  35. package/dist/lazy.js +84 -0
  36. package/dist/lazy.js.map +1 -0
  37. package/dist/promiseCache.d.ts +89 -0
  38. package/dist/promiseCache.d.ts.map +1 -0
  39. package/dist/promiseCache.js +148 -0
  40. package/dist/promiseCache.js.map +1 -0
  41. package/dist/promises.d.ts +38 -0
  42. package/dist/promises.d.ts.map +1 -0
  43. package/dist/promises.js +60 -0
  44. package/dist/promises.js.map +1 -0
  45. package/dist/timer.d.ts +115 -0
  46. package/dist/timer.d.ts.map +1 -0
  47. package/dist/timer.js +189 -0
  48. package/dist/timer.js.map +1 -0
  49. package/dist/tsdoc-metadata.json +11 -0
  50. package/dist/unreachable.d.ts +22 -0
  51. package/dist/unreachable.d.ts.map +1 -0
  52. package/dist/unreachable.js +28 -0
  53. package/dist/unreachable.js.map +1 -0
  54. package/lib/assert.d.ts +17 -0
  55. package/lib/assert.d.ts.map +1 -0
  56. package/lib/assert.js +25 -0
  57. package/lib/assert.js.map +1 -0
  58. package/lib/compare.d.ts +16 -0
  59. package/lib/compare.d.ts.map +1 -0
  60. package/lib/compare.js +28 -0
  61. package/lib/compare.js.map +1 -0
  62. package/lib/core-utils-alpha.d.ts +191 -0
  63. package/lib/core-utils-beta.d.ts +41 -0
  64. package/lib/core-utils-public.d.ts +41 -0
  65. package/lib/core-utils-untrimmed.d.ts +414 -0
  66. package/lib/delay.d.ts +11 -0
  67. package/lib/delay.d.ts.map +1 -0
  68. package/lib/delay.js +15 -0
  69. package/lib/delay.js.map +1 -0
  70. package/lib/heap.d.ts +86 -0
  71. package/lib/heap.d.ts.map +1 -0
  72. package/lib/heap.js +144 -0
  73. package/lib/heap.js.map +1 -0
  74. package/lib/index.d.ts +14 -0
  75. package/lib/index.d.ts.map +1 -0
  76. package/lib/index.js +30 -0
  77. package/lib/index.js.map +1 -0
  78. package/lib/lazy.d.ts +44 -0
  79. package/lib/lazy.d.ts.map +1 -0
  80. package/lib/lazy.js +84 -0
  81. package/lib/lazy.js.map +1 -0
  82. package/lib/promiseCache.d.ts +89 -0
  83. package/lib/promiseCache.d.ts.map +1 -0
  84. package/lib/promiseCache.js +148 -0
  85. package/lib/promiseCache.js.map +1 -0
  86. package/lib/promises.d.ts +38 -0
  87. package/lib/promises.d.ts.map +1 -0
  88. package/lib/promises.js +60 -0
  89. package/lib/promises.js.map +1 -0
  90. package/lib/timer.d.ts +115 -0
  91. package/lib/timer.d.ts.map +1 -0
  92. package/lib/timer.js +189 -0
  93. package/lib/timer.js.map +1 -0
  94. package/lib/unreachable.d.ts +22 -0
  95. package/lib/unreachable.d.ts.map +1 -0
  96. package/lib/unreachable.js +28 -0
  97. package/lib/unreachable.js.map +1 -0
  98. package/package.json +111 -0
  99. package/prettier.config.cjs +8 -0
  100. package/src/assert.ts +23 -0
  101. package/src/compare.ts +33 -0
  102. package/src/delay.ts +12 -0
  103. package/src/heap.ts +182 -0
  104. package/src/index.ts +21 -0
  105. package/src/lazy.ts +88 -0
  106. package/src/promiseCache.ts +205 -0
  107. package/src/promises.ts +63 -0
  108. package/src/timer.ts +289 -0
  109. package/src/unreachable.ts +24 -0
  110. package/tsconfig.esnext.json +6 -0
  111. package/tsconfig.json +12 -0
package/.eslintrc.js ADDED
@@ -0,0 +1,36 @@
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"), "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
+ // This has been disabled in the next eslint-config-fluid.
17
+ // Once the dependency here has been updated, this override can be removed.
18
+ "unicorn/numeric-separators-style": "off",
19
+ },
20
+ overrides: [
21
+ {
22
+ // Rules only for test files
23
+ files: ["*.spec.ts", "*.test.ts", "src/test/**"],
24
+ rules: {
25
+ // Test files are run in node only so additional node libraries can be used.
26
+ "import/no-nodejs-modules": [
27
+ "error",
28
+ { allow: ["node:assert", "node:events", "node:process"] },
29
+ ],
30
+
31
+ // Does not work well with describe/it block scoping
32
+ "unicorn/consistent-function-scoping": "off",
33
+ },
34
+ },
35
+ ],
36
+ };
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);
12
+ config.spec = "dist/test";
13
+ module.exports = config;
package/CHANGELOG.md ADDED
@@ -0,0 +1,81 @@
1
+ # @fluidframework/core-utils
2
+
3
+ ## 2.0.0-internal.8.0.0
4
+
5
+ Dependency updates only.
6
+
7
+ ## 2.0.0-internal.7.4.0
8
+
9
+ Dependency updates only.
10
+
11
+ ## 2.0.0-internal.7.3.0
12
+
13
+ Dependency updates only.
14
+
15
+ ## 2.0.0-internal.7.2.0
16
+
17
+ Dependency updates only.
18
+
19
+ ## 2.0.0-internal.7.1.0
20
+
21
+ Dependency updates only.
22
+
23
+ ## 2.0.0-internal.7.0.0
24
+
25
+ ### Major Changes
26
+
27
+ - Minimum TypeScript version now 5.1.6 [871b3493dd](https://github.com/microsoft/FluidFramework/commits/871b3493dd0d7ea3a89be64998ceb6cb9021a04e)
28
+
29
+ The minimum supported TypeScript version for Fluid 2.0 clients is now 5.1.6.
30
+
31
+ ## 2.0.0-internal.6.4.0
32
+
33
+ Dependency updates only.
34
+
35
+ ## 2.0.0-internal.6.3.0
36
+
37
+ Dependency updates only.
38
+
39
+ ## 2.0.0-internal.6.2.0
40
+
41
+ Dependency updates only.
42
+
43
+ ## 2.0.0-internal.6.1.0
44
+
45
+ Dependency updates only.
46
+
47
+ ## 2.0.0-internal.6.0.0
48
+
49
+ ### Major Changes
50
+
51
+ - Upgraded typescript transpilation target to ES2020 [8abce8cdb4](https://github.com/microsoft/FluidFramework/commits/8abce8cdb4e2832fb6405fb44e393bef03d5648a)
52
+
53
+ Upgraded typescript transpilation target to ES2020. This is done in order to decrease the bundle sizes of Fluid Framework packages. This has provided size improvements across the board for ex. Loader, Driver, Runtime etc. Reduced bundle sizes helps to load lesser code in apps and hence also helps to improve the perf.If any app wants to target any older versions of browsers with which this target version is not compatible, then they can use packages like babel to transpile to a older target.
54
+
55
+ ## 2.0.0-internal.5.4.0
56
+
57
+ Dependency updates only.
58
+
59
+ ## 2.0.0-internal.5.3.0
60
+
61
+ Dependency updates only.
62
+
63
+ ## 2.0.0-internal.5.2.0
64
+
65
+ Dependency updates only.
66
+
67
+ ## 2.0.0-internal.5.1.0
68
+
69
+ Dependency updates only.
70
+
71
+ ## 2.0.0-internal.5.0.0
72
+
73
+ Dependency updates only.
74
+
75
+ ## 2.0.0-internal.4.4.0
76
+
77
+ Dependency updates only.
78
+
79
+ ## 2.0.0-internal.4.1.0
80
+
81
+ Dependency updates only.
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,75 @@
1
+ # @fluidframework/core-utils
2
+
3
+ This package is intended for sharing and promoting best-practice implementations of Fluid-agnostic utility functions
4
+ across packages in the Fluid Framework repo.
5
+
6
+ <!-- AUTO-GENERATED-CONTENT:START (README_PACKAGE_SCOPE_NOTICE:scopeKind=INTERNAL) -->
7
+
8
+ **IMPORTANT: This package is intended strictly as an implementation detail of the Fluid Framework and is not intended for public consumption.**
9
+ **We make no stability guarantees regarding its APIs.**
10
+
11
+ <!-- AUTO-GENERATED-CONTENT:END -->
12
+
13
+ ## Adding code to this package
14
+
15
+ As a utility package, this package does not have a strong identity. This means that it's easy to become a "dumping
16
+ ground" for code that we think we should share but doesn't have an obvious home. We try to avoid dumping things into
17
+ utility packages, and this one is no exception.
18
+
19
+ New code should only be added to this package in rare circumstances. In most cases, the code would be better placed in a
20
+ package with a clear identity (e.g. an "events" package for shared event infrastructure) or not shared at all.
21
+
22
+ ## Requirements
23
+
24
+ This package has important requirements for the code within it.
25
+
26
+ 1. **Code in this package must have zero dependencies.** That is, it must not depend on other packages, even within the
27
+ Fluid Framework repo. `devDependencies` are OK.
28
+ 1. **All exports must be designated `@internal`.** This code is intended for use within the Fluid Framework only.
29
+ 1. This package should **only contain 'implementation' code, not type definitions.** This is the most flexible rule, and
30
+ there are some exceptions. If the type is _only_ necessary when using this package, then it is probably OK. However,
31
+ usually such types would be better placed in core-interfaces or in a package that corresponds to the purpose.
32
+
33
+ If you want to add code that does not meet these requirements, these other packages may be a better choice:
34
+
35
+ - **Types and interfaces** that are intended to be broadly shared across the client release group should be put in the
36
+ **core-interfaces** package.
37
+ - **Shared implementation code with dependencies** should be put in the **client-utils** package.
38
+
39
+ <!-- AUTO-GENERATED-CONTENT:START (README_DEPENDENCY_GUIDELINES_SECTION:includeHeading=TRUE) -->
40
+
41
+ <!-- prettier-ignore-start -->
42
+ <!-- NOTE: This section is automatically generated using @fluid-tools/markdown-magic. Do not update these generated contents directly. -->
43
+
44
+ ## Using Fluid Framework libraries
45
+
46
+ When taking a dependency on a Fluid Framework library, we recommend using a `^` (caret) version range, such as `^1.3.4`.
47
+ While Fluid Framework libraries may use different ranges with interdependencies between other Fluid Framework libraries,
48
+ library consumers should always prefer `^`.
49
+
50
+ Note that when depending on a library version of the form `2.0.0-internal.x.y.z`, called the Fluid internal version scheme,
51
+ you must use a `>= <` dependency range (such as `>=2.0.0-internal.x.y.z <2.0.0-internal.w.0.0` where `w` is `x+1`).
52
+ Standard `^` and `~` ranges will not work as expected.
53
+ See the [@fluid-tools/version-tools](https://github.com/microsoft/FluidFramework/blob/main/build-tools/packages/version-tools/README.md)
54
+ package for more information including tools to convert between version schemes.
55
+
56
+ <!-- prettier-ignore-end -->
57
+
58
+ <!-- AUTO-GENERATED-CONTENT:END -->
59
+
60
+ <!-- AUTO-GENERATED-CONTENT:START (README_TRADEMARK_SECTION:includeHeading=TRUE) -->
61
+
62
+ <!-- prettier-ignore-start -->
63
+ <!-- NOTE: This section is automatically generated using @fluid-tools/markdown-magic. Do not update these generated contents directly. -->
64
+
65
+ ## Trademark
66
+
67
+ This project may contain Microsoft trademarks or logos for Microsoft projects, products, or services.
68
+
69
+ Use of these trademarks or logos must follow Microsoft's [Trademark & Brand Guidelines](https://www.microsoft.com/en-us/legal/intellectualproperty/trademarks/usage/general).
70
+
71
+ Use of Microsoft trademarks or logos in modified versions of this project must not cause confusion or imply Microsoft sponsorship.
72
+
73
+ <!-- prettier-ignore-end -->
74
+
75
+ <!-- AUTO-GENERATED-CONTENT:END -->
@@ -0,0 +1,4 @@
1
+ {
2
+ "$schema": "https://developer.microsoft.com/json-schemas/api-extractor/v7/api-extractor.schema.json",
3
+ "extends": "../../../common/build/build-common/api-extractor-lint.json"
4
+ }
@@ -0,0 +1,4 @@
1
+ {
2
+ "$schema": "https://developer.microsoft.com/json-schemas/api-extractor/v7/api-extractor.schema.json",
3
+ "extends": "../../../common/build/build-common/api-extractor-base.json"
4
+ }
@@ -0,0 +1,147 @@
1
+ ## API Report File for "@fluidframework/core-utils"
2
+
3
+ > Do not edit this file. It is a report generated by [API Extractor](https://api-extractor.com/).
4
+
5
+ ```ts
6
+
7
+ // @alpha
8
+ export function assert(condition: boolean, message: string | number): asserts condition;
9
+
10
+ // @alpha
11
+ export const compareArrays: <T>(left: readonly T[], right: readonly T[], comparator?: (leftItem: T, rightItem: T, index: number) => boolean) => boolean;
12
+
13
+ // @alpha
14
+ export class Deferred<T> {
15
+ constructor();
16
+ get isCompleted(): boolean;
17
+ get promise(): Promise<T>;
18
+ reject(error: any): void;
19
+ resolve(value: T | PromiseLike<T>): void;
20
+ }
21
+
22
+ // @internal
23
+ export const delay: (timeMs: number) => Promise<void>;
24
+
25
+ // @internal
26
+ export class Heap<T> {
27
+ constructor(comp: IComparer<T>);
28
+ add(x: T): IHeapNode<T>;
29
+ // (undocumented)
30
+ comp: IComparer<T>;
31
+ count(): number;
32
+ get(): T | undefined;
33
+ peek(): IHeapNode<T> | undefined;
34
+ remove(node: IHeapNode<T>): void;
35
+ update(node: IHeapNode<T>): void;
36
+ }
37
+
38
+ // @internal
39
+ export interface IComparer<T> {
40
+ compare(a: T, b: T): number;
41
+ min: T;
42
+ }
43
+
44
+ // @internal
45
+ export interface IHeapNode<T> {
46
+ // (undocumented)
47
+ position: number;
48
+ // (undocumented)
49
+ value: T;
50
+ }
51
+
52
+ // @internal
53
+ export interface IPromiseTimer extends ITimer {
54
+ start(): Promise<IPromiseTimerResult>;
55
+ }
56
+
57
+ // @internal (undocumented)
58
+ export interface IPromiseTimerResult {
59
+ // (undocumented)
60
+ timerResult: "timeout" | "cancel";
61
+ }
62
+
63
+ // @internal (undocumented)
64
+ export interface ITimer {
65
+ clear(): void;
66
+ readonly hasTimer: boolean;
67
+ start(): void;
68
+ }
69
+
70
+ // @internal
71
+ export class Lazy<T> {
72
+ constructor(valueGenerator: () => T);
73
+ get evaluated(): boolean;
74
+ get value(): T;
75
+ }
76
+
77
+ // @alpha
78
+ export class LazyPromise<T> implements Promise<T> {
79
+ // (undocumented)
80
+ get [Symbol.toStringTag](): string;
81
+ constructor(execute: () => Promise<T>);
82
+ // (undocumented)
83
+ catch<TResult = never>(onrejected?: ((reason: any) => TResult | PromiseLike<TResult>) | null | undefined): Promise<T | TResult>;
84
+ // (undocumented)
85
+ finally(onfinally?: (() => void) | null | undefined): Promise<T>;
86
+ // (undocumented)
87
+ then<TResult1 = T, TResult2 = never>(onfulfilled?: ((value: T) => TResult1 | PromiseLike<TResult1>) | null | undefined, onrejected?: ((reason: any) => TResult2 | PromiseLike<TResult2>) | null | undefined): Promise<TResult1 | TResult2>;
88
+ }
89
+
90
+ // @internal
91
+ export const NumberComparer: IComparer<number>;
92
+
93
+ // @alpha
94
+ export class PromiseCache<TKey, TResult> {
95
+ constructor({ expiry, removeOnError, }?: PromiseCacheOptions);
96
+ add(key: TKey, asyncFn: () => Promise<TResult>): boolean;
97
+ addOrGet(key: TKey, asyncFn: () => Promise<TResult>): Promise<TResult>;
98
+ addValue(key: TKey, value: TResult): boolean;
99
+ addValueOrGet(key: TKey, value: TResult): Promise<TResult>;
100
+ get(key: TKey): Promise<TResult> | undefined;
101
+ has(key: TKey): boolean;
102
+ remove(key: TKey): boolean;
103
+ }
104
+
105
+ // @alpha
106
+ export type PromiseCacheExpiry = {
107
+ policy: "indefinite";
108
+ } | {
109
+ policy: "absolute" | "sliding";
110
+ durationMs: number;
111
+ };
112
+
113
+ // @alpha
114
+ export interface PromiseCacheOptions {
115
+ expiry?: PromiseCacheExpiry;
116
+ removeOnError?: (error: any) => boolean;
117
+ }
118
+
119
+ // @internal
120
+ export class PromiseTimer implements IPromiseTimer {
121
+ constructor(defaultTimeout: number, defaultHandler: () => void);
122
+ // (undocumented)
123
+ clear(): void;
124
+ get hasTimer(): boolean;
125
+ start(ms?: number, handler?: () => void): Promise<IPromiseTimerResult>;
126
+ // (undocumented)
127
+ protected wrapHandler(handler: () => void): void;
128
+ }
129
+
130
+ // @internal
131
+ export function setLongTimeout(timeoutFn: () => void, timeoutMs: number, setTimeoutIdFn?: (timeoutId: ReturnType<typeof setTimeout>) => void): ReturnType<typeof setTimeout>;
132
+
133
+ // @internal
134
+ export class Timer implements ITimer {
135
+ constructor(defaultTimeout: number, defaultHandler: () => void, getCurrentTick?: () => number);
136
+ clear(): void;
137
+ get hasTimer(): boolean;
138
+ restart(ms?: number, handler?: () => void): void;
139
+ start(ms?: number, handler?: () => void): void;
140
+ }
141
+
142
+ // @internal
143
+ export function unreachableCase(_: never, message?: string): never;
144
+
145
+ // (No @packageDocumentation comment for this package)
146
+
147
+ ```
@@ -0,0 +1,17 @@
1
+ /*!
2
+ * Copyright (c) Microsoft Corporation and contributors. All rights reserved.
3
+ * Licensed under the MIT License.
4
+ */
5
+ /**
6
+ * A browser friendly assert library.
7
+ * Use this instead of the 'assert' package, which has a big impact on bundle sizes.
8
+ * @param condition - The condition that should be true, if the condition is false an error will be thrown.
9
+ * Only use this API when `false` indicates a logic error in the problem and thus a bug that should be fixed.
10
+ * @param message - The message to include in the error when the condition does not hold.
11
+ * A number should not be specified manually: use a string.
12
+ * Before a release, policy-check should be run, which will convert any asserts still using strings to
13
+ * use numbered error codes instead.
14
+ * @alpha
15
+ */
16
+ export declare function assert(condition: boolean, message: string | number): asserts condition;
17
+ //# sourceMappingURL=assert.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"assert.d.ts","sourceRoot":"","sources":["../src/assert.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH;;;;;;;;;;GAUG;AACH,wBAAgB,MAAM,CAAC,SAAS,EAAE,OAAO,EAAE,OAAO,EAAE,MAAM,GAAG,MAAM,GAAG,OAAO,CAAC,SAAS,CAMtF"}
package/dist/assert.js ADDED
@@ -0,0 +1,25 @@
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.assert = void 0;
8
+ /**
9
+ * A browser friendly assert library.
10
+ * Use this instead of the 'assert' package, which has a big impact on bundle sizes.
11
+ * @param condition - The condition that should be true, if the condition is false an error will be thrown.
12
+ * Only use this API when `false` indicates a logic error in the problem and thus a bug that should be fixed.
13
+ * @param message - The message to include in the error when the condition does not hold.
14
+ * A number should not be specified manually: use a string.
15
+ * Before a release, policy-check should be run, which will convert any asserts still using strings to
16
+ * use numbered error codes instead.
17
+ * @alpha
18
+ */
19
+ function assert(condition, message) {
20
+ if (!condition) {
21
+ throw new Error(typeof message === "number" ? `0x${message.toString(16).padStart(3, "0")}` : message);
22
+ }
23
+ }
24
+ exports.assert = assert;
25
+ //# sourceMappingURL=assert.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"assert.js","sourceRoot":"","sources":["../src/assert.ts"],"names":[],"mappings":";AAAA;;;GAGG;;;AAEH;;;;;;;;;;GAUG;AACH,SAAgB,MAAM,CAAC,SAAkB,EAAE,OAAwB;IAClE,IAAI,CAAC,SAAS,EAAE;QACf,MAAM,IAAI,KAAK,CACd,OAAO,OAAO,KAAK,QAAQ,CAAC,CAAC,CAAC,KAAK,OAAO,CAAC,QAAQ,CAAC,EAAE,CAAC,CAAC,QAAQ,CAAC,CAAC,EAAE,GAAG,CAAC,EAAE,CAAC,CAAC,CAAC,OAAO,CACpF,CAAC;KACF;AACF,CAAC;AAND,wBAMC","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\n/**\n * A browser friendly assert library.\n * Use this instead of the 'assert' package, which has a big impact on bundle sizes.\n * @param condition - The condition that should be true, if the condition is false an error will be thrown.\n * Only use this API when `false` indicates a logic error in the problem and thus a bug that should be fixed.\n * @param message - The message to include in the error when the condition does not hold.\n * A number should not be specified manually: use a string.\n * Before a release, policy-check should be run, which will convert any asserts still using strings to\n * use numbered error codes instead.\n * @alpha\n */\nexport function assert(condition: boolean, message: string | number): asserts condition {\n\tif (!condition) {\n\t\tthrow new Error(\n\t\t\ttypeof message === \"number\" ? `0x${message.toString(16).padStart(3, \"0\")}` : message,\n\t\t);\n\t}\n}\n"]}
@@ -0,0 +1,16 @@
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
+ * @alpha
9
+ *
10
+ * @param left - The first array to compare
11
+ * @param right - The second array to compare
12
+ * @param comparator - The function used to check if two `T`s are equivalent.
13
+ * Defaults to `Object.is()` equality (a shallow compare where NaN = NaN and -0 ≠ 0)
14
+ */
15
+ export declare const compareArrays: <T>(left: readonly T[], right: readonly T[], comparator?: (leftItem: T, rightItem: T, index: number) => boolean) => boolean;
16
+ //# 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;;;;;;;;;GASG;AACH,eAAO,MAAM,aAAa,+FAGsB,MAAM,KAAK,OAAO,KAI/D,OAUF,CAAC"}
@@ -0,0 +1,28 @@
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
+ * @alpha
12
+ *
13
+ * @param left - The first array to compare
14
+ * @param right - The second array to compare
15
+ * @param comparator - The function used to check if two `T`s are equivalent.
16
+ * Defaults to `Object.is()` equality (a shallow compare where NaN = NaN and -0 ≠ 0)
17
+ */
18
+ const compareArrays = (left, right, comparator = (leftItem, rightItem) => Object.is(leftItem, rightItem)) => {
19
+ // PERF: 'for-loop' and 'Array.every()' tied.
20
+ // '===' and 'Object.is()' tied.
21
+ // Trivial acceptance adds no measurable overhead.
22
+ // 30% penalty vs. baseline for exported function [node 14 x64].
23
+ return (left === right || // Trivial acceptance: 'left' and 'right' are the same instance
24
+ (left.length === right.length && // Trivial rejection: 'left' and 'right' are different lengths
25
+ left.every((leftItem, index) => comparator(leftItem, right[index], index))));
26
+ };
27
+ exports.compareArrays = compareArrays;
28
+ //# sourceMappingURL=compare.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"compare.js","sourceRoot":"","sources":["../src/compare.ts"],"names":[],"mappings":";AAAA;;;GAGG;;;AAEH;;;;;;;;;GASG;AACI,MAAM,aAAa,GAAG,CAC5B,IAAkB,EAClB,KAAmB,EACnB,aAAoE,CACnE,QAAW,EACX,SAAY,EACF,EAAE,CAAC,MAAM,CAAC,EAAE,CAAC,QAAQ,EAAE,SAAS,CAAC,EAClC,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 * @alpha\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): boolean => 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"]}