@koine/utils 1.0.105 → 1.1.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/Defer.d.ts +1 -1
- package/README.md +3 -0
- package/accentSets.d.ts +1 -1
- package/areEqual.d.ts +19 -0
- package/areEqual.js +77 -0
- package/cookie.d.ts +3 -3
- package/forin.d.ts +7 -0
- package/forin.js +11 -0
- package/getMediaQueryWidthResolvers.d.ts +1 -1
- package/getType.d.ts +5 -5
- package/index.d.ts +5 -0
- package/index.js +5 -0
- package/location.d.ts +1 -1
- package/matchSorter.d.ts +3 -3
- package/node/areEqual.js +81 -0
- package/node/forin.js +15 -0
- package/node/index.js +5 -0
- package/node/noop.js +11 -0
- package/node/quaranteneProps.js +37 -0
- package/node/uuidNumeric.js +10 -0
- package/noop.d.ts +7 -0
- package/noop.js +7 -0
- package/package.json +8 -8
- package/quaranteneProps.d.ts +22 -0
- package/quaranteneProps.js +33 -0
- package/uuidNumeric.d.ts +6 -0
- package/uuidNumeric.js +6 -0
- package/createStorage.d.ts +0 -53
- package/createStorage.js +0 -137
- package/getZonedDate.d.ts +0 -16
- package/getZonedDate.js +0 -37
- package/isIE.d.ts +0 -7
- package/isIE.js +0 -18
- package/isMobile.d.ts +0 -7
- package/isMobile.js +0 -16
- package/navigateToHash.d.ts +0 -8
- package/navigateToHash.js +0 -12
- package/navigateToHashParams.d.ts +0 -9
- package/navigateToHashParams.js +0 -22
- package/navigateToMergedHashParams.d.ts +0 -8
- package/navigateToMergedHashParams.js +0 -14
- package/navigateToMergedParams.d.ts +0 -9
- package/navigateToMergedParams.js +0 -14
- package/navigateToParams.d.ts +0 -10
- package/navigateToParams.js +0 -18
- package/navigateWithoutUrlParam.d.ts +0 -8
- package/navigateWithoutUrlParam.js +0 -19
- package/pageview.d.ts +0 -9
- package/pageview.js +0 -29
- package/redirectTo.d.ts +0 -9
- package/redirectTo.js +0 -15
package/Defer.d.ts
CHANGED
package/README.md
CHANGED
|
@@ -6,6 +6,7 @@ Libraries to encapsulate and re-export from here, the selection is based on:
|
|
|
6
6
|
- [x] treeshake-ability
|
|
7
7
|
- [x] docs in source comments
|
|
8
8
|
|
|
9
|
+
- [dhmk-utils](https://github.com/dhmk083/dhmk-utils)
|
|
9
10
|
- [mesqueeb/merge-anything](https://github.com/mesqueeb/merge-anything)
|
|
10
11
|
- [mesqueeb/filter-anything](https://github.com/mesqueeb/filter-anything)
|
|
11
12
|
- [mesqueeb/case-anything](https://github.com/mesqueeb/case-anything)
|
|
@@ -34,6 +35,8 @@ anyway like [those of `yup`](https://github.com/jquense/yup/blob/master/package.
|
|
|
34
35
|
- [property-expr](https://github.com/jquense/expr/blob/master/index.js)
|
|
35
36
|
- [toposort](https://github.com/marcelklehr/toposort)
|
|
36
37
|
|
|
38
|
+
TODO: check typescript utilities in [TypeScript core](https://github.com/microsoft/TypeScript/blob/main/src/compiler/core.ts)
|
|
39
|
+
|
|
37
40
|
## Code
|
|
38
41
|
|
|
39
42
|
- Transformative functions like `truncate` or `titleCase` should allow for nullable inputs as much as possible, acceptin both `undefined` and `null`.
|
package/accentSets.d.ts
CHANGED
package/areEqual.d.ts
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
type ComparablePrimitive = string | number | boolean;
|
|
2
|
+
type Comparable = ComparablePrimitive | object | Record<string, ComparablePrimitive> | Array<ComparablePrimitive>;
|
|
3
|
+
/**
|
|
4
|
+
* A simple and quick deep equal objects utility. This is meant to be used
|
|
5
|
+
* solely to deduplicate requests payload and perform comparison on JSON ready
|
|
6
|
+
* objects made of primitives `string`, `number` and `boolean`s.
|
|
7
|
+
*
|
|
8
|
+
* It support nested `object`s and `array`s only.
|
|
9
|
+
*
|
|
10
|
+
* NB: `undefined` and `null` values do not count in the comparison as they are
|
|
11
|
+
* usually meant to be ignored in JSON requestBody payloads.
|
|
12
|
+
*
|
|
13
|
+
* According to very rudimentary tests this function takes on average between
|
|
14
|
+
* 0.15 ms and 2ms to compare two averaged sizes requet body payloads.
|
|
15
|
+
*
|
|
16
|
+
* @category objects
|
|
17
|
+
*/
|
|
18
|
+
export declare function areEqual(a: Comparable, b?: Comparable): boolean;
|
|
19
|
+
export default areEqual;
|
package/areEqual.js
ADDED
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
import { isArray } from "./isArray";
|
|
2
|
+
import { isObject } from "./isObject";
|
|
3
|
+
function areEqualArrays(a, b) {
|
|
4
|
+
if (!b)
|
|
5
|
+
return false;
|
|
6
|
+
if (a.length !== b.length)
|
|
7
|
+
return false;
|
|
8
|
+
for (var i = 0; i < a.length; i++) {
|
|
9
|
+
var aValue = a[i];
|
|
10
|
+
var bValue = b[i];
|
|
11
|
+
if (!areEqual(aValue, bValue))
|
|
12
|
+
return false;
|
|
13
|
+
}
|
|
14
|
+
return true;
|
|
15
|
+
}
|
|
16
|
+
function areEqualObjects(a, b) {
|
|
17
|
+
if (!b)
|
|
18
|
+
return false;
|
|
19
|
+
var aKeys = Object.keys(a);
|
|
20
|
+
var bKeys = Object.keys(b);
|
|
21
|
+
if (aKeys.length !== bKeys.length) {
|
|
22
|
+
return false;
|
|
23
|
+
}
|
|
24
|
+
for (var _i = 0, aKeys_1 = aKeys; _i < aKeys_1.length; _i++) {
|
|
25
|
+
var _key = aKeys_1[_i];
|
|
26
|
+
var key = _key;
|
|
27
|
+
var aValue = a[key];
|
|
28
|
+
var bValue = b[key];
|
|
29
|
+
if (!areEqual(aValue, bValue)) {
|
|
30
|
+
return false;
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
return true;
|
|
34
|
+
}
|
|
35
|
+
/**
|
|
36
|
+
* A simple and quick deep equal objects utility. This is meant to be used
|
|
37
|
+
* solely to deduplicate requests payload and perform comparison on JSON ready
|
|
38
|
+
* objects made of primitives `string`, `number` and `boolean`s.
|
|
39
|
+
*
|
|
40
|
+
* It support nested `object`s and `array`s only.
|
|
41
|
+
*
|
|
42
|
+
* NB: `undefined` and `null` values do not count in the comparison as they are
|
|
43
|
+
* usually meant to be ignored in JSON requestBody payloads.
|
|
44
|
+
*
|
|
45
|
+
* According to very rudimentary tests this function takes on average between
|
|
46
|
+
* 0.15 ms and 2ms to compare two averaged sizes requet body payloads.
|
|
47
|
+
*
|
|
48
|
+
* @category objects
|
|
49
|
+
*/
|
|
50
|
+
export function areEqual(a, b) {
|
|
51
|
+
if (!a && !b) {
|
|
52
|
+
// console.log(`areEqual took ${performance.now() - t0} ms`);
|
|
53
|
+
return true;
|
|
54
|
+
}
|
|
55
|
+
// const t0 = performance.now();
|
|
56
|
+
if (!b && a !== b) {
|
|
57
|
+
// console.log(`areEqual took ${performance.now() - t0} ms`);
|
|
58
|
+
return false;
|
|
59
|
+
}
|
|
60
|
+
var areObjects = isObject(a) && isObject(b);
|
|
61
|
+
if (areObjects && !areEqualObjects(a, b)) {
|
|
62
|
+
// console.log(`areEqual took ${performance.now() - t0} ms`);
|
|
63
|
+
return false;
|
|
64
|
+
}
|
|
65
|
+
var areArrays = isArray(a) && isArray(b);
|
|
66
|
+
if (areArrays && !areEqualArrays(a, b)) {
|
|
67
|
+
// console.log(`areEqual took ${performance.now() - t0} ms`);
|
|
68
|
+
return false;
|
|
69
|
+
}
|
|
70
|
+
if (!areObjects && !areArrays && a !== b) {
|
|
71
|
+
// console.log(`areEqual took ${performance.now() - t0} ms`);
|
|
72
|
+
return false;
|
|
73
|
+
}
|
|
74
|
+
// console.log(`areEqual took ${performance.now() - t0} ms`);
|
|
75
|
+
return true;
|
|
76
|
+
}
|
|
77
|
+
export default areEqual;
|
package/cookie.d.ts
CHANGED
|
@@ -7,7 +7,7 @@
|
|
|
7
7
|
* - [js-cookie](https://github.com/js-cookie/js-cookie)
|
|
8
8
|
* - [cookie](https://github.com/jshttp/cookie)
|
|
9
9
|
*/
|
|
10
|
-
|
|
10
|
+
type CookieAttributes = {
|
|
11
11
|
/**
|
|
12
12
|
* Define when the cookie will be removed. Value can be a Number
|
|
13
13
|
* which will be interpreted as days from time of creation or a
|
|
@@ -41,13 +41,13 @@ declare type CookieAttributes = {
|
|
|
41
41
|
*/
|
|
42
42
|
sameSite?: "strict" | "Strict" | "lax" | "Lax" | "none" | "None" | undefined;
|
|
43
43
|
};
|
|
44
|
-
export
|
|
44
|
+
export type CookieAttributesServer = CookieAttributes & {
|
|
45
45
|
maxAge?: number;
|
|
46
46
|
httpOnly?: boolean;
|
|
47
47
|
encode?: (input: string) => string;
|
|
48
48
|
decode?: (input: string) => string;
|
|
49
49
|
};
|
|
50
|
-
export
|
|
50
|
+
export type CookieAttributesClient = CookieAttributes;
|
|
51
51
|
export declare const defaultAttributesClient: {
|
|
52
52
|
path: string;
|
|
53
53
|
};
|
package/forin.d.ts
ADDED
package/forin.js
ADDED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export
|
|
1
|
+
export type GetMediaQueryWidthResolversBreakpoints = Record<string, number>;
|
|
2
2
|
export declare function getMediaQueryWidthResolvers<TBreakpointsConfig extends GetMediaQueryWidthResolversBreakpoints>(customBreakpoints: TBreakpointsConfig): {
|
|
3
3
|
max: (br: Extract<keyof TBreakpointsConfig, string>) => string;
|
|
4
4
|
min: (br: Extract<keyof TBreakpointsConfig, string>) => string;
|
package/getType.d.ts
CHANGED
|
@@ -7,11 +7,11 @@
|
|
|
7
7
|
* - `isInt`
|
|
8
8
|
* - `isFloat`
|
|
9
9
|
*/
|
|
10
|
-
export
|
|
11
|
-
export
|
|
12
|
-
export
|
|
13
|
-
export
|
|
14
|
-
export
|
|
10
|
+
export type AnyFunction = (...args: any[]) => any;
|
|
11
|
+
export type AnyAsyncFunction = (...args: any[]) => Promise<any>;
|
|
12
|
+
export type AnyClass = new (...args: any[]) => any;
|
|
13
|
+
export type PlainObject = Record<string | number | symbol, any>;
|
|
14
|
+
export type TypeGuard<A, B extends A> = (payload: A) => payload is B;
|
|
15
15
|
/**
|
|
16
16
|
* Returns the object type of the given payload
|
|
17
17
|
*
|
package/index.d.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
export * from "./accentSets";
|
|
2
2
|
export * from "./addOrReplaceAtIdx";
|
|
3
|
+
export * from "./areEqual";
|
|
3
4
|
export * from "./arrayOfAll";
|
|
4
5
|
export * from "./arraySum";
|
|
5
6
|
export * from "./arrayToLookup";
|
|
@@ -21,6 +22,7 @@ export * from "./Emitter";
|
|
|
21
22
|
export * from "./encode";
|
|
22
23
|
export * from "./ensureInt";
|
|
23
24
|
export * from "./findDuplicatedIndexes";
|
|
25
|
+
export * from "./forin";
|
|
24
26
|
export * from "./gbToBytes";
|
|
25
27
|
export * from "./getEmptyArray";
|
|
26
28
|
export * from "./getKeys";
|
|
@@ -86,12 +88,14 @@ export * from "./mbToBytes";
|
|
|
86
88
|
export * from "./mergeObjects";
|
|
87
89
|
export * from "./mergeUrlQueryParams";
|
|
88
90
|
export * from "./moveSortableArrayItemByKey";
|
|
91
|
+
export * from "./noop";
|
|
89
92
|
export * from "./normaliseUrlPathname";
|
|
90
93
|
export * from "./normaliseUrl";
|
|
91
94
|
export * from "./objectPick";
|
|
92
95
|
export * from "./objectOmit";
|
|
93
96
|
export * from "./parseCookie";
|
|
94
97
|
export * from "./parseURL";
|
|
98
|
+
export * from "./quaranteneProps";
|
|
95
99
|
export * from "./randomInt";
|
|
96
100
|
export * from "./randomKey";
|
|
97
101
|
export * from "./readCookie";
|
|
@@ -120,5 +124,6 @@ export * from "./updateLinkParams";
|
|
|
120
124
|
export * from "./updateUrlQueryParams";
|
|
121
125
|
export * from "./uppercase";
|
|
122
126
|
export * from "./uuid";
|
|
127
|
+
export * from "./uuidNumeric";
|
|
123
128
|
export * from "./wait";
|
|
124
129
|
export type { Primitive, Class, Constructor, TypedArray, Observer, ObservableLike, Except, Writable, Merge, MergeDeep, MergeExclusive, RequireAtLeastOne, RequireExactlyOne, RequireAllOrNone, RemoveIndexSignature, PartialDeep, ReadonlyDeep, LiteralUnion, Opaque, InvariantOf, SetOptional, SetRequired, ValueOf, ConditionalKeys, ConditionalPick, ConditionalExcept, UnionToIntersection, LiteralToPrimitive, Stringified, IterableElement, Entry, Exact, Entries, SetReturnType, Simplify, Get, StringKeyOf, Schema, Jsonify, JsonPrimitive, JsonObject, JsonArray, JsonValue, Promisable, AsyncReturnType, Asyncify, Trim, Split, Includes, Join, LastArrayElement, FixedLengthArray, MultidimensionalArray, MultidimensionalReadonlyArray, PositiveInfinity, NegativeInfinity, Finite, Integer, Float, NegativeFloat, Negative, NonNegative, NegativeInteger, NonNegativeInteger, CamelCase, CamelCasedProperties, CamelCasedPropertiesDeep, KebabCase, KebabCasedProperties, KebabCasedPropertiesDeep, PascalCase, PascalCasedProperties, PascalCasedPropertiesDeep, SnakeCase, SnakeCasedProperties, SnakeCasedPropertiesDeep, ScreamingSnakeCase, DelimiterCase, DelimiterCasedProperties, DelimiterCasedPropertiesDeep, PackageJson, TsConfigJson, SetNonNullable, Spread, PartialOnUndefinedDeep, OptionalKeysOf, HasOptionalKeys, RequiredKeysOf, HasRequiredKeys, UnwrapOpaque, EmptyObject, IsEmptyObject, TupleToUnion, OmitIndexSignature, PickIndexSignature, ConditionalPickDeep, } from "type-fest";
|
package/index.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
export * from "./accentSets";
|
|
2
2
|
export * from "./addOrReplaceAtIdx";
|
|
3
|
+
export * from "./areEqual";
|
|
3
4
|
export * from "./arrayOfAll";
|
|
4
5
|
export * from "./arraySum";
|
|
5
6
|
export * from "./arrayToLookup";
|
|
@@ -22,6 +23,7 @@ export * from "./encode";
|
|
|
22
23
|
export * from "./ensureInt";
|
|
23
24
|
// export * from "./env"
|
|
24
25
|
export * from "./findDuplicatedIndexes";
|
|
26
|
+
export * from "./forin";
|
|
25
27
|
export * from "./gbToBytes";
|
|
26
28
|
export * from "./getEmptyArray";
|
|
27
29
|
export * from "./getKeys";
|
|
@@ -87,12 +89,14 @@ export * from "./mbToBytes";
|
|
|
87
89
|
export * from "./mergeObjects";
|
|
88
90
|
export * from "./mergeUrlQueryParams";
|
|
89
91
|
export * from "./moveSortableArrayItemByKey";
|
|
92
|
+
export * from "./noop";
|
|
90
93
|
export * from "./normaliseUrlPathname";
|
|
91
94
|
export * from "./normaliseUrl";
|
|
92
95
|
export * from "./objectPick";
|
|
93
96
|
export * from "./objectOmit";
|
|
94
97
|
export * from "./parseCookie";
|
|
95
98
|
export * from "./parseURL";
|
|
99
|
+
export * from "./quaranteneProps";
|
|
96
100
|
export * from "./randomInt";
|
|
97
101
|
export * from "./randomKey";
|
|
98
102
|
export * from "./readCookie";
|
|
@@ -122,4 +126,5 @@ export * from "./updateLinkParams";
|
|
|
122
126
|
export * from "./updateUrlQueryParams";
|
|
123
127
|
export * from "./uppercase";
|
|
124
128
|
export * from "./uuid";
|
|
129
|
+
export * from "./uuidNumeric";
|
|
125
130
|
export * from "./wait";
|
package/location.d.ts
CHANGED
package/matchSorter.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
|
|
1
|
+
type KeyAttributes = {
|
|
2
2
|
threshold?: Ranking;
|
|
3
3
|
maxRanking: Ranking;
|
|
4
4
|
minRanking: Ranking;
|
|
@@ -30,7 +30,7 @@ interface KeyAttributesOptions<ItemType> {
|
|
|
30
30
|
maxRanking?: Ranking;
|
|
31
31
|
minRanking?: Ranking;
|
|
32
32
|
}
|
|
33
|
-
|
|
33
|
+
type KeyOption<ItemType> = KeyAttributesOptions<ItemType> | ValueGetterKey<ItemType> | string;
|
|
34
34
|
interface MatchSorterOptions<ItemType = unknown> {
|
|
35
35
|
keys?: ReadonlyArray<KeyOption<ItemType>>;
|
|
36
36
|
threshold?: Ranking;
|
|
@@ -46,7 +46,7 @@ declare const RANKING_CONTAINS = 3;
|
|
|
46
46
|
declare const RANKING_ACRONYM = 2;
|
|
47
47
|
declare const RANKING_MATCHES = 1;
|
|
48
48
|
declare const RANKING_NO_MATCH = 0;
|
|
49
|
-
|
|
49
|
+
type Ranking = typeof RANKING_CASE_SENSITIVE_EQUAL | typeof RANKING_EQUAL | typeof RANKING_STARTS_WITH | typeof RANKING_WORD_STARTS_WITH | typeof RANKING_CONTAINS | typeof RANKING_ACRONYM | typeof RANKING_MATCHES | typeof RANKING_NO_MATCH;
|
|
50
50
|
declare const defaultBaseSortFn: BaseSorter<unknown>;
|
|
51
51
|
/**
|
|
52
52
|
* Takes an array of items and a value and returns a new array with the items that match the given value
|
package/node/areEqual.js
ADDED
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.areEqual = void 0;
|
|
4
|
+
var isArray_1 = require("./isArray");
|
|
5
|
+
var isObject_1 = require("./isObject");
|
|
6
|
+
function areEqualArrays(a, b) {
|
|
7
|
+
if (!b)
|
|
8
|
+
return false;
|
|
9
|
+
if (a.length !== b.length)
|
|
10
|
+
return false;
|
|
11
|
+
for (var i = 0; i < a.length; i++) {
|
|
12
|
+
var aValue = a[i];
|
|
13
|
+
var bValue = b[i];
|
|
14
|
+
if (!areEqual(aValue, bValue))
|
|
15
|
+
return false;
|
|
16
|
+
}
|
|
17
|
+
return true;
|
|
18
|
+
}
|
|
19
|
+
function areEqualObjects(a, b) {
|
|
20
|
+
if (!b)
|
|
21
|
+
return false;
|
|
22
|
+
var aKeys = Object.keys(a);
|
|
23
|
+
var bKeys = Object.keys(b);
|
|
24
|
+
if (aKeys.length !== bKeys.length) {
|
|
25
|
+
return false;
|
|
26
|
+
}
|
|
27
|
+
for (var _i = 0, aKeys_1 = aKeys; _i < aKeys_1.length; _i++) {
|
|
28
|
+
var _key = aKeys_1[_i];
|
|
29
|
+
var key = _key;
|
|
30
|
+
var aValue = a[key];
|
|
31
|
+
var bValue = b[key];
|
|
32
|
+
if (!areEqual(aValue, bValue)) {
|
|
33
|
+
return false;
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
return true;
|
|
37
|
+
}
|
|
38
|
+
/**
|
|
39
|
+
* A simple and quick deep equal objects utility. This is meant to be used
|
|
40
|
+
* solely to deduplicate requests payload and perform comparison on JSON ready
|
|
41
|
+
* objects made of primitives `string`, `number` and `boolean`s.
|
|
42
|
+
*
|
|
43
|
+
* It support nested `object`s and `array`s only.
|
|
44
|
+
*
|
|
45
|
+
* NB: `undefined` and `null` values do not count in the comparison as they are
|
|
46
|
+
* usually meant to be ignored in JSON requestBody payloads.
|
|
47
|
+
*
|
|
48
|
+
* According to very rudimentary tests this function takes on average between
|
|
49
|
+
* 0.15 ms and 2ms to compare two averaged sizes requet body payloads.
|
|
50
|
+
*
|
|
51
|
+
* @category objects
|
|
52
|
+
*/
|
|
53
|
+
function areEqual(a, b) {
|
|
54
|
+
if (!a && !b) {
|
|
55
|
+
// console.log(`areEqual took ${performance.now() - t0} ms`);
|
|
56
|
+
return true;
|
|
57
|
+
}
|
|
58
|
+
// const t0 = performance.now();
|
|
59
|
+
if (!b && a !== b) {
|
|
60
|
+
// console.log(`areEqual took ${performance.now() - t0} ms`);
|
|
61
|
+
return false;
|
|
62
|
+
}
|
|
63
|
+
var areObjects = (0, isObject_1.isObject)(a) && (0, isObject_1.isObject)(b);
|
|
64
|
+
if (areObjects && !areEqualObjects(a, b)) {
|
|
65
|
+
// console.log(`areEqual took ${performance.now() - t0} ms`);
|
|
66
|
+
return false;
|
|
67
|
+
}
|
|
68
|
+
var areArrays = (0, isArray_1.isArray)(a) && (0, isArray_1.isArray)(b);
|
|
69
|
+
if (areArrays && !areEqualArrays(a, b)) {
|
|
70
|
+
// console.log(`areEqual took ${performance.now() - t0} ms`);
|
|
71
|
+
return false;
|
|
72
|
+
}
|
|
73
|
+
if (!areObjects && !areArrays && a !== b) {
|
|
74
|
+
// console.log(`areEqual took ${performance.now() - t0} ms`);
|
|
75
|
+
return false;
|
|
76
|
+
}
|
|
77
|
+
// console.log(`areEqual took ${performance.now() - t0} ms`);
|
|
78
|
+
return true;
|
|
79
|
+
}
|
|
80
|
+
exports.areEqual = areEqual;
|
|
81
|
+
exports.default = areEqual;
|
package/node/forin.js
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.forin = void 0;
|
|
4
|
+
/**
|
|
5
|
+
* To easily get typed native `for in`
|
|
6
|
+
*
|
|
7
|
+
* @category objects
|
|
8
|
+
*/
|
|
9
|
+
function forin(object, cb) {
|
|
10
|
+
for (var key in object) {
|
|
11
|
+
cb(key, object[key]);
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
exports.forin = forin;
|
|
15
|
+
exports.default = forin;
|
package/node/index.js
CHANGED
|
@@ -3,6 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
var tslib_1 = require("tslib");
|
|
4
4
|
tslib_1.__exportStar(require("./accentSets"), exports);
|
|
5
5
|
tslib_1.__exportStar(require("./addOrReplaceAtIdx"), exports);
|
|
6
|
+
tslib_1.__exportStar(require("./areEqual"), exports);
|
|
6
7
|
tslib_1.__exportStar(require("./arrayOfAll"), exports);
|
|
7
8
|
tslib_1.__exportStar(require("./arraySum"), exports);
|
|
8
9
|
tslib_1.__exportStar(require("./arrayToLookup"), exports);
|
|
@@ -25,6 +26,7 @@ tslib_1.__exportStar(require("./encode"), exports);
|
|
|
25
26
|
tslib_1.__exportStar(require("./ensureInt"), exports);
|
|
26
27
|
// export * from "./env"
|
|
27
28
|
tslib_1.__exportStar(require("./findDuplicatedIndexes"), exports);
|
|
29
|
+
tslib_1.__exportStar(require("./forin"), exports);
|
|
28
30
|
tslib_1.__exportStar(require("./gbToBytes"), exports);
|
|
29
31
|
tslib_1.__exportStar(require("./getEmptyArray"), exports);
|
|
30
32
|
tslib_1.__exportStar(require("./getKeys"), exports);
|
|
@@ -90,12 +92,14 @@ tslib_1.__exportStar(require("./mbToBytes"), exports);
|
|
|
90
92
|
tslib_1.__exportStar(require("./mergeObjects"), exports);
|
|
91
93
|
tslib_1.__exportStar(require("./mergeUrlQueryParams"), exports);
|
|
92
94
|
tslib_1.__exportStar(require("./moveSortableArrayItemByKey"), exports);
|
|
95
|
+
tslib_1.__exportStar(require("./noop"), exports);
|
|
93
96
|
tslib_1.__exportStar(require("./normaliseUrlPathname"), exports);
|
|
94
97
|
tslib_1.__exportStar(require("./normaliseUrl"), exports);
|
|
95
98
|
tslib_1.__exportStar(require("./objectPick"), exports);
|
|
96
99
|
tslib_1.__exportStar(require("./objectOmit"), exports);
|
|
97
100
|
tslib_1.__exportStar(require("./parseCookie"), exports);
|
|
98
101
|
tslib_1.__exportStar(require("./parseURL"), exports);
|
|
102
|
+
tslib_1.__exportStar(require("./quaranteneProps"), exports);
|
|
99
103
|
tslib_1.__exportStar(require("./randomInt"), exports);
|
|
100
104
|
tslib_1.__exportStar(require("./randomKey"), exports);
|
|
101
105
|
tslib_1.__exportStar(require("./readCookie"), exports);
|
|
@@ -125,4 +129,5 @@ tslib_1.__exportStar(require("./updateLinkParams"), exports);
|
|
|
125
129
|
tslib_1.__exportStar(require("./updateUrlQueryParams"), exports);
|
|
126
130
|
tslib_1.__exportStar(require("./uppercase"), exports);
|
|
127
131
|
tslib_1.__exportStar(require("./uuid"), exports);
|
|
132
|
+
tslib_1.__exportStar(require("./uuidNumeric"), exports);
|
|
128
133
|
tslib_1.__exportStar(require("./wait"), exports);
|
package/node/noop.js
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.noop = void 0;
|
|
4
|
+
/**
|
|
5
|
+
* No operation function
|
|
6
|
+
*
|
|
7
|
+
* @category native
|
|
8
|
+
*/
|
|
9
|
+
var noop = function () { return void 0; };
|
|
10
|
+
exports.noop = noop;
|
|
11
|
+
exports.default = exports.noop;
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.quaranteneProps = void 0;
|
|
4
|
+
/**
|
|
5
|
+
* @category impl
|
|
6
|
+
* @usage
|
|
7
|
+
*
|
|
8
|
+
* ```ts
|
|
9
|
+
* const { _: { onKeyDown }, myOwnProp, ...rest } = quaranteneProps([
|
|
10
|
+
* "onPointerLeave",
|
|
11
|
+
* "onPointerMove",
|
|
12
|
+
* "onClick",
|
|
13
|
+
* "onPointerDown",
|
|
14
|
+
* "onPointerUp",
|
|
15
|
+
* "onKeyDown",
|
|
16
|
+
* ]);
|
|
17
|
+
* ```
|
|
18
|
+
*/
|
|
19
|
+
function quaranteneProps(props, propsKeysToQuarantene) {
|
|
20
|
+
// approach 1)
|
|
21
|
+
var healthyProps = {
|
|
22
|
+
_: {},
|
|
23
|
+
};
|
|
24
|
+
for (var key in props) {
|
|
25
|
+
var prop = props[key];
|
|
26
|
+
if (propsKeysToQuarantene.includes(key)) {
|
|
27
|
+
healthyProps._[key] = prop;
|
|
28
|
+
}
|
|
29
|
+
else {
|
|
30
|
+
// @ts-expect-error nevermind
|
|
31
|
+
healthyProps[key] = prop;
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
return healthyProps;
|
|
35
|
+
}
|
|
36
|
+
exports.quaranteneProps = quaranteneProps;
|
|
37
|
+
exports.default = quaranteneProps;
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.uuidNumeric = void 0;
|
|
4
|
+
/**
|
|
5
|
+
* @category uid
|
|
6
|
+
* @see https://stackoverflow.com/a/18048162/1938970
|
|
7
|
+
*/
|
|
8
|
+
var uuidNumeric = function () { return new Date().valueOf(); };
|
|
9
|
+
exports.uuidNumeric = uuidNumeric;
|
|
10
|
+
exports.default = exports.uuidNumeric;
|
package/noop.d.ts
ADDED
package/noop.js
ADDED
package/package.json
CHANGED
|
@@ -2,13 +2,13 @@
|
|
|
2
2
|
"name": "@koine/utils",
|
|
3
3
|
"sideEffects": false,
|
|
4
4
|
"main": "./node/index.js",
|
|
5
|
-
"
|
|
6
|
-
"dependencies": {
|
|
7
|
-
|
|
8
|
-
"
|
|
5
|
+
"types": "./index.d.ts",
|
|
6
|
+
"dependencies": {},
|
|
7
|
+
"peerDependencies": {
|
|
8
|
+
"ts-debounce": "4.0.0",
|
|
9
|
+
"type-fest": "3.5.3",
|
|
10
|
+
"tslib": "2.5.0"
|
|
9
11
|
},
|
|
10
|
-
"
|
|
11
|
-
"
|
|
12
|
-
"module": "./index.js",
|
|
13
|
-
"types": "./index.d.ts"
|
|
12
|
+
"version": "1.1.0",
|
|
13
|
+
"module": "./index.js"
|
|
14
14
|
}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @category impl
|
|
3
|
+
* @usage
|
|
4
|
+
*
|
|
5
|
+
* ```ts
|
|
6
|
+
* const { _: { onKeyDown }, myOwnProp, ...rest } = quaranteneProps([
|
|
7
|
+
* "onPointerLeave",
|
|
8
|
+
* "onPointerMove",
|
|
9
|
+
* "onClick",
|
|
10
|
+
* "onPointerDown",
|
|
11
|
+
* "onPointerUp",
|
|
12
|
+
* "onKeyDown",
|
|
13
|
+
* ]);
|
|
14
|
+
* ```
|
|
15
|
+
*/
|
|
16
|
+
export declare function quaranteneProps<TProps extends Record<never, never>, TSupectPropsKeys extends QuaranteneProps<TProps>>(props: TProps, propsKeysToQuarantene: TSupectPropsKeys): Omit<TProps, TSupectPropsKeys[number]> & {
|
|
17
|
+
_: Pick<TProps, TSupectPropsKeys[number]>;
|
|
18
|
+
};
|
|
19
|
+
export default quaranteneProps;
|
|
20
|
+
type QuaranteneProps<TProps extends Record<never, never>> = readonly (keyof {
|
|
21
|
+
[K in keyof TProps]?: TProps[K];
|
|
22
|
+
})[];
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @category impl
|
|
3
|
+
* @usage
|
|
4
|
+
*
|
|
5
|
+
* ```ts
|
|
6
|
+
* const { _: { onKeyDown }, myOwnProp, ...rest } = quaranteneProps([
|
|
7
|
+
* "onPointerLeave",
|
|
8
|
+
* "onPointerMove",
|
|
9
|
+
* "onClick",
|
|
10
|
+
* "onPointerDown",
|
|
11
|
+
* "onPointerUp",
|
|
12
|
+
* "onKeyDown",
|
|
13
|
+
* ]);
|
|
14
|
+
* ```
|
|
15
|
+
*/
|
|
16
|
+
export function quaranteneProps(props, propsKeysToQuarantene) {
|
|
17
|
+
// approach 1)
|
|
18
|
+
var healthyProps = {
|
|
19
|
+
_: {},
|
|
20
|
+
};
|
|
21
|
+
for (var key in props) {
|
|
22
|
+
var prop = props[key];
|
|
23
|
+
if (propsKeysToQuarantene.includes(key)) {
|
|
24
|
+
healthyProps._[key] = prop;
|
|
25
|
+
}
|
|
26
|
+
else {
|
|
27
|
+
// @ts-expect-error nevermind
|
|
28
|
+
healthyProps[key] = prop;
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
return healthyProps;
|
|
32
|
+
}
|
|
33
|
+
export default quaranteneProps;
|
package/uuidNumeric.d.ts
ADDED
package/uuidNumeric.js
ADDED
package/createStorage.d.ts
DELETED
|
@@ -1,53 +0,0 @@
|
|
|
1
|
-
export declare type CreateStorageConfig = Record<string, any>;
|
|
2
|
-
/**
|
|
3
|
-
* Utility to create a storage instance to interact with `localStorage` using
|
|
4
|
-
* encrypted (encoded) key/values.
|
|
5
|
-
*/
|
|
6
|
-
export declare const createStorage: <T extends CreateStorageConfig>(config: Partial<T>) => {
|
|
7
|
-
/**
|
|
8
|
-
* Get all storage value (it uses `localStorage.get()`).
|
|
9
|
-
*
|
|
10
|
-
* Unparseable values with `JSON.parse()` return their value as it is.
|
|
11
|
-
* If the given `key` argument is not found `null` is returned.
|
|
12
|
-
*/
|
|
13
|
-
get<TKey extends keyof T>(key: TKey): T[TKey] | null;
|
|
14
|
-
/**
|
|
15
|
-
* Get all storage values (it uses `localStorage.get()`).
|
|
16
|
-
*
|
|
17
|
-
* `undefined` and `null` values are not returned.
|
|
18
|
-
*/
|
|
19
|
-
getAll(): T;
|
|
20
|
-
/**
|
|
21
|
-
* Set a storage value (it uses `localStorage.set()`).
|
|
22
|
-
*
|
|
23
|
-
* Non-string values are stringified with `JSON.stringify()`
|
|
24
|
-
*/
|
|
25
|
-
set<TKey_1 extends keyof T>(key: TKey_1, value: T[TKey_1]): void;
|
|
26
|
-
/**
|
|
27
|
-
* Set all given storage values (it uses `localStorage.set()`).
|
|
28
|
-
*
|
|
29
|
-
* Non-string values are stringified with `JSON.stringify()`, `undefined`
|
|
30
|
-
* and `null` values are removed from the storage
|
|
31
|
-
*/
|
|
32
|
-
setMany(newValues: Partial<T>): void;
|
|
33
|
-
/**
|
|
34
|
-
* Check if a storage value is _truthy_ (it uses `localStorage.get()`).
|
|
35
|
-
*/
|
|
36
|
-
has<TKey_2 extends keyof T>(key: TKey_2): boolean;
|
|
37
|
-
/**
|
|
38
|
-
* Remove a storage value (it uses `localStorage.remove()`).
|
|
39
|
-
*/
|
|
40
|
-
remove<TKey_3 extends keyof T>(key: TKey_3): void;
|
|
41
|
-
/**
|
|
42
|
-
* Clear all storage values (it uses `localStorage.remove()`).
|
|
43
|
-
*/
|
|
44
|
-
clear(): void;
|
|
45
|
-
/**
|
|
46
|
-
* Watch a storage value changes, this needs to be executed only in browser
|
|
47
|
-
* context (it uses `window.addEventListener("storage")`).
|
|
48
|
-
*
|
|
49
|
-
* Inspiration from [Multi Tab Logout in React — Redux](https://medium.com/front-end-weekly/multi-tab-logout-in-react-redux-4715f071c7fa)
|
|
50
|
-
*/
|
|
51
|
-
watch: <TKey_4 extends keyof T>(keyToWatch: TKey_4, onRemoved?: () => void, onAdded?: () => void) => () => void;
|
|
52
|
-
};
|
|
53
|
-
export default createStorage;
|
package/createStorage.js
DELETED
|
@@ -1,137 +0,0 @@
|
|
|
1
|
-
import { __assign } from "tslib";
|
|
2
|
-
import { decode } from "./decode";
|
|
3
|
-
import { encode } from "./encode";
|
|
4
|
-
import { isBrowser } from "./isBrowser";
|
|
5
|
-
import { isNullOrUndefined } from "./isNullOrUndefined";
|
|
6
|
-
import { isString } from "./isString";
|
|
7
|
-
/**
|
|
8
|
-
* Utility to create a storage instance to interact with `localStorage` using
|
|
9
|
-
* encrypted (encoded) key/values.
|
|
10
|
-
*/
|
|
11
|
-
export var createStorage = function (config) {
|
|
12
|
-
var methodsMap = { g: "getItem", s: "setItem", r: "removeItem" };
|
|
13
|
-
/**
|
|
14
|
-
* Super minifiable localStorage wrapper with SSR safety
|
|
15
|
-
*/
|
|
16
|
-
var ls = function (method, key, value) {
|
|
17
|
-
return isBrowser
|
|
18
|
-
? localStorage[methodsMap[method]](key, value)
|
|
19
|
-
: function () {
|
|
20
|
-
if (process.env["NODE_ENV"] !== "production") {
|
|
21
|
-
console.warn("[@koine/utils] createStorage: localStorage does not exists in this environment.");
|
|
22
|
-
}
|
|
23
|
-
};
|
|
24
|
-
};
|
|
25
|
-
var keys = Object.keys(config).reduce(function (map, key) {
|
|
26
|
-
var _a;
|
|
27
|
-
return (__assign(__assign({}, map), (_a = {}, _a[key] = encode(key), _a)));
|
|
28
|
-
}, {});
|
|
29
|
-
return {
|
|
30
|
-
/**
|
|
31
|
-
* Get all storage value (it uses `localStorage.get()`).
|
|
32
|
-
*
|
|
33
|
-
* Unparseable values with `JSON.parse()` return their value as it is.
|
|
34
|
-
* If the given `key` argument is not found `null` is returned.
|
|
35
|
-
*/
|
|
36
|
-
get: function (key) {
|
|
37
|
-
var stored = ls("g", keys[key]);
|
|
38
|
-
if (stored) {
|
|
39
|
-
stored = decode(stored);
|
|
40
|
-
try {
|
|
41
|
-
return JSON.parse(stored);
|
|
42
|
-
}
|
|
43
|
-
catch (_e) {
|
|
44
|
-
return stored;
|
|
45
|
-
}
|
|
46
|
-
}
|
|
47
|
-
return null;
|
|
48
|
-
},
|
|
49
|
-
/**
|
|
50
|
-
* Get all storage values (it uses `localStorage.get()`).
|
|
51
|
-
*
|
|
52
|
-
* `undefined` and `null` values are not returned.
|
|
53
|
-
*/
|
|
54
|
-
getAll: function () {
|
|
55
|
-
var all = {};
|
|
56
|
-
for (var key in keys) {
|
|
57
|
-
var value = this.get(key);
|
|
58
|
-
if (!isNullOrUndefined(value)) {
|
|
59
|
-
all[key] = value;
|
|
60
|
-
}
|
|
61
|
-
}
|
|
62
|
-
return all;
|
|
63
|
-
},
|
|
64
|
-
/**
|
|
65
|
-
* Set a storage value (it uses `localStorage.set()`).
|
|
66
|
-
*
|
|
67
|
-
* Non-string values are stringified with `JSON.stringify()`
|
|
68
|
-
*/
|
|
69
|
-
set: function (key, value) {
|
|
70
|
-
ls("s", keys[key], isString(value) ? encode(value) : encode(JSON.stringify(value)));
|
|
71
|
-
},
|
|
72
|
-
/**
|
|
73
|
-
* Set all given storage values (it uses `localStorage.set()`).
|
|
74
|
-
*
|
|
75
|
-
* Non-string values are stringified with `JSON.stringify()`, `undefined`
|
|
76
|
-
* and `null` values are removed from the storage
|
|
77
|
-
*/
|
|
78
|
-
setMany: function (newValues) {
|
|
79
|
-
for (var key in newValues) {
|
|
80
|
-
var value = newValues[key];
|
|
81
|
-
if (!isNullOrUndefined(value)) {
|
|
82
|
-
this.set(key, value);
|
|
83
|
-
}
|
|
84
|
-
else {
|
|
85
|
-
this.remove(key);
|
|
86
|
-
}
|
|
87
|
-
}
|
|
88
|
-
},
|
|
89
|
-
/**
|
|
90
|
-
* Check if a storage value is _truthy_ (it uses `localStorage.get()`).
|
|
91
|
-
*/
|
|
92
|
-
has: function (key) {
|
|
93
|
-
var stored = ls("g", keys[key]);
|
|
94
|
-
return !!stored;
|
|
95
|
-
},
|
|
96
|
-
/**
|
|
97
|
-
* Remove a storage value (it uses `localStorage.remove()`).
|
|
98
|
-
*/
|
|
99
|
-
remove: function (key) {
|
|
100
|
-
ls("r", keys[key]);
|
|
101
|
-
},
|
|
102
|
-
/**
|
|
103
|
-
* Clear all storage values (it uses `localStorage.remove()`).
|
|
104
|
-
*/
|
|
105
|
-
clear: function () {
|
|
106
|
-
for (var key in keys) {
|
|
107
|
-
ls("r", keys[key]);
|
|
108
|
-
}
|
|
109
|
-
},
|
|
110
|
-
/**
|
|
111
|
-
* Watch a storage value changes, this needs to be executed only in browser
|
|
112
|
-
* context (it uses `window.addEventListener("storage")`).
|
|
113
|
-
*
|
|
114
|
-
* Inspiration from [Multi Tab Logout in React — Redux](https://medium.com/front-end-weekly/multi-tab-logout-in-react-redux-4715f071c7fa)
|
|
115
|
-
*/
|
|
116
|
-
watch: function (keyToWatch, onRemoved, onAdded) {
|
|
117
|
-
var handler = function (event) {
|
|
118
|
-
var key = event.key, oldValue = event.oldValue, newValue = event.newValue;
|
|
119
|
-
if (key === keys[keyToWatch]) {
|
|
120
|
-
if (oldValue && !newValue) {
|
|
121
|
-
onRemoved === null || onRemoved === void 0 ? void 0 : onRemoved();
|
|
122
|
-
}
|
|
123
|
-
else if (!oldValue && newValue) {
|
|
124
|
-
onAdded === null || onAdded === void 0 ? void 0 : onAdded();
|
|
125
|
-
}
|
|
126
|
-
}
|
|
127
|
-
};
|
|
128
|
-
if (!isBrowser)
|
|
129
|
-
return function () { return void 0; };
|
|
130
|
-
window.addEventListener("storage", handler);
|
|
131
|
-
return function () {
|
|
132
|
-
window.removeEventListener("storage", handler);
|
|
133
|
-
};
|
|
134
|
-
},
|
|
135
|
-
};
|
|
136
|
-
};
|
|
137
|
-
export default createStorage;
|
package/getZonedDate.d.ts
DELETED
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* It returns a `Date` object from a date `string` adjusted on the user timeZone,
|
|
3
|
-
* if a timeZone is not provided we try getting it from the `Intl` browwser native
|
|
4
|
-
* API. It gracefully falls back returning a _non-timezone-based_ `Date`.
|
|
5
|
-
*
|
|
6
|
-
* @category date
|
|
7
|
-
*
|
|
8
|
-
* @resources
|
|
9
|
-
* - to get the timeZone client side see [this article](https://attacomsian.com/blog/javascript-current-timezone)
|
|
10
|
-
* - for converting the date based on the time zone [date-fns docs](https://date-fns.org/v2.27.0/docs/Time-Zones) and [date-fns-tz docs](https://github.com/marnusw/date-fns-tz)
|
|
11
|
-
*
|
|
12
|
-
* @param dateString A parseable date as string, `Z` is automatically suffixed if not present to correctly get time zone based time from a UTC date.
|
|
13
|
-
* @param timeZone Optionally pass a timeZone (e.g. from user preference or from the server), it falls back trying to read it from the `Intl` browwser native API.
|
|
14
|
-
*/
|
|
15
|
-
export declare function getZonedDate(dateString?: string, timeZone?: string): Date;
|
|
16
|
-
export default getZonedDate;
|
package/getZonedDate.js
DELETED
|
@@ -1,37 +0,0 @@
|
|
|
1
|
-
import utcToZonedTime from "date-fns-tz/utcToZonedTime";
|
|
2
|
-
import isBrowser from "./isBrowser";
|
|
3
|
-
/**
|
|
4
|
-
* It returns a `Date` object from a date `string` adjusted on the user timeZone,
|
|
5
|
-
* if a timeZone is not provided we try getting it from the `Intl` browwser native
|
|
6
|
-
* API. It gracefully falls back returning a _non-timezone-based_ `Date`.
|
|
7
|
-
*
|
|
8
|
-
* @category date
|
|
9
|
-
*
|
|
10
|
-
* @resources
|
|
11
|
-
* - to get the timeZone client side see [this article](https://attacomsian.com/blog/javascript-current-timezone)
|
|
12
|
-
* - for converting the date based on the time zone [date-fns docs](https://date-fns.org/v2.27.0/docs/Time-Zones) and [date-fns-tz docs](https://github.com/marnusw/date-fns-tz)
|
|
13
|
-
*
|
|
14
|
-
* @param dateString A parseable date as string, `Z` is automatically suffixed if not present to correctly get time zone based time from a UTC date.
|
|
15
|
-
* @param timeZone Optionally pass a timeZone (e.g. from user preference or from the server), it falls back trying to read it from the `Intl` browwser native API.
|
|
16
|
-
*/
|
|
17
|
-
export function getZonedDate(dateString, timeZone) {
|
|
18
|
-
if (dateString === void 0) { dateString = ""; }
|
|
19
|
-
if (!dateString.endsWith("Z"))
|
|
20
|
-
dateString += "Z";
|
|
21
|
-
if (!timeZone && isBrowser) {
|
|
22
|
-
try {
|
|
23
|
-
timeZone = Intl.DateTimeFormat().resolvedOptions().timeZone;
|
|
24
|
-
}
|
|
25
|
-
catch (e) {
|
|
26
|
-
if (process.env["NODE_ENV"] !== "production") {
|
|
27
|
-
console.warn("[@koine/utils:getZonedDate] failed reading timeZone, error", e);
|
|
28
|
-
}
|
|
29
|
-
// no need to do anything here, it just means `Intl` failed, probably
|
|
30
|
-
// because the browser does not support it
|
|
31
|
-
}
|
|
32
|
-
}
|
|
33
|
-
return timeZone
|
|
34
|
-
? utcToZonedTime(new Date(dateString), timeZone)
|
|
35
|
-
: new Date(dateString);
|
|
36
|
-
}
|
|
37
|
-
export default getZonedDate;
|
package/isIE.d.ts
DELETED
package/isIE.js
DELETED
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
import { isServer } from "./isServer";
|
|
2
|
-
/**
|
|
3
|
-
* @category detect
|
|
4
|
-
* @category is
|
|
5
|
-
* @see https://stackoverflow.com/a/21712356/12285349
|
|
6
|
-
*/
|
|
7
|
-
export function isIE(ssrValue) {
|
|
8
|
-
if (ssrValue === void 0) { ssrValue = true; }
|
|
9
|
-
if (isServer) {
|
|
10
|
-
return ssrValue;
|
|
11
|
-
}
|
|
12
|
-
var ua = window.navigator.userAgent;
|
|
13
|
-
if (ua.indexOf("MSIE ") > 0 || ua.indexOf("Trident/") > 0) {
|
|
14
|
-
return true;
|
|
15
|
-
}
|
|
16
|
-
return false;
|
|
17
|
-
}
|
|
18
|
-
export default isIE;
|
package/isMobile.d.ts
DELETED
package/isMobile.js
DELETED
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
import { isServer } from "./isServer";
|
|
2
|
-
/**
|
|
3
|
-
* @category detect
|
|
4
|
-
* @category is
|
|
5
|
-
* @see https://stackoverflow.com/a/3540295
|
|
6
|
-
*/
|
|
7
|
-
export function isMobile(ssrValue) {
|
|
8
|
-
if (ssrValue === void 0) { ssrValue = true; }
|
|
9
|
-
if (isServer) {
|
|
10
|
-
return ssrValue;
|
|
11
|
-
}
|
|
12
|
-
return /Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(window.navigator.userAgent);
|
|
13
|
-
// return /(android|bb\d+|meego).+mobile|avantgo|bada\/|blackberry|blazer|compal|elaine|fennec|hiptop|iemobile|ip(hone|od)|ipad|iris|kindle|Android|Silk|lge |maemo|midp|mmp|netfront|opera m(ob|in)i|palm( os)?|phone|p(ixi|re)\/|plucker|pocket|psp|series(4|6)0|symbian|treo|up\.(browser|link)|vodafone|wap|windows (ce|phone)|xda|xiino/i.test(navigator.userAgent)
|
|
14
|
-
// || /1207|6310|6590|3gso|4thp|50[1-6]i|770s|802s|a wa|abac|ac(er|oo|s\-)|ai(ko|rn)|al(av|ca|co)|amoi|an(ex|ny|yw)|aptu|ar(ch|go)|as(te|us)|attw|au(di|\-m|r |s )|avan|be(ck|ll|nq)|bi(lb|rd)|bl(ac|az)|br(e|v)w|bumb|bw\-(n|u)|c55\/|capi|ccwa|cdm\-|cell|chtm|cldc|cmd\-|co(mp|nd)|craw|da(it|ll|ng)|dbte|dc\-s|devi|dica|dmob|do(c|p)o|ds(12|\-d)|el(49|ai)|em(l2|ul)|er(ic|k0)|esl8|ez([4-7]0|os|wa|ze)|fetc|fly(\-|_)|g1 u|g560|gene|gf\-5|g\-mo|go(\.w|od)|gr(ad|un)|haie|hcit|hd\-(m|p|t)|hei\-|hi(pt|ta)|hp( i|ip)|hs\-c|ht(c(\-| |_|a|g|p|s|t)|tp)|hu(aw|tc)|i\-(20|go|ma)|i230|iac( |\-|\/)|ibro|idea|ig01|ikom|im1k|inno|ipaq|iris|ja(t|v)a|jbro|jemu|jigs|kddi|keji|kgt( |\/)|klon|kpt |kwc\-|kyo(c|k)|le(no|xi)|lg( g|\/(k|l|u)|50|54|\-[a-w])|libw|lynx|m1\-w|m3ga|m50\/|ma(te|ui|xo)|mc(01|21|ca)|m\-cr|me(rc|ri)|mi(o8|oa|ts)|mmef|mo(01|02|bi|de|do|t(\-| |o|v)|zz)|mt(50|p1|v )|mwbp|mywa|n10[0-2]|n20[2-3]|n30(0|2)|n50(0|2|5)|n7(0(0|1)|10)|ne((c|m)\-|on|tf|wf|wg|wt)|nok(6|i)|nzph|o2im|op(ti|wv)|oran|owg1|p800|pan(a|d|t)|pdxg|pg(13|\-([1-8]|c))|phil|pire|pl(ay|uc)|pn\-2|po(ck|rt|se)|prox|psio|pt\-g|qa\-a|qc(07|12|21|32|60|\-[2-7]|i\-)|qtek|r380|r600|raks|rim9|ro(ve|zo)|s55\/|sa(ge|ma|mm|ms|ny|va)|sc(01|h\-|oo|p\-)|sdk\/|se(c(\-|0|1)|47|mc|nd|ri)|sgh\-|shar|sie(\-|m)|sk\-0|sl(45|id)|sm(al|ar|b3|it|t5)|so(ft|ny)|sp(01|h\-|v\-|v )|sy(01|mb)|t2(18|50)|t6(00|10|18)|ta(gt|lk)|tcl\-|tdg\-|tel(i|m)|tim\-|t\-mo|to(pl|sh)|ts(70|m\-|m3|m5)|tx\-9|up(\.b|g1|si)|utst|v400|v750|veri|vi(rg|te)|vk(40|5[0-3]|\-v)|vm40|voda|vulc|vx(52|53|60|61|70|80|81|83|85|98)|w3c(\-| )|webc|whit|wi(g |nc|nw)|wmlb|wonu|x700|yas\-|your|zeto|zte\-/i.test(navigator.userAgent.substr(0,4)
|
|
15
|
-
}
|
|
16
|
-
export default isMobile;
|
package/navigateToHash.d.ts
DELETED
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* It updates the browser's location hash by replacing the history state.
|
|
3
|
-
* The non-silent standard way would simply be `location.hash = "#new-hash"`
|
|
4
|
-
*
|
|
5
|
-
* @category location
|
|
6
|
-
*/
|
|
7
|
-
export declare function navigateToHash(hash?: string): void;
|
|
8
|
-
export default navigateToHash;
|
package/navigateToHash.js
DELETED
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* It updates the browser's location hash by replacing the history state.
|
|
3
|
-
* The non-silent standard way would simply be `location.hash = "#new-hash"`
|
|
4
|
-
*
|
|
5
|
-
* @category location
|
|
6
|
-
*/
|
|
7
|
-
export function navigateToHash(hash) {
|
|
8
|
-
if (hash === void 0) { hash = ""; }
|
|
9
|
-
var pathname = location.pathname, search = location.search;
|
|
10
|
-
history.replaceState(null, "", pathname + (search ? "?" + search : "") + "#" + hash);
|
|
11
|
-
}
|
|
12
|
-
export default navigateToHash;
|
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
import { type AnyQueryParams } from "./location";
|
|
2
|
-
/**
|
|
3
|
-
* It updates the `location.hash` with the given query params, it uses `location.hash`
|
|
4
|
-
* if a second argument `hash` is not provded
|
|
5
|
-
*
|
|
6
|
-
* @category location
|
|
7
|
-
*/
|
|
8
|
-
export declare function navigateToHashParams(params?: string | AnyQueryParams, hash?: string): string;
|
|
9
|
-
export default navigateToHashParams;
|
package/navigateToHashParams.js
DELETED
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
import buildUrlQueryString from "./buildUrlQueryString";
|
|
2
|
-
import getUrlHashPathname from "./getUrlHashPathname";
|
|
3
|
-
/**
|
|
4
|
-
* It updates the `location.hash` with the given query params, it uses `location.hash`
|
|
5
|
-
* if a second argument `hash` is not provded
|
|
6
|
-
*
|
|
7
|
-
* @category location
|
|
8
|
-
*/
|
|
9
|
-
export function navigateToHashParams(params, hash) {
|
|
10
|
-
if (params === void 0) { params = {}; }
|
|
11
|
-
if (hash === void 0) { hash = ""; }
|
|
12
|
-
var useLocation = !hash;
|
|
13
|
-
hash = hash || location.hash;
|
|
14
|
-
var hashQueryLess = getUrlHashPathname(hash);
|
|
15
|
-
var queryString = typeof params === "string" ? params : buildUrlQueryString(params);
|
|
16
|
-
var newHash = "#/" + hashQueryLess + queryString;
|
|
17
|
-
if (useLocation) {
|
|
18
|
-
location.hash = newHash;
|
|
19
|
-
}
|
|
20
|
-
return newHash;
|
|
21
|
-
}
|
|
22
|
-
export default navigateToHashParams;
|
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
import { type AnyQueryParams } from "./location";
|
|
2
|
-
/**
|
|
3
|
-
* It updates the "query params" within the `location.hash`, it uses `location`
|
|
4
|
-
*
|
|
5
|
-
* @category location
|
|
6
|
-
*/
|
|
7
|
-
export declare function navigateToMergedHashParams(params?: NonNullable<AnyQueryParams>, hash?: string): string;
|
|
8
|
-
export default navigateToMergedHashParams;
|
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
import getUrlHashParams from "./getUrlHashParams";
|
|
2
|
-
import mergeUrlQueryParams from "./mergeUrlQueryParams";
|
|
3
|
-
import navigateToHashParams from "./navigateToHashParams";
|
|
4
|
-
/**
|
|
5
|
-
* It updates the "query params" within the `location.hash`, it uses `location`
|
|
6
|
-
*
|
|
7
|
-
* @category location
|
|
8
|
-
*/
|
|
9
|
-
export function navigateToMergedHashParams(params, hash) {
|
|
10
|
-
if (params === void 0) { params = {}; }
|
|
11
|
-
if (hash === void 0) { hash = ""; }
|
|
12
|
-
return navigateToHashParams(mergeUrlQueryParams(getUrlHashParams(hash), params), hash);
|
|
13
|
-
}
|
|
14
|
-
export default navigateToMergedHashParams;
|
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
import { type AnyQueryParams } from "./location";
|
|
2
|
-
/**
|
|
3
|
-
* Merge current URL query parameters with the given ones, it uses `history`.
|
|
4
|
-
*
|
|
5
|
-
* @category location
|
|
6
|
-
* @param replace Replace URL instead of pushing it in the history stack. By default it pushes it.
|
|
7
|
-
*/
|
|
8
|
-
export declare function navigateToMergedParams(params?: NonNullable<AnyQueryParams>, replace?: boolean): string;
|
|
9
|
-
export default navigateToMergedParams;
|
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
import getUrlQueryParams from "./getUrlQueryParams";
|
|
2
|
-
import mergeUrlQueryParams from "./mergeUrlQueryParams";
|
|
3
|
-
import navigateToParams from "./navigateToParams";
|
|
4
|
-
/**
|
|
5
|
-
* Merge current URL query parameters with the given ones, it uses `history`.
|
|
6
|
-
*
|
|
7
|
-
* @category location
|
|
8
|
-
* @param replace Replace URL instead of pushing it in the history stack. By default it pushes it.
|
|
9
|
-
*/
|
|
10
|
-
export function navigateToMergedParams(params, replace) {
|
|
11
|
-
if (params === void 0) { params = {}; }
|
|
12
|
-
return navigateToParams(mergeUrlQueryParams(getUrlQueryParams(), params), replace);
|
|
13
|
-
}
|
|
14
|
-
export default navigateToMergedParams;
|
package/navigateToParams.d.ts
DELETED
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
import { type AnyQueryParams } from "./location";
|
|
2
|
-
/**
|
|
3
|
-
* Change current URL query parameters, it uses `history`.
|
|
4
|
-
*
|
|
5
|
-
* @category location
|
|
6
|
-
* @param replace Replace URL instead of pushing it in the history stack. By default it pushes it.
|
|
7
|
-
* @returns The query string with initial `?`
|
|
8
|
-
*/
|
|
9
|
-
export declare function navigateToParams(params?: string | AnyQueryParams, replace?: boolean): string;
|
|
10
|
-
export default navigateToParams;
|
package/navigateToParams.js
DELETED
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
import buildUrlQueryString from "./buildUrlQueryString";
|
|
2
|
-
import isBrowser from "./isBrowser";
|
|
3
|
-
/**
|
|
4
|
-
* Change current URL query parameters, it uses `history`.
|
|
5
|
-
*
|
|
6
|
-
* @category location
|
|
7
|
-
* @param replace Replace URL instead of pushing it in the history stack. By default it pushes it.
|
|
8
|
-
* @returns The query string with initial `?`
|
|
9
|
-
*/
|
|
10
|
-
export function navigateToParams(params, replace) {
|
|
11
|
-
if (params === void 0) { params = {}; }
|
|
12
|
-
var queryString = typeof params === "string" ? params : buildUrlQueryString(params);
|
|
13
|
-
if (isBrowser) {
|
|
14
|
-
history[replace ? "replaceState" : "pushState"](null, "", location.pathname + queryString);
|
|
15
|
-
}
|
|
16
|
-
return queryString;
|
|
17
|
-
}
|
|
18
|
-
export default navigateToParams;
|
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Remove URL query parameter, it uses `history`
|
|
3
|
-
*
|
|
4
|
-
* @category location
|
|
5
|
-
* @param replace Replace URL instead of pushing it in the history stack. By default it pushes it.
|
|
6
|
-
*/
|
|
7
|
-
export declare function navigateWithoutUrlParam(paramName?: string, replace?: boolean): string;
|
|
8
|
-
export default navigateWithoutUrlParam;
|
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
import getUrlQueryParams from "./getUrlQueryParams";
|
|
2
|
-
import navigateToParams from "./navigateToParams";
|
|
3
|
-
/**
|
|
4
|
-
* Remove URL query parameter, it uses `history`
|
|
5
|
-
*
|
|
6
|
-
* @category location
|
|
7
|
-
* @param replace Replace URL instead of pushing it in the history stack. By default it pushes it.
|
|
8
|
-
*/
|
|
9
|
-
export function navigateWithoutUrlParam(paramName, replace) {
|
|
10
|
-
var params = {};
|
|
11
|
-
var currentParams = getUrlQueryParams();
|
|
12
|
-
for (var key in currentParams) {
|
|
13
|
-
if (key !== paramName) {
|
|
14
|
-
params[key] = currentParams[key];
|
|
15
|
-
}
|
|
16
|
-
}
|
|
17
|
-
return navigateToParams(params, replace);
|
|
18
|
-
}
|
|
19
|
-
export default navigateWithoutUrlParam;
|
package/pageview.d.ts
DELETED
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
export declare type GtmPageviewArgs = [
|
|
2
|
-
page_path?: string,
|
|
3
|
-
page_title?: string,
|
|
4
|
-
page_location?: string
|
|
5
|
-
];
|
|
6
|
-
/**
|
|
7
|
-
* @category analytics-google
|
|
8
|
-
*/
|
|
9
|
-
export declare const pageview: (page_path?: string | undefined, page_title?: string | undefined, page_location?: string | undefined) => void;
|
package/pageview.js
DELETED
|
@@ -1,29 +0,0 @@
|
|
|
1
|
-
import isUndefined from "./isUndefined";
|
|
2
|
-
/**
|
|
3
|
-
* @category analytics-google
|
|
4
|
-
*/
|
|
5
|
-
export var pageview = function () {
|
|
6
|
-
var args = [];
|
|
7
|
-
for (var _i = 0; _i < arguments.length; _i++) {
|
|
8
|
-
args[_i] = arguments[_i];
|
|
9
|
-
}
|
|
10
|
-
if (!isUndefined(window) && !isUndefined(window.gtag)) {
|
|
11
|
-
window.gtag("event", "page_view", {
|
|
12
|
-
page_path: args[0] || location.pathname,
|
|
13
|
-
page_title: args[1] || document.title,
|
|
14
|
-
page_location: args[2] || location.href,
|
|
15
|
-
// send_to: '<GA_MEASUREMENT_ID>'
|
|
16
|
-
});
|
|
17
|
-
}
|
|
18
|
-
};
|
|
19
|
-
// export type GtmEventArgs = [
|
|
20
|
-
// eventCategory?: string,
|
|
21
|
-
// eventAction?: string,
|
|
22
|
-
// eventLabel?: string,
|
|
23
|
-
// eventValue?: string
|
|
24
|
-
// ];
|
|
25
|
-
// export const event = (...args: GtmEventArgs) => {
|
|
26
|
-
// if (!isUndefined(window) && !isUndefined(window.gtag)) {
|
|
27
|
-
// window.gtag("send", "event", ...args);
|
|
28
|
-
// }
|
|
29
|
-
// };
|
package/redirectTo.d.ts
DELETED
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
import { type AnyQueryParams } from "./location";
|
|
2
|
-
/**
|
|
3
|
-
* Redirect to url with params {optionally}, removes eventual trailing question
|
|
4
|
-
* marks from the given URL, it uses `location`
|
|
5
|
-
*
|
|
6
|
-
* @category location
|
|
7
|
-
*/
|
|
8
|
-
export declare function redirectTo(url: string, params?: AnyQueryParams): void;
|
|
9
|
-
export default redirectTo;
|
package/redirectTo.js
DELETED
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
import buildUrlQueryString from "./buildUrlQueryString";
|
|
2
|
-
import isBrowser from "./isBrowser";
|
|
3
|
-
/**
|
|
4
|
-
* Redirect to url with params {optionally}, removes eventual trailing question
|
|
5
|
-
* marks from the given URL, it uses `location`
|
|
6
|
-
*
|
|
7
|
-
* @category location
|
|
8
|
-
*/
|
|
9
|
-
export function redirectTo(url, params) {
|
|
10
|
-
if (isBrowser) {
|
|
11
|
-
var queryString = buildUrlQueryString(params);
|
|
12
|
-
location.href = url.replace(/\?+$/g, "") + queryString;
|
|
13
|
-
}
|
|
14
|
-
}
|
|
15
|
-
export default redirectTo;
|