@danielsimonjr/mathts-core 0.14.3 → 0.15.1

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 (90) hide show
  1. package/dist/arithmetic/scalar.d.ts +56 -0
  2. package/dist/arithmetic/scalar.d.ts.map +1 -0
  3. package/dist/array.d.ts +265 -0
  4. package/dist/array.d.ts.map +1 -0
  5. package/dist/bignumber-formatter.d.ts +135 -0
  6. package/dist/bignumber-formatter.d.ts.map +1 -0
  7. package/dist/collection.d.ts +67 -0
  8. package/dist/collection.d.ts.map +1 -0
  9. package/dist/config.d.ts +20 -0
  10. package/dist/config.d.ts.map +1 -0
  11. package/dist/constants.d.ts +30 -0
  12. package/dist/constants.d.ts.map +1 -0
  13. package/dist/customs.d.ts +44 -0
  14. package/dist/customs.d.ts.map +1 -0
  15. package/dist/error/DimensionError.d.ts +28 -0
  16. package/dist/error/DimensionError.d.ts.map +1 -0
  17. package/dist/error/IndexError.d.ts +41 -0
  18. package/dist/error/IndexError.d.ts.map +1 -0
  19. package/dist/error/MathjsError.d.ts +13 -0
  20. package/dist/error/MathjsError.d.ts.map +1 -0
  21. package/dist/factory/factory.d.ts +154 -0
  22. package/dist/factory/factory.d.ts.map +1 -0
  23. package/dist/factory/index.d.ts +6 -0
  24. package/dist/factory/index.d.ts.map +1 -0
  25. package/dist/factory.d.ts +122 -0
  26. package/dist/factory.d.ts.map +1 -0
  27. package/dist/index.d.ts +24 -2593
  28. package/dist/index.d.ts.map +1 -0
  29. package/dist/index.js +36 -18
  30. package/dist/internal.d.ts +33 -1344
  31. package/dist/internal.d.ts.map +1 -0
  32. package/dist/internal.js +36 -6
  33. package/dist/is.d.ts +256 -0
  34. package/dist/is.d.ts.map +1 -0
  35. package/dist/map.d.ts +147 -0
  36. package/dist/map.d.ts.map +1 -0
  37. package/dist/number.d.ts +314 -0
  38. package/dist/number.d.ts.map +1 -0
  39. package/dist/numeric/stable.d.ts +130 -0
  40. package/dist/numeric/stable.d.ts.map +1 -0
  41. package/dist/object.d.ts +119 -0
  42. package/dist/object.d.ts.map +1 -0
  43. package/dist/shared.d.ts +41 -0
  44. package/dist/shared.d.ts.map +1 -0
  45. package/dist/string.d.ts +70 -0
  46. package/dist/string.d.ts.map +1 -0
  47. package/dist/switch.d.ts +9 -0
  48. package/dist/switch.d.ts.map +1 -0
  49. package/dist/typed/index.d.ts +7 -0
  50. package/dist/typed/index.d.ts.map +1 -0
  51. package/dist/typed/mathts-typed.d.ts +246 -0
  52. package/dist/typed/mathts-typed.d.ts.map +1 -0
  53. package/dist/typed/type-bridge.d.ts +9 -0
  54. package/dist/typed/type-bridge.d.ts.map +1 -0
  55. package/dist/types/bignumber.d.ts +370 -0
  56. package/dist/types/bignumber.d.ts.map +1 -0
  57. package/dist/types/complex.d.ts +284 -0
  58. package/dist/types/complex.d.ts.map +1 -0
  59. package/dist/types/dual-rules.d.ts +129 -0
  60. package/dist/types/dual-rules.d.ts.map +1 -0
  61. package/dist/types/dual.d.ts +39 -0
  62. package/dist/types/dual.d.ts.map +1 -0
  63. package/dist/types/fraction.d.ts +215 -0
  64. package/dist/types/fraction.d.ts.map +1 -0
  65. package/dist/types/interfaces.d.ts +143 -0
  66. package/dist/types/interfaces.d.ts.map +1 -0
  67. package/dist/types/matrix/Range.d.ts +767 -0
  68. package/dist/types/matrix/Range.d.ts.map +1 -0
  69. package/dist/types/unit/Unit.d.ts +3 -0
  70. package/dist/types/unit/Unit.d.ts.map +1 -0
  71. package/dist/types/unit/dependencies.d.ts +4 -0
  72. package/dist/types/unit/dependencies.d.ts.map +1 -0
  73. package/dist/types/unit/errors.d.ts +18 -0
  74. package/dist/types/unit/errors.d.ts.map +1 -0
  75. package/dist/types/unit/index.d.ts +7 -0
  76. package/dist/types/unit/index.d.ts.map +1 -0
  77. package/dist/types/unit/unit-types.d.ts +231 -0
  78. package/dist/types/unit/unit-types.d.ts.map +1 -0
  79. package/dist/types/unit-definitions.d.ts +79 -0
  80. package/dist/types/unit-definitions.d.ts.map +1 -0
  81. package/dist/types/unit-prefixes.d.ts +29 -0
  82. package/dist/types/unit-prefixes.d.ts.map +1 -0
  83. package/dist/types/unit.d.ts +28 -0
  84. package/dist/types/unit.d.ts.map +1 -0
  85. package/dist/types/wasm-loader.d.ts +35 -0
  86. package/dist/types/wasm-loader.d.ts.map +1 -0
  87. package/dist/wasm-loader.d.ts +97 -0
  88. package/dist/wasm-loader.d.ts.map +1 -0
  89. package/package.json +8 -8
  90. package/dist/index-B4LIOfHN.d.ts +0 -449
@@ -0,0 +1 @@
1
+ {"version":3,"file":"internal.d.ts","sourceRoot":"","sources":["../src/internal.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AACH,cAAc,SAAS,CAAC;AACxB,cAAc,aAAa,CAAC;AAC5B,cAAc,aAAa,CAAC;AAC5B,OAAO,EAAE,cAAc,EAAE,QAAQ,EAAE,QAAQ,EAAE,OAAO,EAAE,MAAM,aAAa,CAAC;AAC1E,YAAY,EAAE,gBAAgB,EAAE,MAAM,aAAa,CAAC;AASpD,YAAY,EAAE,aAAa,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAC/D,OAAO,EAAE,cAAc,EAAE,MAAM,aAAa,CAAC;AAU7C,OAAO,EAAE,WAAW,EAAE,MAAM,wBAAwB,CAAC;AACrD,OAAO,EAAE,cAAc,EAAE,MAAM,2BAA2B,CAAC;AAC3D,OAAO,EAAE,UAAU,EAAE,gBAAgB,EAAE,MAAM,uBAAuB,CAAC;AAoBrE,cAAc,cAAc,CAAC;AAM7B,OAAO,EACL,MAAM,IAAI,aAAa,EACvB,SAAS,EACT,MAAM,EACN,WAAW,EACX,KAAK,oBAAoB,GAC1B,MAAM,aAAa,CAAC;AAMrB,OAAO,EACL,MAAM,IAAI,eAAe,EACzB,aAAa,IAAI,sBAAsB,EACvC,aAAa,IAAI,sBAAsB,EACvC,OAAO,IAAI,gBAAgB,EAC3B,KAAK,cAAc,GACpB,MAAM,0BAA0B,CAAC;AAIlC,mBAAmB,4BAA4B,CAAC;AAMhD,OAAO,EAAE,eAAe,EAAE,gBAAgB,EAAE,IAAI,IAAI,QAAQ,EAAE,MAAM,uBAAuB,CAAC;AAe5F,YAAY,EAAE,WAAW,EAAE,eAAe,EAAE,MAAM,YAAY,CAAC;AAC/D,OAAO,EACL,SAAS,EACT,QAAQ,EACR,uBAAuB,EACvB,aAAa,EACb,YAAY,EACZ,MAAM,EACN,OAAO,EACP,oBAAoB,EACpB,OAAO,EACP,SAAS,EACT,OAAO,EACP,GAAG,EACH,OAAO,EACP,MAAM,EACN,YAAY,EACZ,IAAI,EACJ,QAAQ,EACR,UAAU,EACV,gBAAgB,EAChB,IAAI,EACJ,OAAO,EACP,MAAM,EACN,cAAc,EACd,sBAAsB,EACtB,WAAW,EACX,eAAe,EACf,OAAO,EACP,GAAG,IAAI,eAAe,EACtB,OAAO,IAAI,YAAY,EACvB,WAAW,IAAI,gBAAgB,EAC/B,KAAK,IAAI,UAAU,GACpB,MAAM,YAAY,CAAC;AAEpB,OAAO,EAAE,mBAAmB,EAAE,OAAO,EAAE,WAAW,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,iBAAiB,CAAC;AAC7F,OAAO,EAAE,OAAO,EAAE,MAAM,aAAa,CAAC;AAEtC,OAAO,EACL,iBAAiB,EACjB,cAAc,EACd,cAAc,EACd,SAAS,EACT,QAAQ,EACR,MAAM,IAAI,SAAS,EACnB,mBAAmB,GACpB,MAAM,UAAU,CAAC;AAOlB,YAAY,EAAE,cAAc,EAAE,YAAY,EAAE,MAAM,wBAAwB,CAAC;AAc3E,OAAO,EACL,cAAc,EACd,gBAAgB,EAChB,mBAAmB,EACnB,mBAAmB,EACnB,mBAAmB,GACpB,MAAM,kBAAkB,CAAC"}
package/dist/internal.js CHANGED
@@ -87,6 +87,8 @@ var DimensionError = class _DimensionError extends RangeError {
87
87
  relation;
88
88
  isDimensionError = true;
89
89
  /**
90
+ * Create a DimensionError. When `actual` is a string and `expected` is not given, the string is the message.
91
+ *
90
92
  * @param actual - The actual size or custom error message
91
93
  * @param expected - The expected size (optional if actual is a custom message)
92
94
  * @param relation - Optional relation between actual and expected size: '!=', '<', etc.
@@ -1196,7 +1198,6 @@ var ObjectWrappingMap = class {
1196
1198
  [Symbol.iterator]() {
1197
1199
  return this.entries();
1198
1200
  }
1199
- // @ts-expect-error: Implementation is compatible but TS can't infer it
1200
1201
  keys() {
1201
1202
  return Object.keys(this.wrappedObject).filter((key) => this.has(key)).values();
1202
1203
  }
@@ -1210,11 +1211,25 @@ var ObjectWrappingMap = class {
1210
1211
  has(key) {
1211
1212
  return isSafeProperty(this.wrappedObject, key) && key in this.wrappedObject;
1212
1213
  }
1213
- // @ts-expect-error: Implementation is compatible but TS can't infer it
1214
+ /**
1215
+ * Return the value for `key`; when the key is absent, set it to `defaultValue` first.
1216
+ * Declared because the ESNext `Map` (TC39 upsert) has it, and `implements Map` requires it.
1217
+ */
1218
+ getOrInsert(key, defaultValue) {
1219
+ if (!this.has(key)) this.set(key, defaultValue);
1220
+ return this.get(key);
1221
+ }
1222
+ /**
1223
+ * Return the value for `key`; when the key is absent, set it to `callback(key)` first.
1224
+ * Declared because the ESNext `Map` (TC39 upsert) has it, and `implements Map` requires it.
1225
+ */
1226
+ getOrInsertComputed(key, callback) {
1227
+ if (!this.has(key)) this.set(key, callback(key));
1228
+ return this.get(key);
1229
+ }
1214
1230
  entries() {
1215
1231
  return mapIterator(this.keys(), (key) => [key, this.get(key)]);
1216
1232
  }
1217
- // @ts-expect-error: Implementation is compatible but TS can't infer it
1218
1233
  *values() {
1219
1234
  for (const key of this.keys()) {
1220
1235
  yield this.get(key);
@@ -1247,6 +1262,8 @@ var PartitionedMap = class {
1247
1262
  bKeys;
1248
1263
  [Symbol.toStringTag] = "PartitionedMap";
1249
1264
  /**
1265
+ * Create a PartitionedMap over two maps.
1266
+ *
1250
1267
  * @param a - Primary map
1251
1268
  * @param b - Secondary map
1252
1269
  * @param bKeys - Set of keys that should be read/written to map b
@@ -1274,17 +1291,30 @@ var PartitionedMap = class {
1274
1291
  has(key) {
1275
1292
  return this.b.has(key) || this.a.has(key);
1276
1293
  }
1277
- // @ts-expect-error: Implementation is compatible but TS can't infer it
1294
+ /**
1295
+ * Return the value for `key`; when the key is absent, set it to `defaultValue` first.
1296
+ * Declared because the ESNext `Map` (TC39 upsert) has it, and `implements Map` requires it.
1297
+ */
1298
+ getOrInsert(key, defaultValue) {
1299
+ if (!this.has(key)) this.set(key, defaultValue);
1300
+ return this.get(key);
1301
+ }
1302
+ /**
1303
+ * Return the value for `key`; when the key is absent, set it to `callback(key)` first.
1304
+ * Declared because the ESNext `Map` (TC39 upsert) has it, and `implements Map` requires it.
1305
+ */
1306
+ getOrInsertComputed(key, callback) {
1307
+ if (!this.has(key)) this.set(key, callback(key));
1308
+ return this.get(key);
1309
+ }
1278
1310
  keys() {
1279
1311
  return (/* @__PURE__ */ new Set([...this.a.keys(), ...this.b.keys()]))[Symbol.iterator]();
1280
1312
  }
1281
- // @ts-expect-error: Implementation is compatible but TS can't infer it
1282
1313
  *values() {
1283
1314
  for (const key of this.keys()) {
1284
1315
  yield this.get(key);
1285
1316
  }
1286
1317
  }
1287
- // @ts-expect-error: Implementation is compatible but TS can't infer it
1288
1318
  entries() {
1289
1319
  return mapIterator(this.keys(), (key) => [key, this.get(key)]);
1290
1320
  }
package/dist/is.d.ts ADDED
@@ -0,0 +1,256 @@
1
+ /**
2
+ * Shape of a BigNumber value that the duck-typing guards in this module read.
3
+ */
4
+ export interface BigNumber {
5
+ isBigNumber: boolean;
6
+ constructor: {
7
+ prototype: {
8
+ isBigNumber: boolean;
9
+ };
10
+ isDecimal?: (x: unknown) => boolean;
11
+ };
12
+ }
13
+ /**
14
+ * Shape of a complex number: real part `re` and imaginary part `im`.
15
+ */
16
+ export interface Complex {
17
+ re: number;
18
+ im: number;
19
+ }
20
+ /**
21
+ * Shape of a fraction: numerator `n` and denominator `d`.
22
+ */
23
+ export interface Fraction {
24
+ n: number;
25
+ d: number;
26
+ }
27
+ /**
28
+ * Shape of a Unit value that the duck-typing guards in this module read.
29
+ */
30
+ export interface Unit {
31
+ constructor: {
32
+ prototype: {
33
+ isUnit: boolean;
34
+ };
35
+ };
36
+ }
37
+ /**
38
+ * Shape of a Matrix value that the duck-typing guards in this module read.
39
+ */
40
+ export interface Matrix {
41
+ isMatrix?: boolean;
42
+ _size?: number[];
43
+ constructor: {
44
+ prototype: {
45
+ isMatrix: boolean;
46
+ };
47
+ };
48
+ }
49
+ /**
50
+ * Shape of a Matrix that also has the `isDenseMatrix` flag.
51
+ */
52
+ export interface DenseMatrix extends Matrix {
53
+ isDenseMatrix: boolean;
54
+ }
55
+ /**
56
+ * Shape of a Matrix that also has the `isSparseMatrix` flag.
57
+ */
58
+ export interface SparseMatrix extends Matrix {
59
+ isSparseMatrix: boolean;
60
+ }
61
+ /**
62
+ * Shape of a Range value: start, end and step.
63
+ */
64
+ export interface Range {
65
+ start: number;
66
+ end: number;
67
+ step: number;
68
+ constructor: {
69
+ prototype: {
70
+ isRange: boolean;
71
+ };
72
+ };
73
+ }
74
+ /**
75
+ * Shape of one dimension of an Index.
76
+ */
77
+ export interface IndexDimension {
78
+ _data?: unknown[];
79
+ _size: number[];
80
+ isRange?: boolean;
81
+ start?: number;
82
+ end?: number;
83
+ }
84
+ /**
85
+ * Shape of an Index value: its dimensions and the optional source size.
86
+ */
87
+ export interface Index {
88
+ _dimensions: (IndexDimension | string)[];
89
+ _sourceSize?: (number | null)[];
90
+ constructor: {
91
+ prototype: {
92
+ isIndex: boolean;
93
+ };
94
+ };
95
+ }
96
+ /**
97
+ * Test whether a value is a primitive number.
98
+ *
99
+ * @param x - The value to test.
100
+ * @returns True when `typeof x` is `'number'`.
101
+ */
102
+ export declare function isNumber(x: unknown): x is number;
103
+ /**
104
+ * Test whether a value is a BigNumber.
105
+ *
106
+ * @param x - The value to test.
107
+ * @returns True when `x` and its constructor prototype both have `isBigNumber === true`, or when `x.constructor.isDecimal(x)` returns true.
108
+ */
109
+ export declare function isBigNumber(x: unknown): x is BigNumber;
110
+ /**
111
+ * Test whether a value is a primitive bigint.
112
+ *
113
+ * @param x - The value to test.
114
+ * @returns True when `typeof x` is `'bigint'`.
115
+ */
116
+ export declare function isBigInt(x: unknown): x is bigint;
117
+ /**
118
+ * Test whether a value is a Complex number.
119
+ *
120
+ * @param x - The value to test.
121
+ * @returns True when `x` is an object whose prototype has `isComplex === true`.
122
+ */
123
+ export declare function isComplex(x: unknown): x is Complex;
124
+ /**
125
+ * Test whether a value is a Fraction.
126
+ *
127
+ * @param x - The value to test.
128
+ * @returns True when `x` is an object whose prototype has `isFraction === true`.
129
+ */
130
+ export declare function isFraction(x: unknown): x is Fraction;
131
+ /**
132
+ * Test whether a value is a Unit.
133
+ *
134
+ * @param x - The value to test.
135
+ * @returns True when the constructor prototype of `x` has `isUnit === true`.
136
+ */
137
+ export declare function isUnit(x: unknown): x is Unit;
138
+ /**
139
+ * Test whether a value is a primitive string.
140
+ *
141
+ * @param x - The value to test.
142
+ * @returns True when `typeof x` is `'string'`.
143
+ */
144
+ export declare function isString(x: unknown): x is string;
145
+ export declare const isArray: (arg: any) => arg is any[];
146
+ /**
147
+ * Test whether a value is a Matrix of any storage type.
148
+ *
149
+ * @param x - The value to test.
150
+ * @returns True when the constructor prototype of `x` has `isMatrix === true`.
151
+ */
152
+ export declare function isMatrix(x: unknown): x is Matrix;
153
+ /**
154
+ * Test whether a value is a collection: an Array or Matrix
155
+ * @param x
156
+ * @returns {boolean} isCollection
157
+ */
158
+ export declare function isCollection(x: unknown): x is unknown[] | Matrix;
159
+ /**
160
+ * Test whether a value is a DenseMatrix.
161
+ *
162
+ * @param x - The value to test.
163
+ * @returns True when `x` has `isDenseMatrix === true` and its constructor prototype has `isMatrix === true`.
164
+ */
165
+ export declare function isDenseMatrix(x: unknown): x is DenseMatrix;
166
+ /**
167
+ * Test whether a value is a SparseMatrix.
168
+ *
169
+ * @param x - The value to test.
170
+ * @returns True when `x` has `isSparseMatrix === true` and its constructor prototype has `isMatrix === true`.
171
+ */
172
+ export declare function isSparseMatrix(x: unknown): x is SparseMatrix;
173
+ /**
174
+ * Test whether a value is a Range.
175
+ *
176
+ * @param x - The value to test.
177
+ * @returns True when the constructor prototype of `x` has `isRange === true`.
178
+ */
179
+ export declare function isRange(x: unknown): x is Range;
180
+ /**
181
+ * Test whether a value is an Index.
182
+ *
183
+ * @param x - The value to test.
184
+ * @returns True when the constructor prototype of `x` has `isIndex === true`.
185
+ */
186
+ export declare function isIndex(x: unknown): x is Index;
187
+ /**
188
+ * Test whether a value is a primitive boolean.
189
+ *
190
+ * @param x - The value to test.
191
+ * @returns True when `typeof x` is `'boolean'`.
192
+ */
193
+ export declare function isBoolean(x: unknown): x is boolean;
194
+ /**
195
+ * Test whether a value is a function.
196
+ *
197
+ * @param x - The value to test.
198
+ * @returns True when `typeof x` is `'function'`.
199
+ */
200
+ export declare function isFunction(x: unknown): x is (...args: unknown[]) => unknown;
201
+ /**
202
+ * Test whether a value is a Date.
203
+ *
204
+ * @param x - The value to test.
205
+ * @returns True when `x` is an `instanceof Date`.
206
+ */
207
+ export declare function isDate(x: unknown): x is Date;
208
+ /**
209
+ * Test whether a value is a regular expression.
210
+ *
211
+ * @param x - The value to test.
212
+ * @returns True when `x` is an `instanceof RegExp`.
213
+ */
214
+ export declare function isRegExp(x: unknown): x is RegExp;
215
+ /**
216
+ * Test whether a value is a plain object.
217
+ *
218
+ * @param x - The value to test.
219
+ * @returns True when the constructor of `x` is `Object` and `x` is not a Complex or a Fraction.
220
+ */
221
+ export declare function isObject(x: unknown): x is Record<string, unknown>;
222
+ /**
223
+ * Returns `true` if the passed object appears to be a Map (i.e. duck typing).
224
+ *
225
+ * Methods looked for are `get`, `set`, `keys` and `has`.
226
+ *
227
+ * @param object
228
+ * @returns
229
+ */
230
+ export declare function isMap(object: unknown): object is Map<unknown, unknown>;
231
+ /**
232
+ * Test whether a value is null.
233
+ *
234
+ * @param x - The value to test.
235
+ * @returns True when `x === null`.
236
+ */
237
+ export declare function isNull(x: unknown): x is null;
238
+ /**
239
+ * Test whether a value is undefined.
240
+ *
241
+ * @param x - The value to test.
242
+ * @returns True when `x === undefined`.
243
+ */
244
+ export declare function isUndefined(x: unknown): x is undefined;
245
+ /**
246
+ * Get the type name of a value.
247
+ *
248
+ * For an object, the result is `'null'`, `'BigNumber'`, `'Complex'`, `'Fraction'`,
249
+ * the constructor name, or `'Object'`, in that order of test.
250
+ * For other values, the result is the `typeof` string.
251
+ *
252
+ * @param x - The value to examine.
253
+ * @returns The type name.
254
+ */
255
+ export declare function typeOf(x: unknown): string;
256
+ //# sourceMappingURL=is.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"is.d.ts","sourceRoot":"","sources":["../src/is.ts"],"names":[],"mappings":"AAeA;;GAEG;AACH,MAAM,WAAW,SAAS;IACxB,WAAW,EAAE,OAAO,CAAC;IACrB,WAAW,EAAE;QACX,SAAS,EAAE;YAAE,WAAW,EAAE,OAAO,CAAA;SAAE,CAAC;QACpC,SAAS,CAAC,EAAE,CAAC,CAAC,EAAE,OAAO,KAAK,OAAO,CAAC;KACrC,CAAC;CACH;AAED;;GAEG;AACH,MAAM,WAAW,OAAO;IACtB,EAAE,EAAE,MAAM,CAAC;IACX,EAAE,EAAE,MAAM,CAAC;CACZ;AAED;;GAEG;AACH,MAAM,WAAW,QAAQ;IACvB,CAAC,EAAE,MAAM,CAAC;IACV,CAAC,EAAE,MAAM,CAAC;CACX;AAED;;GAEG;AACH,MAAM,WAAW,IAAI;IACnB,WAAW,EAAE;QACX,SAAS,EAAE;YAAE,MAAM,EAAE,OAAO,CAAA;SAAE,CAAC;KAChC,CAAC;CACH;AAED;;GAEG;AACH,MAAM,WAAW,MAAM;IACrB,QAAQ,CAAC,EAAE,OAAO,CAAC;IACnB,KAAK,CAAC,EAAE,MAAM,EAAE,CAAC;IACjB,WAAW,EAAE;QACX,SAAS,EAAE;YAAE,QAAQ,EAAE,OAAO,C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;AACH,wBAAgB,QAAQ,CAAC,CAAC,EAAE,OAAO,GAAG,CAAC,IAAI,MAAM,CAEhD;AAED;;;;;GAKG;AACH,wBAAgB,QAAQ,CAAC,CAAC,EAAE,OAAO,GAAG,CAAC,IAAI,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAQjE;AAED;;;;;;;GAOG;AACH,wBAAgB,KAAK,CAAC,MAAM,EAAE,OAAO,GAAG,MAAM,IAAI,GAAG,CAAC,OAAO,EAAE,OAAO,CAAC,CActE;AAED;;;;;GAKG;AACH,wBAAgB,MAAM,CAAC,CAAC,EAAE,OAAO,GAAG,CAAC,IAAI,IAAI,CAE5C;AAED;;;;;GAKG;AACH,wBAAgB,WAAW,CAAC,CAAC,EAAE,OAAO,GAAG,CAAC,IAAI,SAAS,CAEtD;AAED;;;;;;;;;GASG;AACH,wBAAgB,MAAM,CAAC,CAAC,EAAE,OAAO,GAAG,MAAM,CAmBzC"}
package/dist/map.d.ts ADDED
@@ -0,0 +1,147 @@
1
+ /**
2
+ * A map facade on a bare object.
3
+ *
4
+ * The small number of methods needed to implement a scope,
5
+ * forwarding on to the SafeProperty functions. Over time, the codebase
6
+ * will stop using this method, as all objects will be Maps, rather than
7
+ * more security prone objects.
8
+ */
9
+ /**
10
+ * The iterator type `Map` itself declares, derived from the installed TS lib
11
+ * rather than hard-coded: older libs say `IterableIterator<[K, V]>`, TS >= 5.6
12
+ * says `MapIterator<[K, V]>` (which additionally requires `[Symbol.dispose]`).
13
+ * Deriving it keeps `implements Map<K, V>` honest on every TS version.
14
+ */
15
+ type MapEntryIterator<K, V> = ReturnType<Map<K, V>[typeof Symbol.iterator]>;
16
+ /** The iterator type `Map.prototype.keys` declares, derived like `MapEntryIterator`. */
17
+ type MapKeyIterator<K, V> = ReturnType<Map<K, V>['keys']>;
18
+ /** The iterator type `Map.prototype.values` declares, derived like `MapEntryIterator`. */
19
+ type MapValueIterator<K, V> = ReturnType<Map<K, V>['values']>;
20
+ /** The iterator type `Map.prototype.entries` declares, derived like `MapEntryIterator`. */
21
+ type MapEntriesIterator<K, V> = ReturnType<Map<K, V>['entries']>;
22
+ /**
23
+ * A Map view of a plain object.
24
+ *
25
+ * The map does not copy the object. Reads use `getSafeProperty` and writes use
26
+ * `setSafeProperty` on the wrapped object.
27
+ */
28
+ export declare class ObjectWrappingMap<K = string, V = unknown> implements Map<K, V> {
29
+ wrappedObject: Record<string, V>;
30
+ readonly [Symbol.toStringTag]: string;
31
+ constructor(object: Record<string, V>);
32
+ /**
33
+ * Declared as a real method rather than assigned in the constructor through a
34
+ * cast. The old form satisfied the runtime but never appeared in the emitted
35
+ * type, so `implements Map<K, V>` was a lie that only surfaced downstream:
36
+ * consumers compiling with `skipLibCheck: false` got TS2420 ("incorrectly
37
+ * implements interface 'Map'... '[Symbol.iterator]' is missing").
38
+ */
39
+ [Symbol.iterator](): MapEntryIterator<K, V>;
40
+ keys(): MapKeyIterator<K, V>;
41
+ get(key: K): V | undefined;
42
+ set(key: K, value: V): this;
43
+ has(key: K): boolean;
44
+ /**
45
+ * Return the value for `key`; when the key is absent, set it to `defaultValue` first.
46
+ * Declared because the ESNext `Map` (TC39 upsert) has it, and `implements Map` requires it.
47
+ */
48
+ getOrInsert(key: K, defaultValue: V): V;
49
+ /**
50
+ * Return the value for `key`; when the key is absent, set it to `callback(key)` first.
51
+ * Declared because the ESNext `Map` (TC39 upsert) has it, and `implements Map` requires it.
52
+ */
53
+ getOrInsertComputed(key: K, callback: (key: K) => V): V;
54
+ entries(): MapEntriesIterator<K, V>;
55
+ values(): MapValueIterator<K, V>;
56
+ forEach(callback: (value: V, key: K, map: Map<K, V>) => void): void;
57
+ delete(key: K): boolean;
58
+ clear(): void;
59
+ get size(): number;
60
+ }
61
+ /**
62
+ * Create a map with two partitions: a and b.
63
+ * The set with bKeys determines which keys/values are read/written to map b,
64
+ * all other values are read/written to map a
65
+ *
66
+ * For example:
67
+ *
68
+ * const a = new Map()
69
+ * const b = new Map()
70
+ * const p = new PartitionedMap(a, b, new Set(['x', 'y']))
71
+ *
72
+ * In this case, values `x` and `y` are read/written to map `b`,
73
+ * all other values are read/written to map `a`.
74
+ */
75
+ export declare class PartitionedMap<K = unknown, V = unknown> implements Map<K, V> {
76
+ a: Map<K, V>;
77
+ b: Map<K, V>;
78
+ bKeys: Set<K>;
79
+ readonly [Symbol.toStringTag]: string;
80
+ /**
81
+ * Create a PartitionedMap over two maps.
82
+ *
83
+ * @param a - Primary map
84
+ * @param b - Secondary map
85
+ * @param bKeys - Set of keys that should be read/written to map b
86
+ */
87
+ constructor(a: Map<K, V>, b: Map<K, V>, bKeys: Set<K>);
88
+ /** See the note on `ObjectWrappingMap[Symbol.iterator]` — same fix. */
89
+ [Symbol.iterator](): MapEntryIterator<K, V>;
90
+ get(key: K): V | undefined;
91
+ set(key: K, value: V): this;
92
+ has(key: K): boolean;
93
+ /**
94
+ * Return the value for `key`; when the key is absent, set it to `defaultValue` first.
95
+ * Declared because the ESNext `Map` (TC39 upsert) has it, and `implements Map` requires it.
96
+ */
97
+ getOrInsert(key: K, defaultValue: V): V;
98
+ /**
99
+ * Return the value for `key`; when the key is absent, set it to `callback(key)` first.
100
+ * Declared because the ESNext `Map` (TC39 upsert) has it, and `implements Map` requires it.
101
+ */
102
+ getOrInsertComputed(key: K, callback: (key: K) => V): V;
103
+ keys(): MapKeyIterator<K, V>;
104
+ values(): MapValueIterator<K, V>;
105
+ entries(): MapEntriesIterator<K, V>;
106
+ forEach(callback: (value: V, key: K, map: Map<K, V>) => void): void;
107
+ delete(key: K): boolean;
108
+ clear(): void;
109
+ get size(): number;
110
+ }
111
+ /**
112
+ * Creates an empty map, or whatever your platform's polyfill is.
113
+ *
114
+ * @returns an empty Map or Map like object.
115
+ */
116
+ export declare function createEmptyMap<K = string, V = unknown>(): Map<K, V>;
117
+ /**
118
+ * Creates a Map from the given object.
119
+ *
120
+ * @param mapOrObject - Map or object to convert
121
+ * @returns Map instance
122
+ */
123
+ export declare function createMap<K = string, V = unknown>(mapOrObject?: Map<K, V> | Record<string, V> | null): Map<K, V>;
124
+ /**
125
+ * Unwraps a map into an object.
126
+ *
127
+ * @param map - Map to convert to object
128
+ * @returns Plain object
129
+ */
130
+ export declare function toObject<V = unknown>(map: Map<unknown, V>): Record<string, V>;
131
+ /**
132
+ * Copies the contents of key-value pairs from each `objects` in to `map`.
133
+ *
134
+ * Object is `objects` can be a `Map` or object.
135
+ *
136
+ * This is the `Map` analog to `Object.assign`.
137
+ */
138
+ export declare function assign<K = unknown, V = unknown>(map: Map<K, V>, ...objects: (Map<K, V> | Record<string, V> | null | undefined)[]): Map<K, V>;
139
+ /**
140
+ * Returns `true` if `object` is an {@link ObjectWrappingMap}.
141
+ *
142
+ * Defined here, next to the class it guards, so `is.ts` need not import
143
+ * `map.ts` — that import was the sole edge closing the `is`/`map` cycle.
144
+ */
145
+ export declare function isObjectWrappingMap(object: unknown): object is ObjectWrappingMap;
146
+ export {};
147
+ //# sourceMappingURL=map.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"map.d.ts","sourceRoot":"","sources":["../src/map.ts"],"names":[],"mappings":"AAmCA;;;;;;;GAOG;AACH;;;;;GAKG;AACH,KAAK,gBAAgB,CAAC,CAAC,EAAE,CAAC,IAAI,UAAU,CAAC,GAAG,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,OAAO,MAAM,CAAC,QAAQ,CAAC,CAAC,CAAC;AAE5E,wFAAwF;AACxF,KAAK,cAAc,CAAC,CAAC,EAAE,CAAC,IAAI,UAAU,CAAC,GAAG,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC;AAE1D,0FAA0F;AAC1F,KAAK,gBAAgB,CAAC,CAAC,EAAE,CAAC,IAAI,UAAU,CAAC,GAAG,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,QAAQ,CAAC,CAAC,CAAC;AAE9D,2FAA2F;AAC3F,KAAK,kBAAkB,CAAC,CAAC,EAAE,CAAC,IAAI,UAAU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