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