@jiovan-labs/ts-multi-map 0.0.0-stage → 2.0.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.
Files changed (36) hide show
  1. package/LICENSE.txt +21 -0
  2. package/README.md +46 -2
  3. package/dist/cjs/index.d.ts +7 -0
  4. package/dist/cjs/index.js +47 -0
  5. package/dist/cjs/type/declaration.d.ts +10 -0
  6. package/dist/cjs/type/declaration.js +17 -0
  7. package/dist/cjs/util/MultiKeyMap.d.ts +34 -0
  8. package/dist/cjs/util/MultiKeyMap.js +530 -0
  9. package/dist/cjs/util/MultiValueMap.d.ts +35 -0
  10. package/dist/cjs/util/MultiValueMap.js +527 -0
  11. package/dist/cjs/util/RangeMap.d.ts +36 -0
  12. package/dist/cjs/util/RangeMap.js +584 -0
  13. package/dist/cjs/util/ReadonlyMultiKeyMap.d.ts +27 -0
  14. package/dist/cjs/util/ReadonlyMultiKeyMap.js +364 -0
  15. package/dist/cjs/util/ReadonlyMultiValueMap.d.ts +27 -0
  16. package/dist/cjs/util/ReadonlyMultiValueMap.js +365 -0
  17. package/dist/cjs/util/ReadonlyRangeMap.d.ts +27 -0
  18. package/dist/cjs/util/ReadonlyRangeMap.js +376 -0
  19. package/dist/esm/index.d.ts +7 -0
  20. package/dist/esm/index.js +7 -0
  21. package/dist/esm/type/declaration.d.ts +10 -0
  22. package/dist/esm/type/declaration.js +1 -0
  23. package/dist/esm/util/MultiKeyMap.d.ts +34 -0
  24. package/dist/esm/util/MultiKeyMap.js +318 -0
  25. package/dist/esm/util/MultiValueMap.d.ts +35 -0
  26. package/dist/esm/util/MultiValueMap.js +328 -0
  27. package/dist/esm/util/RangeMap.d.ts +36 -0
  28. package/dist/esm/util/RangeMap.js +358 -0
  29. package/dist/esm/util/ReadonlyMultiKeyMap.d.ts +27 -0
  30. package/dist/esm/util/ReadonlyMultiKeyMap.js +136 -0
  31. package/dist/esm/util/ReadonlyMultiValueMap.d.ts +27 -0
  32. package/dist/esm/util/ReadonlyMultiValueMap.js +136 -0
  33. package/dist/esm/util/ReadonlyRangeMap.d.ts +27 -0
  34. package/dist/esm/util/ReadonlyRangeMap.js +135 -0
  35. package/dist/umd/ts-multi-map.min.js +1 -0
  36. package/package.json +111 -5
@@ -0,0 +1,376 @@
1
+ var __defProp = Object.defineProperty;
2
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
3
+ var __getOwnPropNames = Object.getOwnPropertyNames;
4
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
5
+ var __export = (target, all) => {
6
+ for (var name in all)
7
+ __defProp(target, name, { get: all[name], enumerable: true });
8
+ };
9
+ var __copyProps = (to, from, except, desc) => {
10
+ if (from && typeof from === "object" || typeof from === "function") {
11
+ for (let key of __getOwnPropNames(from))
12
+ if (!__hasOwnProp.call(to, key) && key !== except)
13
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
14
+ }
15
+ return to;
16
+ };
17
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
18
+
19
+ // src/util/ReadonlyRangeMap.ts
20
+ var ReadonlyRangeMap_exports = {};
21
+ __export(ReadonlyRangeMap_exports, {
22
+ ReadonlyRangeMap: () => ReadonlyRangeMap
23
+ });
24
+ module.exports = __toCommonJS(ReadonlyRangeMap_exports);
25
+ var import__ = require("..");
26
+ var ReadonlyRangeMap = class {
27
+ /**
28
+ * Construct a readonly range map instance
29
+ *
30
+ * @param entries the map entries
31
+ * @param validation whether to compare the ranges to all the ranges previously, to determine if there are any conflicts
32
+ *
33
+ * @example
34
+ * ```ts
35
+ * const map = new ReadonlyRangeMap([
36
+ * [[1, 30], 'green'],
37
+ * [[30, 60], 'blue'],
38
+ * [[60, 90], 'orange'],
39
+ * [[90, 100, true, true], 'red']
40
+ * ]);
41
+ * ```
42
+ */
43
+ constructor(entries, validation = true) {
44
+ this.map = new import__.RangeMap();
45
+ entries == null ? void 0 : entries.forEach((entry) => {
46
+ const [k, v] = entry;
47
+ this.map.set(k, v, validation);
48
+ });
49
+ }
50
+ /**
51
+ * Construct a readonly range map instance
52
+ *
53
+ * @param entries the map entries
54
+ * @param validation whether to compare the ranges to all the ranges previously, to determine if there are any conflicts
55
+ *
56
+ * @returns a readonly multi value map instance
57
+ *
58
+ * @example
59
+ * ```ts
60
+ * const map = ReadonlyRangeMap.of([
61
+ * [[1, 30], 'green'],
62
+ * [[30, 60], 'blue'],
63
+ * [[60, 90], 'orange'],
64
+ * [[90, 100, true, true], 'red']
65
+ * ]);
66
+ * ```
67
+ */
68
+ static of(entries, validation = true) {
69
+ return new ReadonlyRangeMap(entries, validation);
70
+ }
71
+ /**
72
+ * Returns the value of the given key
73
+ *
74
+ * @param key the key to retrieve
75
+ * @param defaults the default value if not found
76
+ *
77
+ * @returns the value of the given key
78
+ *
79
+ * @example
80
+ * ```ts
81
+ * const map = ReadonlyRangeMap.of([
82
+ * [[1, 50, true, true], 'white'],
83
+ * [[51, 100, false, true], 'black']
84
+ * ]);
85
+ * map.get([1, 50, true, true]); // 'white'
86
+ * map.get([51, 100, false, true]); // 'black'
87
+ * ```
88
+ */
89
+ get(key, defaults) {
90
+ return this.map.get(key, defaults);
91
+ }
92
+ /**
93
+ * Returns the value that associated to the number, by determining which bound contains the given number
94
+ *
95
+ * @param digit the number to retrieve
96
+ * @param defaults the default value if not found
97
+ *
98
+ * @returns the value that associated to the number, by determining which bound contains the given number
99
+ *
100
+ * @example
101
+ * ```ts
102
+ * const map = ReadonlyRangeMap.of([
103
+ * [[1, 50, true, true], 'white'],
104
+ * [[51, 100, false, true], 'black']
105
+ * ]);
106
+ * map.get(25); // 'white'
107
+ * map.get(200); // undefined
108
+ * ```
109
+ */
110
+ getByDigit(digit, defaults) {
111
+ return this.map.getByDigit(digit, defaults);
112
+ }
113
+ /**
114
+ * Returns the keys of the map
115
+ *
116
+ * @returns the keys of the map
117
+ */
118
+ keys() {
119
+ return this.map.keys();
120
+ }
121
+ /**
122
+ * Returns the value array of the map
123
+ *
124
+ * @returns the value array of the map
125
+ */
126
+ values() {
127
+ return this.map.values();
128
+ }
129
+ /**
130
+ * Returns the key/value entries of the map
131
+ *
132
+ * @returns the key/value entries of the map
133
+ */
134
+ entries() {
135
+ return this.map.entries();
136
+ }
137
+ /**
138
+ * Processes each entry in the map
139
+ *
140
+ * @param callback a callback function that processes each entry
141
+ * @param thisArg any instance to retrieve 'this' reference in the callback function
142
+ *
143
+ * @example
144
+ * ```ts
145
+ * map.forEach((value, key) => {
146
+ * console.log(value);
147
+ * });
148
+ * ```
149
+ */
150
+ forEach(callback, thisArg) {
151
+ this.map.forEach(callback, thisArg);
152
+ }
153
+ /**
154
+ * Processes each entry in the map with index capability
155
+ *
156
+ * @param callback a callback function that processes each entry
157
+ * @param thisArg any instance to retrieve 'this' reference in the callback function
158
+ *
159
+ * @example
160
+ * ```ts
161
+ * map.forEachIndexing((value, key, index) => {
162
+ * console.log(index);
163
+ * });
164
+ * ```
165
+ */
166
+ forEachIndexing(callback, thisArg) {
167
+ this.map.forEachIndexing(callback, thisArg);
168
+ }
169
+ /**
170
+ * Processes each entry in the map with breakable capability
171
+ *
172
+ * @param callback a callback function that processes each entry. Returning false indicates to break the map iteration
173
+ * @param thisArg any instance to retrieve 'this' reference in the callback function
174
+ *
175
+ * @example
176
+ * ```ts
177
+ * map.forEachBreakable((value, key) => {
178
+ * return true;
179
+ * });
180
+ * ```
181
+ */
182
+ forEachBreakable(callback, thisArg) {
183
+ this.map.forEachBreakable(callback, thisArg);
184
+ }
185
+ /**
186
+ * Returns whether the map contains the given key
187
+ *
188
+ * @param key the key to check
189
+ *
190
+ * @returns whether the map contains the given key
191
+ *
192
+ * @example
193
+ * ```ts
194
+ * map.hasKey([1, 30]);
195
+ * ```
196
+ */
197
+ hasKey(key) {
198
+ return this.map.hasKey(key);
199
+ }
200
+ /**
201
+ * Returns whether the map contains the given key/value pair
202
+ *
203
+ * @param key the key to check
204
+ * @param value the value to check
205
+ *
206
+ * @returns whether the map contains the given key/value pair
207
+ *
208
+ * @example
209
+ * ```ts
210
+ * const map = ReadonlyRangeMap.of([
211
+ * [[1, 50], 'white']
212
+ * ]);
213
+ * map.hasKeyValue([1, 50], 'white'); // true
214
+ * map.hasKeyValue([1, 50], 'black'); // false
215
+ * ```
216
+ */
217
+ hasKeyValue(key, value) {
218
+ return this.map.hasKeyValue(key, value);
219
+ }
220
+ /**
221
+ * Returns whether the map contains any of the given keys
222
+ *
223
+ * @param keys the keys to check
224
+ *
225
+ * @returns whether the map contains any of the given keys
226
+ *
227
+ * @example
228
+ * ```ts
229
+ * const map = ReadonlyRangeMap.of([
230
+ * [[1, 50, true, true], 'white'],
231
+ * [[51, 100, false, true], 'black']
232
+ * ]);
233
+ * map.hasAnyKeys([[1, 50, true, true], [20, 60]]); // true
234
+ * ```
235
+ */
236
+ hasAnyKeys(keys) {
237
+ return this.map.hasAnyKeys(keys);
238
+ }
239
+ /**
240
+ * Returns whether the map contains all the given keys
241
+ *
242
+ * @param keys the keys to check
243
+ *
244
+ * @returns whether the map contains all the given keys
245
+ *
246
+ * @example
247
+ * ```ts
248
+ * map.hasAllKeys([[1, 50], [51, 100]]);
249
+ * ```
250
+ */
251
+ hasAllKeys(keys) {
252
+ return this.map.hasAllKeys(keys);
253
+ }
254
+ /**
255
+ * Returns whether any entries of the map that contains the given values
256
+ *
257
+ * @param value the value to check
258
+ *
259
+ * @returns whether any entries of the map that contains the given values
260
+ *
261
+ * @example
262
+ * ```ts
263
+ * const map = ReadonlyRangeMap.of([
264
+ * [[1, 50, true, true], 'white'],
265
+ * [[51, 100, false, true], 'black']
266
+ * ]);
267
+ * map.hasValue('white'); // true
268
+ * map.hasValue('blue'); // false
269
+ * ```
270
+ */
271
+ hasValue(value) {
272
+ return this.map.hasValue(value);
273
+ }
274
+ /**
275
+ * Returns whether the map contains any of the given values
276
+ *
277
+ * @param values the values to check
278
+ *
279
+ * @returns whether the map contains any of the given values
280
+ *
281
+ * @example
282
+ * ```ts
283
+ * const map = ReadonlyRangeMap.of([
284
+ * [[1, 50, true, true], 'white'],
285
+ * [[51, 100, false, true], 'black']
286
+ * ]);
287
+ * map.hasAnyValues(['red', 'black']); // true
288
+ * map.hasAnyValues(['top', 'right']); // false
289
+ * ```
290
+ */
291
+ hasAnyValues(values) {
292
+ return this.map.hasAnyValues(values);
293
+ }
294
+ /**
295
+ * Returns whether the map contains all the given values, matching exactly
296
+ *
297
+ * @param values the values to check
298
+ *
299
+ * @returns whether the map contains all the given values, matching exactly
300
+ *
301
+ * @example
302
+ * ```ts
303
+ * map.hasAllValues(['red', 'green', 'blue']);
304
+ * ```
305
+ */
306
+ hasAllValues(values) {
307
+ return this.map.hasAllValues(values);
308
+ }
309
+ /**
310
+ * Returns whether the map is empty
311
+ *
312
+ * @returns whether the map is empty
313
+ */
314
+ isEmpty() {
315
+ return this.map.isEmpty();
316
+ }
317
+ /**
318
+ * Returns whether the map is not empty
319
+ *
320
+ * @returns whether the map is not empty
321
+ */
322
+ isNotEmpty() {
323
+ return this.map.isNotEmpty();
324
+ }
325
+ /**
326
+ * Response for returning the list of key/value to iterate
327
+ *
328
+ * @example
329
+ * ```ts
330
+ * for (const [key, value] of map) {
331
+ * console.log(value);
332
+ * }
333
+ * ```
334
+ */
335
+ // @ts-ignore
336
+ [Symbol.iterator]() {
337
+ return this.map[Symbol.iterator]();
338
+ }
339
+ /**
340
+ * Returns the size of map
341
+ *
342
+ * @returns the size of map
343
+ */
344
+ get size() {
345
+ return this.map.size;
346
+ }
347
+ /**
348
+ * Returns the string representation of the map identifier ('ReadonlyRangeMap')
349
+ *
350
+ * @returns the string representation of the map identifier
351
+ */
352
+ get [Symbol.toStringTag]() {
353
+ return "ReadonlyRangeMap";
354
+ }
355
+ /**
356
+ * Returns the string representation of the map elements
357
+ *
358
+ * @returns the string representation of the map elements
359
+ *
360
+ * @example
361
+ * ```ts
362
+ * const map = ReadonlyRangeMap.of([
363
+ * [[1, 50, true, true], 'white'],
364
+ * [[51, 100, false, true], 'black']
365
+ * ]);
366
+ * console.log(map.toString()); // '[start:1,end:50,startInclusive:true,endInclusive:true]:white;[start:51,end:100,startInclusive:false,endInclusive:true]:black'
367
+ * ```
368
+ */
369
+ toString() {
370
+ return this.map.toString();
371
+ }
372
+ };
373
+ // Annotate the CommonJS export names for ESM import in node:
374
+ 0 && (module.exports = {
375
+ ReadonlyRangeMap
376
+ });
@@ -0,0 +1,7 @@
1
+ export { MultiKeyMap } from './util/MultiKeyMap';
2
+ export { MultiValueMap } from './util/MultiValueMap';
3
+ export { RangeMap } from './util/RangeMap';
4
+ export { ReadonlyMultiKeyMap } from './util/ReadonlyMultiKeyMap';
5
+ export { ReadonlyMultiValueMap } from './util/ReadonlyMultiValueMap';
6
+ export { ReadonlyRangeMap } from './util/ReadonlyRangeMap';
7
+ export * from './type/declaration';
@@ -0,0 +1,7 @@
1
+ export { MultiKeyMap } from "./util/MultiKeyMap";
2
+ export { MultiValueMap } from "./util/MultiValueMap";
3
+ export { RangeMap } from "./util/RangeMap";
4
+ export { ReadonlyMultiKeyMap } from "./util/ReadonlyMultiKeyMap";
5
+ export { ReadonlyMultiValueMap } from "./util/ReadonlyMultiValueMap";
6
+ export { ReadonlyRangeMap } from "./util/ReadonlyRangeMap";
7
+ export * from "./type/declaration";
@@ -0,0 +1,10 @@
1
+ export type MultiKeyMapEntry<K, V> = [K[], V];
2
+ export type MultiKeyMapEntries<K, V> = readonly (readonly [K[], V])[] | null;
3
+ export type MultiValueMapEntry<K, V> = [K, V[]];
4
+ export type MultiValueMapEntries<K, V> = readonly (readonly [K, V[]])[] | null;
5
+ export type RangeMapKey = {
6
+ start: number;
7
+ end: number;
8
+ startInclusive?: boolean;
9
+ endInclusive?: boolean;
10
+ };
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,34 @@
1
+ import { type MultiKeyMapEntries } from "..";
2
+ export declare class MultiKeyMap<K, V> implements Omit<Map<K[], V>, 'delete' | 'forEach' | 'get' | 'has' | 'set' | 'entries' | 'keys' | 'values' | 'push'> {
3
+ private readonly keyMap;
4
+ private readonly valueMap;
5
+ static of<K, V>(entries?: MultiKeyMapEntries<K, V>): MultiKeyMap<K, V>;
6
+ constructor(entries?: MultiKeyMapEntries<K, V>);
7
+ get(keys: K[], defaults?: V): V | undefined;
8
+ set(keys: K[], value: V): void;
9
+ clear(): void;
10
+ keys(): K[][];
11
+ values(): V[];
12
+ entries(): [K[], V][];
13
+ deleteByKey(key: K[]): boolean;
14
+ deleteByKeys(keys: K[][]): boolean;
15
+ deleteByValue(value: V): boolean;
16
+ deleteByValues(values: V[]): boolean;
17
+ forEach(callback: (value?: V, keys?: K[]) => void, thisArg?: any): void;
18
+ forEachIndexing(callback: (value?: V, keys?: K[], index?: number) => void, thisArg?: any): void;
19
+ forEachBreakable(callback: (value?: V, keys?: K[]) => boolean, thisArg?: any): void;
20
+ hasKey(keys: K[], exact?: boolean): boolean;
21
+ hasKeyValue(keys: K[], value: V): boolean;
22
+ hasAnyKeys(keys: K[][], exact?: boolean): boolean;
23
+ hasAllKeys(keys: K[][], exact?: boolean): boolean;
24
+ hasValue(value: V): boolean;
25
+ hasAnyValues(values: V[]): boolean;
26
+ hasAllValues(values: V[]): boolean;
27
+ isEmpty(): boolean;
28
+ isNotEmpty(): boolean;
29
+ getKey(value: V, defaults?: K[]): K[] | undefined;
30
+ [Symbol.iterator](): IterableIterator<[K[], V]>;
31
+ get size(): number;
32
+ get [Symbol.toStringTag](): string;
33
+ toString(): string;
34
+ }