@telperion/js-utils 3.5.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.
- package/LICENSE +21 -0
- package/README.md +621 -0
- package/array/arrayize.cjs +22 -0
- package/array/arrayize.d.ts +17 -0
- package/array/arrayize.js +21 -0
- package/array/arrayize.js.map +1 -0
- package/array/async-map.cjs +40 -0
- package/array/async-map.d.ts +34 -0
- package/array/async-map.js +39 -0
- package/array/async-map.js.map +1 -0
- package/array/compact.cjs +34 -0
- package/array/compact.d.ts +28 -0
- package/array/compact.js +33 -0
- package/array/compact.js.map +1 -0
- package/array/difference.cjs +16 -0
- package/array/difference.d.ts +45 -0
- package/array/difference.js +15 -0
- package/array/difference.js.map +1 -0
- package/array/find-by-key.cjs +35 -0
- package/array/find-by-key.d.ts +30 -0
- package/array/find-by-key.js +34 -0
- package/array/find-by-key.js.map +1 -0
- package/array/index.cjs +14 -0
- package/array/index.d.ts +11 -0
- package/array/index.js +13 -0
- package/array/index.js.map +1 -0
- package/array/intersection.cjs +16 -0
- package/array/intersection.d.ts +45 -0
- package/array/intersection.js +15 -0
- package/array/intersection.js.map +1 -0
- package/array/limit.cjs +37 -0
- package/array/limit.d.ts +29 -0
- package/array/limit.js +36 -0
- package/array/limit.js.map +1 -0
- package/array/proto/async-map.cjs +6 -0
- package/array/proto/async-map.d.ts +25 -0
- package/array/proto/async-map.js +6 -0
- package/array/proto/async-map.js.map +1 -0
- package/array/proto/compact.cjs +6 -0
- package/array/proto/compact.d.ts +15 -0
- package/array/proto/compact.js +6 -0
- package/array/proto/compact.js.map +1 -0
- package/array/proto/difference.cjs +6 -0
- package/array/proto/difference.d.ts +27 -0
- package/array/proto/difference.js +6 -0
- package/array/proto/difference.js.map +1 -0
- package/array/proto/find-by-key.cjs +6 -0
- package/array/proto/find-by-key.d.ts +25 -0
- package/array/proto/find-by-key.js +6 -0
- package/array/proto/find-by-key.js.map +1 -0
- package/array/proto/intersection.cjs +6 -0
- package/array/proto/intersection.d.ts +27 -0
- package/array/proto/intersection.js +6 -0
- package/array/proto/intersection.js.map +1 -0
- package/array/proto/limit.cjs +6 -0
- package/array/proto/limit.d.ts +24 -0
- package/array/proto/limit.js +6 -0
- package/array/proto/limit.js.map +1 -0
- package/array/proto/remove.cjs +6 -0
- package/array/proto/remove.d.ts +32 -0
- package/array/proto/remove.js +6 -0
- package/array/proto/remove.js.map +1 -0
- package/array/proto/replace.cjs +6 -0
- package/array/proto/replace.d.ts +72 -0
- package/array/proto/replace.js +6 -0
- package/array/proto/replace.js.map +1 -0
- package/array/proto/uniquify-by-key.cjs +6 -0
- package/array/proto/uniquify-by-key.d.ts +24 -0
- package/array/proto/uniquify-by-key.js +6 -0
- package/array/proto/uniquify-by-key.js.map +1 -0
- package/array/proto/uniquify.cjs +6 -0
- package/array/proto/uniquify.d.ts +23 -0
- package/array/proto/uniquify.js +6 -0
- package/array/proto/uniquify.js.map +1 -0
- package/array/remove.cjs +46 -0
- package/array/remove.d.ts +33 -0
- package/array/remove.js +45 -0
- package/array/remove.js.map +1 -0
- package/array/replace.cjs +69 -0
- package/array/replace.d.ts +139 -0
- package/array/replace.js +68 -0
- package/array/replace.js.map +1 -0
- package/array/static/arrayize.cjs +4 -0
- package/array/static/arrayize.d.ts +6 -0
- package/array/static/arrayize.js +4 -0
- package/array/static/arrayize.js.map +1 -0
- package/array/uniquify-by-key.cjs +41 -0
- package/array/uniquify-by-key.d.ts +29 -0
- package/array/uniquify-by-key.js +40 -0
- package/array/uniquify-by-key.js.map +1 -0
- package/array/uniquify.cjs +32 -0
- package/array/uniquify.d.ts +27 -0
- package/array/uniquify.js +31 -0
- package/array/uniquify.js.map +1 -0
- package/boolean/static/is-falsy.cjs +4 -0
- package/boolean/static/is-falsy.d.ts +23 -0
- package/boolean/static/is-falsy.js +4 -0
- package/boolean/static/is-falsy.js.map +1 -0
- package/boolean/static/is-truthy.cjs +4 -0
- package/boolean/static/is-truthy.d.ts +23 -0
- package/boolean/static/is-truthy.js +4 -0
- package/boolean/static/is-truthy.js.map +1 -0
- package/class/index.cjs +4 -0
- package/class/index.d.ts +1 -0
- package/class/index.js +3 -0
- package/class/index.js.map +1 -0
- package/class/mixin.cjs +60 -0
- package/class/mixin.d.ts +50 -0
- package/class/mixin.js +59 -0
- package/class/mixin.js.map +1 -0
- package/compact.cjs +39 -0
- package/compact.d.ts +2 -0
- package/compact.js +38 -0
- package/compact.js.map +1 -0
- package/function/call.cjs +6 -0
- package/function/call.d.ts +1 -0
- package/function/call.js +5 -0
- package/function/call.js.map +1 -0
- package/function/debounce.cjs +85 -0
- package/function/debounce.d.ts +44 -0
- package/function/debounce.js +82 -0
- package/function/debounce.js.map +1 -0
- package/function/defer.cjs +42 -0
- package/function/defer.d.ts +26 -0
- package/function/defer.js +41 -0
- package/function/defer.js.map +1 -0
- package/function/index.cjs +8 -0
- package/function/index.d.ts +5 -0
- package/function/index.js +7 -0
- package/function/index.js.map +1 -0
- package/function/noop.cjs +23 -0
- package/function/noop.d.ts +20 -0
- package/function/noop.js +22 -0
- package/function/noop.js.map +1 -0
- package/function/of.cjs +44 -0
- package/function/of.d.ts +31 -0
- package/function/of.js +43 -0
- package/function/of.js.map +1 -0
- package/function/proto/debounce.cjs +6 -0
- package/function/proto/debounce.d.ts +30 -0
- package/function/proto/debounce.js +6 -0
- package/function/proto/debounce.js.map +1 -0
- package/function/static/call.cjs +4 -0
- package/function/static/call.d.ts +6 -0
- package/function/static/call.js +4 -0
- package/function/static/call.js.map +1 -0
- package/function/static/defer.cjs +4 -0
- package/function/static/defer.d.ts +23 -0
- package/function/static/defer.js +4 -0
- package/function/static/defer.js.map +1 -0
- package/function/static/noop.cjs +4 -0
- package/function/static/noop.d.ts +18 -0
- package/function/static/noop.js +4 -0
- package/function/static/noop.js.map +1 -0
- package/function/static/of.cjs +4 -0
- package/function/static/of.d.ts +26 -0
- package/function/static/of.js +4 -0
- package/function/static/of.js.map +1 -0
- package/index.cjs +31 -0
- package/index.d.ts +14 -0
- package/index.js +17 -0
- package/index.js.map +1 -0
- package/is-falsy.cjs +33 -0
- package/is-falsy.d.ts +28 -0
- package/is-falsy.js +32 -0
- package/is-falsy.js.map +1 -0
- package/is-truthy.cjs +33 -0
- package/is-truthy.d.ts +28 -0
- package/is-truthy.js +32 -0
- package/is-truthy.js.map +1 -0
- package/limit.cjs +34 -0
- package/limit.d.ts +2 -0
- package/limit.js +33 -0
- package/limit.js.map +1 -0
- package/map/index.cjs +4 -0
- package/map/index.d.ts +1 -0
- package/map/index.js +3 -0
- package/map/index.js.map +1 -0
- package/map/merge.cjs +33 -0
- package/map/merge.d.ts +24 -0
- package/map/merge.js +32 -0
- package/map/merge.js.map +1 -0
- package/math/index.cjs +4 -0
- package/math/index.d.ts +1 -0
- package/math/index.js +3 -0
- package/math/index.js.map +1 -0
- package/math/min-max.cjs +29 -0
- package/math/min-max.d.ts +24 -0
- package/math/min-max.js +28 -0
- package/math/min-max.js.map +1 -0
- package/math/static/min-max.cjs +4 -0
- package/math/static/min-max.d.ts +20 -0
- package/math/static/min-max.js +4 -0
- package/math/static/min-max.js.map +1 -0
- package/object/clone.cjs +157 -0
- package/object/clone.d.ts +161 -0
- package/object/clone.js +156 -0
- package/object/clone.js.map +1 -0
- package/object/compact.cjs +49 -0
- package/object/compact.d.ts +37 -0
- package/object/compact.js +48 -0
- package/object/compact.js.map +1 -0
- package/object/deep-freeze.cjs +16 -0
- package/object/deep-freeze.d.ts +1 -0
- package/object/deep-freeze.js +15 -0
- package/object/deep-freeze.js.map +1 -0
- package/object/deepest.cjs +55 -0
- package/object/deepest.d.ts +47 -0
- package/object/deepest.js +54 -0
- package/object/deepest.js.map +1 -0
- package/object/index.cjs +7 -0
- package/object/index.d.ts +4 -0
- package/object/index.js +6 -0
- package/object/index.js.map +1 -0
- package/object/static/clone.cjs +4 -0
- package/object/static/clone.d.ts +43 -0
- package/object/static/clone.js +4 -0
- package/object/static/clone.js.map +1 -0
- package/object/static/compact.cjs +4 -0
- package/object/static/compact.d.ts +26 -0
- package/object/static/compact.js +4 -0
- package/object/static/compact.js.map +1 -0
- package/object/static/deep-freeze.cjs +4 -0
- package/object/static/deep-freeze.d.ts +6 -0
- package/object/static/deep-freeze.js +4 -0
- package/object/static/deep-freeze.js.map +1 -0
- package/object/static/deepest.cjs +4 -0
- package/object/static/deepest.d.ts +32 -0
- package/object/static/deepest.js +4 -0
- package/object/static/deepest.js.map +1 -0
- package/open-promise.cjs +115 -0
- package/open-promise.d.ts +80 -0
- package/open-promise.js +113 -0
- package/open-promise.js.map +1 -0
- package/package.json +667 -0
- package/promise/chain.cjs +12 -0
- package/promise/chain.d.ts +7 -0
- package/promise/chain.js +11 -0
- package/promise/chain.js.map +1 -0
- package/promise/index.cjs +10 -0
- package/promise/index.d.ts +7 -0
- package/promise/index.js +9 -0
- package/promise/index.js.map +1 -0
- package/promise/never.cjs +41 -0
- package/promise/never.d.ts +34 -0
- package/promise/never.js +39 -0
- package/promise/never.js.map +1 -0
- package/promise/promisify.cjs +12 -0
- package/promise/promisify.d.ts +7 -0
- package/promise/promisify.js +11 -0
- package/promise/promisify.js.map +1 -0
- package/promise/proto/revert.cjs +6 -0
- package/promise/proto/revert.d.ts +29 -0
- package/promise/proto/revert.js +6 -0
- package/promise/proto/revert.js.map +1 -0
- package/promise/proto/try-catch.cjs +7 -0
- package/promise/proto/try-catch.d.ts +30 -0
- package/promise/proto/try-catch.js +7 -0
- package/promise/proto/try-catch.js.map +1 -0
- package/promise/revert.cjs +43 -0
- package/promise/revert.d.ts +38 -0
- package/promise/revert.js +42 -0
- package/promise/revert.js.map +1 -0
- package/promise/static/chain.cjs +4 -0
- package/promise/static/chain.d.ts +10 -0
- package/promise/static/chain.js +4 -0
- package/promise/static/chain.js.map +1 -0
- package/promise/static/never.cjs +5 -0
- package/promise/static/never.d.ts +39 -0
- package/promise/static/never.js +5 -0
- package/promise/static/never.js.map +1 -0
- package/promise/static/timeout.cjs +4 -0
- package/promise/static/timeout.d.ts +21 -0
- package/promise/static/timeout.js +4 -0
- package/promise/static/timeout.js.map +1 -0
- package/promise/static/try-one-by-one.cjs +4 -0
- package/promise/static/try-one-by-one.d.ts +27 -0
- package/promise/static/try-one-by-one.js +4 -0
- package/promise/static/try-one-by-one.js.map +1 -0
- package/promise/timeout.cjs +104 -0
- package/promise/timeout.d.ts +109 -0
- package/promise/timeout.js +103 -0
- package/promise/timeout.js.map +1 -0
- package/promise/try-catch.cjs +12 -0
- package/promise/try-catch.d.ts +45 -0
- package/promise/try-catch.js +11 -0
- package/promise/try-catch.js.map +1 -0
- package/promise/try-one-by-one.cjs +59 -0
- package/promise/try-one-by-one.d.ts +42 -0
- package/promise/try-one-by-one.js +58 -0
- package/promise/try-one-by-one.js.map +1 -0
- package/set/proto/difference.cjs +6 -0
- package/set/proto/difference.d.ts +26 -0
- package/set/proto/difference.js +6 -0
- package/set/proto/difference.js.map +1 -0
- package/set/proto/intersection.cjs +6 -0
- package/set/proto/intersection.d.ts +26 -0
- package/set/proto/intersection.js +6 -0
- package/set/proto/intersection.js.map +1 -0
- package/smart-map.cjs +108 -0
- package/smart-map.d.ts +81 -0
- package/smart-map.js +106 -0
- package/smart-map.js.map +1 -0
- package/string/index.cjs +4 -0
- package/string/index.d.ts +1 -0
- package/string/index.js +3 -0
- package/string/index.js.map +1 -0
- package/string/limit.cjs +35 -0
- package/string/limit.d.ts +29 -0
- package/string/limit.js +34 -0
- package/string/limit.js.map +1 -0
- package/string/proto/limit.cjs +6 -0
- package/string/proto/limit.d.ts +30 -0
- package/string/proto/limit.js +6 -0
- package/string/proto/limit.js.map +1 -0
- package/time/days.cjs +21 -0
- package/time/days.d.ts +15 -0
- package/time/days.js +20 -0
- package/time/days.js.map +1 -0
- package/time/hours.cjs +21 -0
- package/time/hours.d.ts +15 -0
- package/time/hours.js +20 -0
- package/time/hours.js.map +1 -0
- package/time/index.cjs +10 -0
- package/time/index.d.ts +7 -0
- package/time/index.js +9 -0
- package/time/index.js.map +1 -0
- package/time/minutes.cjs +21 -0
- package/time/minutes.d.ts +15 -0
- package/time/minutes.js +20 -0
- package/time/minutes.js.map +1 -0
- package/time/months.cjs +21 -0
- package/time/months.d.ts +15 -0
- package/time/months.js +20 -0
- package/time/months.js.map +1 -0
- package/time/seconds.cjs +20 -0
- package/time/seconds.d.ts +15 -0
- package/time/seconds.js +19 -0
- package/time/seconds.js.map +1 -0
- package/time/weeks.cjs +21 -0
- package/time/weeks.d.ts +15 -0
- package/time/weeks.js +20 -0
- package/time/weeks.js.map +1 -0
- package/time/years.cjs +21 -0
- package/time/years.d.ts +15 -0
- package/time/years.js +20 -0
- package/time/years.js.map +1 -0
- package/unique-id.cjs +24 -0
- package/unique-id.d.ts +21 -0
- package/unique-id.js +23 -0
- package/unique-id.js.map +1 -0
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../../../libs/js-utils/src/set/proto/intersection.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAa,MAAM,wCAAwC,CAAC;AA4BjF,GAAG,CAAC,SAAS,CAAC,eAAe,GAAG,UAA0B,SAAoB,EAAE,SAAS,GAAG,IAAI;IAC9F,OAAO,YAAY,CAAC,IAAI,EAAE,SAAS,EAAE,SAAS,CAAC,CAAC;AAClD,CAAC,CAAC","file":"intersection.js","sourcesContent":["import { intersection, Inclusion } from '@telperion/js-utils/array/intersection';\n\ndeclare global {\n export interface Set<T> {\n /**\n * #### Intersection\n *\n * Gets the intersection of the two arrays or sets\n *\n * * * *\n * Example:\n * ```typescript\n * import \"@telperion/js-utils/set/proto/intersection\";\n *\n * const base = new Set([\"a\", \"b\", \"c\", \"d\"]);\n *\n * base.getIntersection([\"a\", \"b\"]); // Set([\"a\", \"b\"])\n * ```\n * * * *\n * @param base Base Set\n * @param inclusion Set or Array to include its values\n * @param allEquals By default all the same items encountered in the inclusion will be included, set this argument as false to get real intersection\n * @returns Intersection of base and inclusion\n */\n getIntersection(inclusion: Inclusion, allEquals?: boolean): Set<T>;\n }\n}\n\nSet.prototype.getIntersection = function<T>(this: Set<T>, inclusion: Inclusion, allEquals = true) {\n return intersection(this, inclusion, allEquals);\n};\n"]}
|
package/smart-map.cjs
ADDED
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/* eslint-disable @typescript-eslint/no-explicit-any */
|
|
3
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
|
+
exports.SmartMap = void 0;
|
|
5
|
+
// Symbols to protect overriding private methods & properties of SmartMap Class
|
|
6
|
+
const KEY__WEAKMAP = Symbol('SmartMap.weakMap');
|
|
7
|
+
/**
|
|
8
|
+
* ### SmartMap
|
|
9
|
+
*
|
|
10
|
+
* Like WeakMap but can also store values using primitive keys
|
|
11
|
+
*
|
|
12
|
+
* * * *
|
|
13
|
+
* Example usage:
|
|
14
|
+
* ```typescript
|
|
15
|
+
* import { SmartMap } from "@telperion/js-utils";
|
|
16
|
+
*
|
|
17
|
+
* const aMap = new SmartMap();
|
|
18
|
+
*
|
|
19
|
+
* aMap.set("foo", "foo");
|
|
20
|
+
* aMap.set(1, "thales rocks");
|
|
21
|
+
*
|
|
22
|
+
* console.log(aMap.size) // 2
|
|
23
|
+
*
|
|
24
|
+
* aMap.set({}, "thales rocks again");
|
|
25
|
+
* console.log(aMap.size) // 2
|
|
26
|
+
*
|
|
27
|
+
* const anObject = {};
|
|
28
|
+
* aMap.set(anObject, "thales rocks again and again");
|
|
29
|
+
* console.log(aMap.size) // 3
|
|
30
|
+
* console.log(aMap.get(anObject)) // "thales rocks again and again"
|
|
31
|
+
* ```
|
|
32
|
+
* * * *
|
|
33
|
+
* @template K Typeof Key
|
|
34
|
+
* @template V Typeof Value
|
|
35
|
+
*/
|
|
36
|
+
class SmartMap extends Map {
|
|
37
|
+
/**
|
|
38
|
+
* Symbol refference of weakmap property
|
|
39
|
+
*/
|
|
40
|
+
static KEY__WEAKMAP = KEY__WEAKMAP;
|
|
41
|
+
/**
|
|
42
|
+
* Allowed key types to store them in a weakmap instance
|
|
43
|
+
*/
|
|
44
|
+
static TYPES_TO_STORE_IN_WEAKMAP = Object.freeze(['object', 'function']);
|
|
45
|
+
/**
|
|
46
|
+
* Returns a boolean whether if the key is storable in weakmap or not
|
|
47
|
+
*
|
|
48
|
+
* @param key Key to check if it can be stored in weakmap
|
|
49
|
+
* @returns A boolean whether if the key is storable in weakmap or not
|
|
50
|
+
*/
|
|
51
|
+
static isStorableInWeakMap(key) {
|
|
52
|
+
return key !== null && SmartMap.TYPES_TO_STORE_IN_WEAKMAP.some(_key => typeof key === _key);
|
|
53
|
+
}
|
|
54
|
+
/**
|
|
55
|
+
* The WeakMap object to store values with associated non-primitive (object) keys
|
|
56
|
+
*/
|
|
57
|
+
[KEY__WEAKMAP] = new WeakMap();
|
|
58
|
+
/**
|
|
59
|
+
* Returns a boolean asserting whether a value has been associated to the key in the SmartMap object or not.
|
|
60
|
+
*
|
|
61
|
+
* @param key The key of the element to test for presence in the SmartMap object.
|
|
62
|
+
* @returns A boolean asserting whether a value has been associated to the key in the SmartMap object or not.
|
|
63
|
+
*/
|
|
64
|
+
has(key) {
|
|
65
|
+
if (SmartMap.isStorableInWeakMap(key)) {
|
|
66
|
+
return this[KEY__WEAKMAP].has(key);
|
|
67
|
+
}
|
|
68
|
+
return super.has(key);
|
|
69
|
+
}
|
|
70
|
+
/**
|
|
71
|
+
* Returns the value associated to the key, or undefined if there is none.
|
|
72
|
+
*
|
|
73
|
+
* @param key The key of the element to return from the SmartMap object.
|
|
74
|
+
* @returns The value associated to the key
|
|
75
|
+
*/
|
|
76
|
+
get(key) {
|
|
77
|
+
if (SmartMap.isStorableInWeakMap(key)) {
|
|
78
|
+
return this[KEY__WEAKMAP].get(key);
|
|
79
|
+
}
|
|
80
|
+
return super.get(key);
|
|
81
|
+
}
|
|
82
|
+
/**
|
|
83
|
+
* Sets the value for the key in the SmartMap object.
|
|
84
|
+
*
|
|
85
|
+
* @param key The key of the element to add to the SmartMap object.
|
|
86
|
+
* @param value The value of the element to add to the SmartMap object.
|
|
87
|
+
* @returns Returns the SmartMap object.
|
|
88
|
+
*/
|
|
89
|
+
set(key, value) {
|
|
90
|
+
if (SmartMap.isStorableInWeakMap(key)) {
|
|
91
|
+
this[KEY__WEAKMAP].set(key, value);
|
|
92
|
+
}
|
|
93
|
+
else {
|
|
94
|
+
super.set(key, value);
|
|
95
|
+
}
|
|
96
|
+
return this;
|
|
97
|
+
}
|
|
98
|
+
/**
|
|
99
|
+
* Removes the associated value from the SmartMap object,
|
|
100
|
+
*
|
|
101
|
+
* @param key The key of the element to remove from the SmartMap object.
|
|
102
|
+
* @returns `true` if an element in the SmartMap object existed and has been removed, or `false` if the element does not exist. `SmartMap.prototype.has(key)` will return false afterwards.
|
|
103
|
+
*/
|
|
104
|
+
delete(key) {
|
|
105
|
+
return this[KEY__WEAKMAP].delete(key) || super.delete(key);
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
exports.SmartMap = SmartMap;
|
package/smart-map.d.ts
ADDED
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
declare const KEY__WEAKMAP: unique symbol;
|
|
2
|
+
/**
|
|
3
|
+
* ### SmartMap
|
|
4
|
+
*
|
|
5
|
+
* Like WeakMap but can also store values using primitive keys
|
|
6
|
+
*
|
|
7
|
+
* * * *
|
|
8
|
+
* Example usage:
|
|
9
|
+
* ```typescript
|
|
10
|
+
* import { SmartMap } from "@telperion/js-utils";
|
|
11
|
+
*
|
|
12
|
+
* const aMap = new SmartMap();
|
|
13
|
+
*
|
|
14
|
+
* aMap.set("foo", "foo");
|
|
15
|
+
* aMap.set(1, "thales rocks");
|
|
16
|
+
*
|
|
17
|
+
* console.log(aMap.size) // 2
|
|
18
|
+
*
|
|
19
|
+
* aMap.set({}, "thales rocks again");
|
|
20
|
+
* console.log(aMap.size) // 2
|
|
21
|
+
*
|
|
22
|
+
* const anObject = {};
|
|
23
|
+
* aMap.set(anObject, "thales rocks again and again");
|
|
24
|
+
* console.log(aMap.size) // 3
|
|
25
|
+
* console.log(aMap.get(anObject)) // "thales rocks again and again"
|
|
26
|
+
* ```
|
|
27
|
+
* * * *
|
|
28
|
+
* @template K Typeof Key
|
|
29
|
+
* @template V Typeof Value
|
|
30
|
+
*/
|
|
31
|
+
export declare class SmartMap<K = any, V = any> extends Map<K, V> {
|
|
32
|
+
/**
|
|
33
|
+
* Symbol refference of weakmap property
|
|
34
|
+
*/
|
|
35
|
+
protected static readonly KEY__WEAKMAP: symbol;
|
|
36
|
+
/**
|
|
37
|
+
* Allowed key types to store them in a weakmap instance
|
|
38
|
+
*/
|
|
39
|
+
static readonly TYPES_TO_STORE_IN_WEAKMAP: readonly string[];
|
|
40
|
+
/**
|
|
41
|
+
* Returns a boolean whether if the key is storable in weakmap or not
|
|
42
|
+
*
|
|
43
|
+
* @param key Key to check if it can be stored in weakmap
|
|
44
|
+
* @returns A boolean whether if the key is storable in weakmap or not
|
|
45
|
+
*/
|
|
46
|
+
protected static isStorableInWeakMap<Key>(key: Key): boolean;
|
|
47
|
+
/**
|
|
48
|
+
* The WeakMap object to store values with associated non-primitive (object) keys
|
|
49
|
+
*/
|
|
50
|
+
protected [KEY__WEAKMAP]: WeakMap<NonNullable<K>, V>;
|
|
51
|
+
/**
|
|
52
|
+
* Returns a boolean asserting whether a value has been associated to the key in the SmartMap object or not.
|
|
53
|
+
*
|
|
54
|
+
* @param key The key of the element to test for presence in the SmartMap object.
|
|
55
|
+
* @returns A boolean asserting whether a value has been associated to the key in the SmartMap object or not.
|
|
56
|
+
*/
|
|
57
|
+
has(key: K): boolean;
|
|
58
|
+
/**
|
|
59
|
+
* Returns the value associated to the key, or undefined if there is none.
|
|
60
|
+
*
|
|
61
|
+
* @param key The key of the element to return from the SmartMap object.
|
|
62
|
+
* @returns The value associated to the key
|
|
63
|
+
*/
|
|
64
|
+
get(key: K): V | undefined;
|
|
65
|
+
/**
|
|
66
|
+
* Sets the value for the key in the SmartMap object.
|
|
67
|
+
*
|
|
68
|
+
* @param key The key of the element to add to the SmartMap object.
|
|
69
|
+
* @param value The value of the element to add to the SmartMap object.
|
|
70
|
+
* @returns Returns the SmartMap object.
|
|
71
|
+
*/
|
|
72
|
+
set(key: K, value: V): this;
|
|
73
|
+
/**
|
|
74
|
+
* Removes the associated value from the SmartMap object,
|
|
75
|
+
*
|
|
76
|
+
* @param key The key of the element to remove from the SmartMap object.
|
|
77
|
+
* @returns `true` if an element in the SmartMap object existed and has been removed, or `false` if the element does not exist. `SmartMap.prototype.has(key)` will return false afterwards.
|
|
78
|
+
*/
|
|
79
|
+
delete(key: K): boolean;
|
|
80
|
+
}
|
|
81
|
+
export {};
|
package/smart-map.js
ADDED
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
/* eslint-disable @typescript-eslint/no-explicit-any */
|
|
2
|
+
// Symbols to protect overriding private methods & properties of SmartMap Class
|
|
3
|
+
const KEY__WEAKMAP = Symbol('SmartMap.weakMap');
|
|
4
|
+
/**
|
|
5
|
+
* ### SmartMap
|
|
6
|
+
*
|
|
7
|
+
* Like WeakMap but can also store values using primitive keys
|
|
8
|
+
*
|
|
9
|
+
* * * *
|
|
10
|
+
* Example usage:
|
|
11
|
+
* ```typescript
|
|
12
|
+
* import { SmartMap } from "@telperion/js-utils";
|
|
13
|
+
*
|
|
14
|
+
* const aMap = new SmartMap();
|
|
15
|
+
*
|
|
16
|
+
* aMap.set("foo", "foo");
|
|
17
|
+
* aMap.set(1, "thales rocks");
|
|
18
|
+
*
|
|
19
|
+
* console.log(aMap.size) // 2
|
|
20
|
+
*
|
|
21
|
+
* aMap.set({}, "thales rocks again");
|
|
22
|
+
* console.log(aMap.size) // 2
|
|
23
|
+
*
|
|
24
|
+
* const anObject = {};
|
|
25
|
+
* aMap.set(anObject, "thales rocks again and again");
|
|
26
|
+
* console.log(aMap.size) // 3
|
|
27
|
+
* console.log(aMap.get(anObject)) // "thales rocks again and again"
|
|
28
|
+
* ```
|
|
29
|
+
* * * *
|
|
30
|
+
* @template K Typeof Key
|
|
31
|
+
* @template V Typeof Value
|
|
32
|
+
*/
|
|
33
|
+
export class SmartMap extends Map {
|
|
34
|
+
/**
|
|
35
|
+
* Symbol refference of weakmap property
|
|
36
|
+
*/
|
|
37
|
+
static KEY__WEAKMAP = KEY__WEAKMAP;
|
|
38
|
+
/**
|
|
39
|
+
* Allowed key types to store them in a weakmap instance
|
|
40
|
+
*/
|
|
41
|
+
static TYPES_TO_STORE_IN_WEAKMAP = Object.freeze(['object', 'function']);
|
|
42
|
+
/**
|
|
43
|
+
* Returns a boolean whether if the key is storable in weakmap or not
|
|
44
|
+
*
|
|
45
|
+
* @param key Key to check if it can be stored in weakmap
|
|
46
|
+
* @returns A boolean whether if the key is storable in weakmap or not
|
|
47
|
+
*/
|
|
48
|
+
static isStorableInWeakMap(key) {
|
|
49
|
+
return key !== null && SmartMap.TYPES_TO_STORE_IN_WEAKMAP.some(_key => typeof key === _key);
|
|
50
|
+
}
|
|
51
|
+
/**
|
|
52
|
+
* The WeakMap object to store values with associated non-primitive (object) keys
|
|
53
|
+
*/
|
|
54
|
+
[KEY__WEAKMAP] = new WeakMap();
|
|
55
|
+
/**
|
|
56
|
+
* Returns a boolean asserting whether a value has been associated to the key in the SmartMap object or not.
|
|
57
|
+
*
|
|
58
|
+
* @param key The key of the element to test for presence in the SmartMap object.
|
|
59
|
+
* @returns A boolean asserting whether a value has been associated to the key in the SmartMap object or not.
|
|
60
|
+
*/
|
|
61
|
+
has(key) {
|
|
62
|
+
if (SmartMap.isStorableInWeakMap(key)) {
|
|
63
|
+
return this[KEY__WEAKMAP].has(key);
|
|
64
|
+
}
|
|
65
|
+
return super.has(key);
|
|
66
|
+
}
|
|
67
|
+
/**
|
|
68
|
+
* Returns the value associated to the key, or undefined if there is none.
|
|
69
|
+
*
|
|
70
|
+
* @param key The key of the element to return from the SmartMap object.
|
|
71
|
+
* @returns The value associated to the key
|
|
72
|
+
*/
|
|
73
|
+
get(key) {
|
|
74
|
+
if (SmartMap.isStorableInWeakMap(key)) {
|
|
75
|
+
return this[KEY__WEAKMAP].get(key);
|
|
76
|
+
}
|
|
77
|
+
return super.get(key);
|
|
78
|
+
}
|
|
79
|
+
/**
|
|
80
|
+
* Sets the value for the key in the SmartMap object.
|
|
81
|
+
*
|
|
82
|
+
* @param key The key of the element to add to the SmartMap object.
|
|
83
|
+
* @param value The value of the element to add to the SmartMap object.
|
|
84
|
+
* @returns Returns the SmartMap object.
|
|
85
|
+
*/
|
|
86
|
+
set(key, value) {
|
|
87
|
+
if (SmartMap.isStorableInWeakMap(key)) {
|
|
88
|
+
this[KEY__WEAKMAP].set(key, value);
|
|
89
|
+
}
|
|
90
|
+
else {
|
|
91
|
+
super.set(key, value);
|
|
92
|
+
}
|
|
93
|
+
return this;
|
|
94
|
+
}
|
|
95
|
+
/**
|
|
96
|
+
* Removes the associated value from the SmartMap object,
|
|
97
|
+
*
|
|
98
|
+
* @param key The key of the element to remove from the SmartMap object.
|
|
99
|
+
* @returns `true` if an element in the SmartMap object existed and has been removed, or `false` if the element does not exist. `SmartMap.prototype.has(key)` will return false afterwards.
|
|
100
|
+
*/
|
|
101
|
+
delete(key) {
|
|
102
|
+
return this[KEY__WEAKMAP].delete(key) || super.delete(key);
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
//# sourceMappingURL=smart-map.js.map
|
package/smart-map.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../../../libs/js-utils/src/smart-map.ts"],"names":[],"mappings":"AAAA,uDAAuD;AAEvD,+EAA+E;AAC/E,MAAM,YAAY,GAAkB,MAAM,CAAC,kBAAkB,CAAC,CAAC;AAE/D;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA4BG;AACH,MAAM,OAAO,QAA2B,SAAQ,GAAS;IACvD;;OAEG;IACO,MAAM,CAAU,YAAY,GAAG,YAAY,CAAC;IAEtD;;OAEG;IACI,MAAM,CAAU,yBAAyB,GAAG,MAAM,CAAC,MAAM,CAAC,CAAC,QAAQ,EAAE,UAAU,CAAC,CAAC,CAAC;IAEzF;;;;;OAKG;IACO,MAAM,CAAC,mBAAmB,CAAM,GAAQ;QAChD,OAAO,GAAG,KAAK,IAAI,IAAI,QAAQ,CAAC,yBAAyB,CAAC,IAAI,CAAC,IAAI,CAAC,EAAE,CAAC,OAAO,GAAG,KAAK,IAAI,CAAC,CAAC;IAC9F,CAAC;IAED;;OAEG;IACO,CAAC,YAAY,CAAC,GAAG,IAAI,OAAO,EAAqB,CAAC;IAE5D;;;;;OAKG;IACM,GAAG,CAAC,GAAM;QACjB,IAAI,QAAQ,CAAC,mBAAmB,CAAC,GAAG,CAAC,EAAE,CAAC;YACtC,OAAO,IAAI,CAAC,YAAY,CAAC,CAAC,GAAG,CAAC,GAAI,CAAC,CAAC;QACtC,CAAC;QAED,OAAO,KAAK,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC;IACxB,CAAC;IAED;;;;;OAKG;IACM,GAAG,CAAC,GAAM;QACjB,IAAI,QAAQ,CAAC,mBAAmB,CAAC,GAAG,CAAC,EAAE,CAAC;YACtC,OAAO,IAAI,CAAC,YAAY,CAAC,CAAC,GAAG,CAAC,GAAqB,CAAC,CAAC;QACvD,CAAC;QAED,OAAO,KAAK,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC;IACxB,CAAC;IAED;;;;;;OAMG;IACM,GAAG,CAAC,GAAM,EAAE,KAAQ;QAC3B,IAAI,QAAQ,CAAC,mBAAmB,CAAC,GAAG,CAAC,EAAE,CAAC;YACtC,IAAI,CAAC,YAAY,CAAC,CAAC,GAAG,CAAC,GAAqB,EAAE,KAAK,CAAC,CAAC;QACvD,CAAC;aAAM,CAAC;YACN,KAAK,CAAC,GAAG,CAAC,GAAG,EAAE,KAAK,CAAC,CAAC;QACxB,CAAC;QAED,OAAO,IAAI,CAAC;IACd,CAAC;IAED;;;;;OAKG;IACM,MAAM,CAAC,GAAM;QACpB,OAAO,IAAI,CAAC,YAAY,CAAC,CAAC,MAAM,CAAC,GAAqB,CAAC,IAAI,KAAK,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC;IAC/E,CAAC","file":"smart-map.js","sourcesContent":["/* eslint-disable @typescript-eslint/no-explicit-any */\n\n// Symbols to protect overriding private methods & properties of SmartMap Class\nconst KEY__WEAKMAP: unique symbol = Symbol('SmartMap.weakMap');\n\n/**\n * ### SmartMap\n *\n * Like WeakMap but can also store values using primitive keys\n *\n * * * *\n * Example usage:\n * ```typescript\n * import { SmartMap } from \"@telperion/js-utils\";\n *\n * const aMap = new SmartMap();\n *\n * aMap.set(\"foo\", \"foo\");\n * aMap.set(1, \"thales rocks\");\n *\n * console.log(aMap.size) // 2\n *\n * aMap.set({}, \"thales rocks again\");\n * console.log(aMap.size) // 2\n *\n * const anObject = {};\n * aMap.set(anObject, \"thales rocks again and again\");\n * console.log(aMap.size) // 3\n * console.log(aMap.get(anObject)) // \"thales rocks again and again\"\n * ```\n * * * *\n * @template K Typeof Key\n * @template V Typeof Value\n */\nexport class SmartMap<K = any, V = any> extends Map<K, V> {\n /**\n * Symbol refference of weakmap property\n */\n protected static readonly KEY__WEAKMAP = KEY__WEAKMAP;\n\n /**\n * Allowed key types to store them in a weakmap instance\n */\n public static readonly TYPES_TO_STORE_IN_WEAKMAP = Object.freeze(['object', 'function']);\n\n /**\n * Returns a boolean whether if the key is storable in weakmap or not\n *\n * @param key Key to check if it can be stored in weakmap\n * @returns A boolean whether if the key is storable in weakmap or not\n */\n protected static isStorableInWeakMap<Key>(key: Key): boolean {\n return key !== null && SmartMap.TYPES_TO_STORE_IN_WEAKMAP.some(_key => typeof key === _key);\n }\n\n /**\n * The WeakMap object to store values with associated non-primitive (object) keys\n */\n protected [KEY__WEAKMAP] = new WeakMap<NonNullable<K>, V>();\n\n /**\n * Returns a boolean asserting whether a value has been associated to the key in the SmartMap object or not.\n *\n * @param key The key of the element to test for presence in the SmartMap object.\n * @returns A boolean asserting whether a value has been associated to the key in the SmartMap object or not.\n */\n override has(key: K): boolean {\n if (SmartMap.isStorableInWeakMap(key)) {\n return this[KEY__WEAKMAP].has(key!);\n }\n\n return super.has(key);\n }\n\n /**\n * Returns the value associated to the key, or undefined if there is none.\n *\n * @param key The key of the element to return from the SmartMap object.\n * @returns The value associated to the key\n */\n override get(key: K): V | undefined {\n if (SmartMap.isStorableInWeakMap(key)) {\n return this[KEY__WEAKMAP].get(key as NonNullable<K>);\n }\n\n return super.get(key);\n }\n\n /**\n * Sets the value for the key in the SmartMap object.\n *\n * @param key The key of the element to add to the SmartMap object.\n * @param value The value of the element to add to the SmartMap object.\n * @returns Returns the SmartMap object.\n */\n override set(key: K, value: V): this {\n if (SmartMap.isStorableInWeakMap(key)) {\n this[KEY__WEAKMAP].set(key as NonNullable<K>, value);\n } else {\n super.set(key, value);\n }\n\n return this;\n }\n\n /**\n * Removes the associated value from the SmartMap object,\n *\n * @param key The key of the element to remove from the SmartMap object.\n * @returns `true` if an element in the SmartMap object existed and has been removed, or `false` if the element does not exist. `SmartMap.prototype.has(key)` will return false afterwards.\n */\n override delete(key: K): boolean {\n return this[KEY__WEAKMAP].delete(key as NonNullable<K>) || super.delete(key);\n }\n}\n"]}
|
package/string/index.cjs
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from '@telperion/js-utils/string/limit';
|
package/string/index.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../../../libs/js-utils/src/string/index.ts"],"names":[],"mappings":"AAAA,cAAc,kCAAkC,CAAC","file":"index.js","sourcesContent":["export * from '@telperion/js-utils/string/limit';\n"]}
|
package/string/limit.cjs
ADDED
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.limit = limit;
|
|
4
|
+
const limit_1 = require("@telperion/js-utils/array/limit");
|
|
5
|
+
/**
|
|
6
|
+
* #### Limit
|
|
7
|
+
*
|
|
8
|
+
* Limits the string to `n` character
|
|
9
|
+
*
|
|
10
|
+
* * * *
|
|
11
|
+
* Example:
|
|
12
|
+
* ```typescript
|
|
13
|
+
* import { limit } from "@telperion/js-utils/string";
|
|
14
|
+
*
|
|
15
|
+
* const str = 'foobarbaz';
|
|
16
|
+
*
|
|
17
|
+
* limit(str, 3); // 'foo'
|
|
18
|
+
* ```
|
|
19
|
+
*
|
|
20
|
+
* Prototype Example:
|
|
21
|
+
* ```typescript
|
|
22
|
+
* import "@telperion/js-utils/string/proto/limit";
|
|
23
|
+
*
|
|
24
|
+
* const str = 'foobarbaz';
|
|
25
|
+
*
|
|
26
|
+
* str.limit(3); // 'foo'
|
|
27
|
+
* ```
|
|
28
|
+
* * * *
|
|
29
|
+
* @param str: String to limit
|
|
30
|
+
* @param count Count to limit string character size
|
|
31
|
+
* @return Limited string
|
|
32
|
+
*/
|
|
33
|
+
function limit(str, count) {
|
|
34
|
+
return (0, limit_1.limit)(str.split(''), count).join('');
|
|
35
|
+
}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* #### Limit
|
|
3
|
+
*
|
|
4
|
+
* Limits the string to `n` character
|
|
5
|
+
*
|
|
6
|
+
* * * *
|
|
7
|
+
* Example:
|
|
8
|
+
* ```typescript
|
|
9
|
+
* import { limit } from "@telperion/js-utils/string";
|
|
10
|
+
*
|
|
11
|
+
* const str = 'foobarbaz';
|
|
12
|
+
*
|
|
13
|
+
* limit(str, 3); // 'foo'
|
|
14
|
+
* ```
|
|
15
|
+
*
|
|
16
|
+
* Prototype Example:
|
|
17
|
+
* ```typescript
|
|
18
|
+
* import "@telperion/js-utils/string/proto/limit";
|
|
19
|
+
*
|
|
20
|
+
* const str = 'foobarbaz';
|
|
21
|
+
*
|
|
22
|
+
* str.limit(3); // 'foo'
|
|
23
|
+
* ```
|
|
24
|
+
* * * *
|
|
25
|
+
* @param str: String to limit
|
|
26
|
+
* @param count Count to limit string character size
|
|
27
|
+
* @return Limited string
|
|
28
|
+
*/
|
|
29
|
+
export declare function limit(str: string, count: number): string;
|
package/string/limit.js
ADDED
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { limit as arrLimit } from '@telperion/js-utils/array/limit';
|
|
2
|
+
/**
|
|
3
|
+
* #### Limit
|
|
4
|
+
*
|
|
5
|
+
* Limits the string to `n` character
|
|
6
|
+
*
|
|
7
|
+
* * * *
|
|
8
|
+
* Example:
|
|
9
|
+
* ```typescript
|
|
10
|
+
* import { limit } from "@telperion/js-utils/string";
|
|
11
|
+
*
|
|
12
|
+
* const str = 'foobarbaz';
|
|
13
|
+
*
|
|
14
|
+
* limit(str, 3); // 'foo'
|
|
15
|
+
* ```
|
|
16
|
+
*
|
|
17
|
+
* Prototype Example:
|
|
18
|
+
* ```typescript
|
|
19
|
+
* import "@telperion/js-utils/string/proto/limit";
|
|
20
|
+
*
|
|
21
|
+
* const str = 'foobarbaz';
|
|
22
|
+
*
|
|
23
|
+
* str.limit(3); // 'foo'
|
|
24
|
+
* ```
|
|
25
|
+
* * * *
|
|
26
|
+
* @param str: String to limit
|
|
27
|
+
* @param count Count to limit string character size
|
|
28
|
+
* @return Limited string
|
|
29
|
+
*/
|
|
30
|
+
export function limit(str, count) {
|
|
31
|
+
return arrLimit(str.split(''), count).join('');
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
//# sourceMappingURL=limit.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../../../libs/js-utils/src/string/limit.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,IAAI,QAAQ,EAAE,MAAM,iCAAiC,CAAC;AAEpE;;;;;;;;;;;;;;;;;;;;;;;;;;;GA2BG;AACH,MAAM,UAAU,KAAK,CAAC,GAAW,EAAE,KAAa;IAC9C,OAAO,QAAQ,CAAC,GAAG,CAAC,KAAK,CAAC,EAAE,CAAC,EAAE,KAAK,CAAC,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC;AACjD,CAAC","file":"limit.js","sourcesContent":["import { limit as arrLimit } from '@telperion/js-utils/array/limit';\n\n/**\n * #### Limit\n *\n * Limits the string to `n` character\n *\n * * * *\n * Example:\n * ```typescript\n * import { limit } from \"@telperion/js-utils/string\";\n *\n * const str = 'foobarbaz';\n *\n * limit(str, 3); // 'foo'\n * ```\n *\n * Prototype Example:\n * ```typescript\n * import \"@telperion/js-utils/string/proto/limit\";\n *\n * const str = 'foobarbaz';\n *\n * str.limit(3); // 'foo'\n * ```\n * * * *\n * @param str: String to limit\n * @param count Count to limit string character size\n * @return Limited string\n */\nexport function limit(str: string, count: number): string {\n return arrLimit(str.split(''), count).join('');\n}\n"]}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import type { Tail } from '@thalesrc/extra-ts-types';
|
|
2
|
+
import { limit } from '@telperion/js-utils/string/limit';
|
|
3
|
+
type FuncType = typeof limit;
|
|
4
|
+
type FuncArgs = Parameters<FuncType>;
|
|
5
|
+
type FuncReturn = ReturnType<FuncType>;
|
|
6
|
+
type ProtoArgs = Tail<FuncArgs>;
|
|
7
|
+
declare global {
|
|
8
|
+
export interface String {
|
|
9
|
+
/**
|
|
10
|
+
* #### Limit
|
|
11
|
+
*
|
|
12
|
+
* Limits the string to `n` character
|
|
13
|
+
*
|
|
14
|
+
* * * *
|
|
15
|
+
* Example:
|
|
16
|
+
* ```typescript
|
|
17
|
+
* import "@telperion/js-utils/string/proto/limit";
|
|
18
|
+
*
|
|
19
|
+
* const str = 'foobarbaz';
|
|
20
|
+
*
|
|
21
|
+
* str.limit(3); // 'foo'
|
|
22
|
+
* ```
|
|
23
|
+
* * * *
|
|
24
|
+
* @param count Count to limit string character size
|
|
25
|
+
* @return Limited string
|
|
26
|
+
*/
|
|
27
|
+
limit(...args: ProtoArgs): FuncReturn;
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../../../libs/js-utils/src/string/proto/limit.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,KAAK,EAAE,MAAM,kCAAkC,CAAC;AA+BzD,MAAM,CAAC,SAAS,CAAC,KAAK,GAAG,UAAwB,GAAG,IAAe;IACjE,OAAO,KAAK,CAAC,IAAI,EAAE,GAAG,IAAI,CAAC,CAAC;AAC9B,CAAC,CAAC","file":"limit.js","sourcesContent":["import type { Tail } from '@thalesrc/extra-ts-types';\n\nimport { limit } from '@telperion/js-utils/string/limit';\n\ntype FuncType = typeof limit;\ntype FuncArgs = Parameters<FuncType>;\ntype FuncReturn = ReturnType<FuncType>;\ntype ProtoArgs = Tail<FuncArgs>;\n\ndeclare global {\n export interface String {\n /**\n * #### Limit\n *\n * Limits the string to `n` character\n *\n * * * *\n * Example:\n * ```typescript\n * import \"@telperion/js-utils/string/proto/limit\";\n *\n * const str = 'foobarbaz';\n *\n * str.limit(3); // 'foo'\n * ```\n * * * *\n * @param count Count to limit string character size\n * @return Limited string\n */\n limit(...args: ProtoArgs): FuncReturn;\n }\n}\n\nString.prototype.limit = function (this: string, ...args: ProtoArgs): FuncReturn {\n return limit(this, ...args);\n};\n"]}
|
package/time/days.cjs
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.days = days;
|
|
4
|
+
const hours_1 = require("@telperion/js-utils/time/hours");
|
|
5
|
+
/**
|
|
6
|
+
* Converts days to milliseconds
|
|
7
|
+
*
|
|
8
|
+
* #### Example
|
|
9
|
+
* ```typescript
|
|
10
|
+
* import { days } from "@telperion/js-utils/time";
|
|
11
|
+
*
|
|
12
|
+
* const expiryTime = Date.now() + days(7); // 7 days from now
|
|
13
|
+
* console.log(new Date(expiryTime));
|
|
14
|
+
* ```
|
|
15
|
+
*
|
|
16
|
+
* @param value - Number of days
|
|
17
|
+
* @returns Equivalent value in milliseconds
|
|
18
|
+
*/
|
|
19
|
+
function days(value) {
|
|
20
|
+
return (0, hours_1.hours)(value) * 24;
|
|
21
|
+
}
|
package/time/days.d.ts
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Converts days to milliseconds
|
|
3
|
+
*
|
|
4
|
+
* #### Example
|
|
5
|
+
* ```typescript
|
|
6
|
+
* import { days } from "@telperion/js-utils/time";
|
|
7
|
+
*
|
|
8
|
+
* const expiryTime = Date.now() + days(7); // 7 days from now
|
|
9
|
+
* console.log(new Date(expiryTime));
|
|
10
|
+
* ```
|
|
11
|
+
*
|
|
12
|
+
* @param value - Number of days
|
|
13
|
+
* @returns Equivalent value in milliseconds
|
|
14
|
+
*/
|
|
15
|
+
export declare function days(value: number): number;
|
package/time/days.js
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { hours } from "@telperion/js-utils/time/hours";
|
|
2
|
+
/**
|
|
3
|
+
* Converts days to milliseconds
|
|
4
|
+
*
|
|
5
|
+
* #### Example
|
|
6
|
+
* ```typescript
|
|
7
|
+
* import { days } from "@telperion/js-utils/time";
|
|
8
|
+
*
|
|
9
|
+
* const expiryTime = Date.now() + days(7); // 7 days from now
|
|
10
|
+
* console.log(new Date(expiryTime));
|
|
11
|
+
* ```
|
|
12
|
+
*
|
|
13
|
+
* @param value - Number of days
|
|
14
|
+
* @returns Equivalent value in milliseconds
|
|
15
|
+
*/
|
|
16
|
+
export function days(value) {
|
|
17
|
+
return hours(value) * 24;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
//# sourceMappingURL=days.js.map
|
package/time/days.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../../../libs/js-utils/src/time/days.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,MAAM,gCAAgC,CAAC;AAEvD;;;;;;;;;;;;;GAaG;AACH,MAAM,UAAU,IAAI,CAAC,KAAa;IAChC,OAAO,KAAK,CAAC,KAAK,CAAC,GAAG,EAAE,CAAC;AAC3B,CAAC","file":"days.js","sourcesContent":["import { hours } from \"@telperion/js-utils/time/hours\";\r\n\r\n/**\r\n * Converts days to milliseconds\r\n *\r\n * #### Example\r\n * ```typescript\r\n * import { days } from \"@telperion/js-utils/time\";\r\n *\r\n * const expiryTime = Date.now() + days(7); // 7 days from now\r\n * console.log(new Date(expiryTime));\r\n * ```\r\n *\r\n * @param value - Number of days\r\n * @returns Equivalent value in milliseconds\r\n */\r\nexport function days(value: number): number {\r\n return hours(value) * 24;\r\n}\r\n"]}
|
package/time/hours.cjs
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.hours = hours;
|
|
4
|
+
const minutes_1 = require("@telperion/js-utils/time/minutes");
|
|
5
|
+
/**
|
|
6
|
+
* Converts hours to milliseconds
|
|
7
|
+
*
|
|
8
|
+
* #### Example
|
|
9
|
+
* ```typescript
|
|
10
|
+
* import { hours } from "@telperion/js-utils/time";
|
|
11
|
+
*
|
|
12
|
+
* const delay = hours(1); // 3600000 milliseconds
|
|
13
|
+
* setTimeout(() => console.log('Done!'), delay);
|
|
14
|
+
* ```
|
|
15
|
+
*
|
|
16
|
+
* @param value - Number of hours
|
|
17
|
+
* @returns Equivalent value in milliseconds
|
|
18
|
+
*/
|
|
19
|
+
function hours(value) {
|
|
20
|
+
return (0, minutes_1.minutes)(value) * 60;
|
|
21
|
+
}
|
package/time/hours.d.ts
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Converts hours to milliseconds
|
|
3
|
+
*
|
|
4
|
+
* #### Example
|
|
5
|
+
* ```typescript
|
|
6
|
+
* import { hours } from "@telperion/js-utils/time";
|
|
7
|
+
*
|
|
8
|
+
* const delay = hours(1); // 3600000 milliseconds
|
|
9
|
+
* setTimeout(() => console.log('Done!'), delay);
|
|
10
|
+
* ```
|
|
11
|
+
*
|
|
12
|
+
* @param value - Number of hours
|
|
13
|
+
* @returns Equivalent value in milliseconds
|
|
14
|
+
*/
|
|
15
|
+
export declare function hours(value: number): number;
|
package/time/hours.js
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { minutes } from "@telperion/js-utils/time/minutes";
|
|
2
|
+
/**
|
|
3
|
+
* Converts hours to milliseconds
|
|
4
|
+
*
|
|
5
|
+
* #### Example
|
|
6
|
+
* ```typescript
|
|
7
|
+
* import { hours } from "@telperion/js-utils/time";
|
|
8
|
+
*
|
|
9
|
+
* const delay = hours(1); // 3600000 milliseconds
|
|
10
|
+
* setTimeout(() => console.log('Done!'), delay);
|
|
11
|
+
* ```
|
|
12
|
+
*
|
|
13
|
+
* @param value - Number of hours
|
|
14
|
+
* @returns Equivalent value in milliseconds
|
|
15
|
+
*/
|
|
16
|
+
export function hours(value) {
|
|
17
|
+
return minutes(value) * 60;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
//# sourceMappingURL=hours.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../../../libs/js-utils/src/time/hours.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,kCAAkC,CAAC;AAE3D;;;;;;;;;;;;;GAaG;AACH,MAAM,UAAU,KAAK,CAAC,KAAa;IACjC,OAAO,OAAO,CAAC,KAAK,CAAC,GAAG,EAAE,CAAC;AAC7B,CAAC","file":"hours.js","sourcesContent":["import { minutes } from \"@telperion/js-utils/time/minutes\";\r\n\r\n/**\r\n * Converts hours to milliseconds\r\n *\r\n * #### Example\r\n * ```typescript\r\n * import { hours } from \"@telperion/js-utils/time\";\r\n *\r\n * const delay = hours(1); // 3600000 milliseconds\r\n * setTimeout(() => console.log('Done!'), delay);\r\n * ```\r\n *\r\n * @param value - Number of hours\r\n * @returns Equivalent value in milliseconds\r\n */\r\nexport function hours(value: number): number {\r\n return minutes(value) * 60;\r\n}\r\n"]}
|
package/time/index.cjs
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const tslib_1 = require("tslib");
|
|
4
|
+
tslib_1.__exportStar(require("@telperion/js-utils/time/seconds"), exports);
|
|
5
|
+
tslib_1.__exportStar(require("@telperion/js-utils/time/minutes"), exports);
|
|
6
|
+
tslib_1.__exportStar(require("@telperion/js-utils/time/hours"), exports);
|
|
7
|
+
tslib_1.__exportStar(require("@telperion/js-utils/time/days"), exports);
|
|
8
|
+
tslib_1.__exportStar(require("@telperion/js-utils/time/weeks"), exports);
|
|
9
|
+
tslib_1.__exportStar(require("@telperion/js-utils/time/months"), exports);
|
|
10
|
+
tslib_1.__exportStar(require("@telperion/js-utils/time/years"), exports);
|
package/time/index.d.ts
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
export * from "@telperion/js-utils/time/seconds";
|
|
2
|
+
export * from "@telperion/js-utils/time/minutes";
|
|
3
|
+
export * from "@telperion/js-utils/time/hours";
|
|
4
|
+
export * from "@telperion/js-utils/time/days";
|
|
5
|
+
export * from "@telperion/js-utils/time/weeks";
|
|
6
|
+
export * from "@telperion/js-utils/time/months";
|
|
7
|
+
export * from "@telperion/js-utils/time/years";
|
package/time/index.js
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
export * from "@telperion/js-utils/time/seconds";
|
|
2
|
+
export * from "@telperion/js-utils/time/minutes";
|
|
3
|
+
export * from "@telperion/js-utils/time/hours";
|
|
4
|
+
export * from "@telperion/js-utils/time/days";
|
|
5
|
+
export * from "@telperion/js-utils/time/weeks";
|
|
6
|
+
export * from "@telperion/js-utils/time/months";
|
|
7
|
+
export * from "@telperion/js-utils/time/years";
|
|
8
|
+
|
|
9
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../../../libs/js-utils/src/time/index.ts"],"names":[],"mappings":"AAAA,cAAc,kCAAkC,CAAC;AACjD,cAAc,kCAAkC,CAAC;AACjD,cAAc,gCAAgC,CAAC;AAC/C,cAAc,+BAA+B,CAAC;AAC9C,cAAc,gCAAgC,CAAC;AAC/C,cAAc,iCAAiC,CAAC;AAChD,cAAc,gCAAgC,CAAC","file":"index.js","sourcesContent":["export * from \"@telperion/js-utils/time/seconds\";\r\nexport * from \"@telperion/js-utils/time/minutes\";\r\nexport * from \"@telperion/js-utils/time/hours\";\r\nexport * from \"@telperion/js-utils/time/days\";\r\nexport * from \"@telperion/js-utils/time/weeks\";\r\nexport * from \"@telperion/js-utils/time/months\";\r\nexport * from \"@telperion/js-utils/time/years\";\r\n"]}
|