@koine/utils 1.0.104 → 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.
Files changed (60) hide show
  1. package/Defer.d.ts +1 -1
  2. package/README.md +3 -0
  3. package/accentSets.d.ts +1 -1
  4. package/areEqual.d.ts +19 -0
  5. package/areEqual.js +77 -0
  6. package/cookie.d.ts +3 -3
  7. package/forin.d.ts +7 -0
  8. package/forin.js +11 -0
  9. package/gbToBytes.d.ts +7 -0
  10. package/gbToBytes.js +7 -0
  11. package/getMediaQueryWidthResolvers.d.ts +1 -1
  12. package/getType.d.ts +5 -5
  13. package/index.d.ts +8 -0
  14. package/index.js +8 -0
  15. package/kbToBytes.d.ts +7 -0
  16. package/kbToBytes.js +7 -0
  17. package/location.d.ts +1 -1
  18. package/matchSorter.d.ts +3 -3
  19. package/mbToBytes.d.ts +7 -0
  20. package/mbToBytes.js +7 -0
  21. package/node/areEqual.js +81 -0
  22. package/node/forin.js +15 -0
  23. package/node/gbToBytes.js +11 -0
  24. package/node/index.js +8 -0
  25. package/node/kbToBytes.js +11 -0
  26. package/node/mbToBytes.js +11 -0
  27. package/node/noop.js +11 -0
  28. package/node/quaranteneProps.js +37 -0
  29. package/node/uuidNumeric.js +10 -0
  30. package/noop.d.ts +7 -0
  31. package/noop.js +7 -0
  32. package/package.json +8 -8
  33. package/quaranteneProps.d.ts +22 -0
  34. package/quaranteneProps.js +33 -0
  35. package/uuidNumeric.d.ts +6 -0
  36. package/uuidNumeric.js +6 -0
  37. package/createStorage.d.ts +0 -53
  38. package/createStorage.js +0 -137
  39. package/getZonedDate.d.ts +0 -16
  40. package/getZonedDate.js +0 -37
  41. package/isIE.d.ts +0 -7
  42. package/isIE.js +0 -18
  43. package/isMobile.d.ts +0 -7
  44. package/isMobile.js +0 -16
  45. package/navigateToHash.d.ts +0 -8
  46. package/navigateToHash.js +0 -12
  47. package/navigateToHashParams.d.ts +0 -9
  48. package/navigateToHashParams.js +0 -22
  49. package/navigateToMergedHashParams.d.ts +0 -8
  50. package/navigateToMergedHashParams.js +0 -14
  51. package/navigateToMergedParams.d.ts +0 -9
  52. package/navigateToMergedParams.js +0 -14
  53. package/navigateToParams.d.ts +0 -10
  54. package/navigateToParams.js +0 -18
  55. package/navigateWithoutUrlParam.d.ts +0 -8
  56. package/navigateWithoutUrlParam.js +0 -19
  57. package/pageview.d.ts +0 -9
  58. package/pageview.js +0 -29
  59. package/redirectTo.d.ts +0 -9
  60. package/redirectTo.js +0 -15
package/package.json CHANGED
@@ -2,13 +2,13 @@
2
2
  "name": "@koine/utils",
3
3
  "sideEffects": false,
4
4
  "main": "./node/index.js",
5
- "typings": "./index.d.ts",
6
- "dependencies": {
7
- "ts-debounce": "^4.0.0",
8
- "tslib": "^2.4.0"
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
- "peerDependencies": {},
11
- "version": "1.0.104",
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;
@@ -0,0 +1,6 @@
1
+ /**
2
+ * @category uid
3
+ * @see https://stackoverflow.com/a/18048162/1938970
4
+ */
5
+ export declare const uuidNumeric: () => number;
6
+ export default uuidNumeric;
package/uuidNumeric.js ADDED
@@ -0,0 +1,6 @@
1
+ /**
2
+ * @category uid
3
+ * @see https://stackoverflow.com/a/18048162/1938970
4
+ */
5
+ export var uuidNumeric = function () { return new Date().valueOf(); };
6
+ export default uuidNumeric;
@@ -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
@@ -1,7 +0,0 @@
1
- /**
2
- * @category detect
3
- * @category is
4
- * @see https://stackoverflow.com/a/21712356/12285349
5
- */
6
- export declare function isIE(ssrValue?: boolean): boolean;
7
- export default isIE;
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
@@ -1,7 +0,0 @@
1
- /**
2
- * @category detect
3
- * @category is
4
- * @see https://stackoverflow.com/a/3540295
5
- */
6
- export declare function isMobile(ssrValue?: boolean): boolean;
7
- export default isMobile;
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;
@@ -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;
@@ -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;
@@ -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;
@@ -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;