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