@wikicasa-dev/utilities 1.2.5 → 1.2.7
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/dist/index.js +65 -64
- package/dist/utils/ObjectUtils.d.ts +49 -0
- package/dist/utils/ObjectUtils.js +36 -22
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -1,57 +1,58 @@
|
|
|
1
1
|
import { isArrNullOrEmpty as r } from "./utils/ArrayUtils.js";
|
|
2
2
|
import { rgba as a } from "./utils/ColorUtils.js";
|
|
3
|
-
import { decodeCookie as i, encodeCookie as l, getCookie as
|
|
3
|
+
import { decodeCookie as i, encodeCookie as l, getCookie as p, removeCookie as n } from "./utils/CookieUtils.js";
|
|
4
4
|
import { formatCurrency as E, formatCurrencyShort as f } from "./utils/CurrencyUtils.js";
|
|
5
5
|
import { formatDate as d, formatDateToddMMYYYY as u, getStartAndEndOfDayUTC as x, subtractDaysFromDate as g } from "./utils/DateUtils.js";
|
|
6
|
-
import { getCurrentDeviceSize as O, isMobile as C, isSafari as
|
|
6
|
+
import { getCurrentDeviceSize as O, isMobile as C, isSafari as y, isWindows as P, isiOSDevice as S } from "./utils/DeviceDetectionUtils.js";
|
|
7
7
|
import { emptyElem as L, getSingleElement as R, hideElem as T, showElem as D } from "./utils/DOMUtils.js";
|
|
8
|
-
import { hash256 as
|
|
9
|
-
import { debounce as
|
|
8
|
+
import { hash256 as h, hashEmail as G } from "./utils/EmailUtils.js";
|
|
9
|
+
import { debounce as X, isPromise as M } from "./utils/FunctionUtils.js";
|
|
10
10
|
import { awaitableSetTimeout as I, createCustomEvent as w } from "./utils/GenericUtils.js";
|
|
11
11
|
import { formatFloat as k, formatInteger as F, formatLocaleNumber as U, formatLocaleNumberAuto as Y, formatNumber as H, formatterNumberObj as W, parseLocaleNumber as z, parseLocaleNumberAuto as Q } from "./utils/NumberUtils.js";
|
|
12
|
-
import {
|
|
13
|
-
import { observeOnce as
|
|
14
|
-
import { addPermissionStateListener as
|
|
15
|
-
import { buildParams as ne, buildURL as
|
|
16
|
-
import { capitalizeFirstLetter as
|
|
17
|
-
import { appendQueryString as
|
|
18
|
-
import { COMPETITOR_REGEX as
|
|
19
|
-
import { browserSupportGeolocation as Xe, getUserPosition as
|
|
20
|
-
import { formatAddress as
|
|
21
|
-
import { googlePlaceConverter as
|
|
22
|
-
import { downloadFile as
|
|
23
|
-
import { calcPolygonCenter as
|
|
12
|
+
import { applyMergePatch as B, areObjectsEqual as K, deepCopy as V, getOrDefault as J, getOrNull as Z, invertFlatObject as $, invertKeyToValue as ee, isEmptyObject as oe, shallowCopyObjectTo as re } from "./utils/ObjectUtils.js";
|
|
13
|
+
import { observeOnce as ae } from "./utils/ObserverUtils.js";
|
|
14
|
+
import { addPermissionStateListener as ie, onNotificationsPermissionChange as le } from "./utils/PermissionUtils.js";
|
|
15
|
+
import { buildParams as ne, buildURL as se } from "./utils/RESB_UrlBuilder.js";
|
|
16
|
+
import { capitalizeFirstLetter as fe, cleanASCII as ce, decodeTextWithEntities as de, replaceAll as ue, replaceAllTokens as xe, stringToHyphened as ge, strip as be } from "./utils/StringUtils.js";
|
|
17
|
+
import { appendQueryString as Ce } from "./utils/URLBuilderUtils.js";
|
|
18
|
+
import { COMPETITOR_REGEX as Pe, DATE_REGEX as Se, EMAIL_REGEX as Ae, EMAIL_REGEX_INTO_TEXT as Le, EXCLUDED_REGEX as Re, GLOBAL_PHONE_REGEX as Te, PASSWORD_REGEX as De, PHONE_REGEX as _e, ROOMS_REGEX as he, SQM_REGEX as Ge } from "./utils/RegexUtils.js";
|
|
19
|
+
import { browserSupportGeolocation as Xe, getUserPosition as Me } from "./utils/GeolocationUtils.js";
|
|
20
|
+
import { formatAddress as Ie, formattedAddress as we } from "./utils/AdressUtils.js";
|
|
21
|
+
import { googlePlaceConverter as ke } from "./utils/GAutocompleteUtils.js";
|
|
22
|
+
import { downloadFile as Ue } from "./utils/DownloadUtils.js";
|
|
23
|
+
import { calcPolygonCenter as He, encodePolygon as We, getMinMaxLatLng as ze, getPolygonString as Qe, parsePoints as qe, removeDuplicatePoints as Be } from "./utils/MapUtils.js";
|
|
24
24
|
export {
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
25
|
+
Pe as COMPETITOR_REGEX,
|
|
26
|
+
Se as DATE_REGEX,
|
|
27
|
+
Ae as EMAIL_REGEX,
|
|
28
|
+
Le as EMAIL_REGEX_INTO_TEXT,
|
|
29
|
+
Re as EXCLUDED_REGEX,
|
|
30
|
+
Te as GLOBAL_PHONE_REGEX,
|
|
31
|
+
De as PASSWORD_REGEX,
|
|
32
|
+
_e as PHONE_REGEX,
|
|
33
|
+
he as ROOMS_REGEX,
|
|
34
34
|
Ge as SQM_REGEX,
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
B as
|
|
35
|
+
ie as addPermissionStateListener,
|
|
36
|
+
Ce as appendQueryString,
|
|
37
|
+
B as applyMergePatch,
|
|
38
|
+
K as areObjectsEqual,
|
|
38
39
|
I as awaitableSetTimeout,
|
|
39
40
|
Xe as browserSupportGeolocation,
|
|
40
41
|
ne as buildParams,
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
42
|
+
se as buildURL,
|
|
43
|
+
He as calcPolygonCenter,
|
|
44
|
+
fe as capitalizeFirstLetter,
|
|
45
|
+
ce as cleanASCII,
|
|
45
46
|
w as createCustomEvent,
|
|
46
|
-
|
|
47
|
+
X as debounce,
|
|
47
48
|
i as decodeCookie,
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
49
|
+
de as decodeTextWithEntities,
|
|
50
|
+
V as deepCopy,
|
|
51
|
+
Ue as downloadFile,
|
|
51
52
|
L as emptyElem,
|
|
52
53
|
l as encodeCookie,
|
|
53
|
-
|
|
54
|
-
|
|
54
|
+
We as encodePolygon,
|
|
55
|
+
Ie as formatAddress,
|
|
55
56
|
E as formatCurrency,
|
|
56
57
|
f as formatCurrencyShort,
|
|
57
58
|
d as formatDate,
|
|
@@ -61,43 +62,43 @@ export {
|
|
|
61
62
|
U as formatLocaleNumber,
|
|
62
63
|
Y as formatLocaleNumberAuto,
|
|
63
64
|
H as formatNumber,
|
|
64
|
-
|
|
65
|
+
we as formattedAddress,
|
|
65
66
|
W as formatterNumberObj,
|
|
66
|
-
|
|
67
|
+
p as getCookie,
|
|
67
68
|
O as getCurrentDeviceSize,
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
69
|
+
ze as getMinMaxLatLng,
|
|
70
|
+
J as getOrDefault,
|
|
71
|
+
Z as getOrNull,
|
|
72
|
+
Qe as getPolygonString,
|
|
72
73
|
R as getSingleElement,
|
|
73
74
|
x as getStartAndEndOfDayUTC,
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
75
|
+
Me as getUserPosition,
|
|
76
|
+
ke as googlePlaceConverter,
|
|
77
|
+
h as hash256,
|
|
78
|
+
G as hashEmail,
|
|
78
79
|
T as hideElem,
|
|
79
|
-
|
|
80
|
-
|
|
80
|
+
$ as invertFlatObject,
|
|
81
|
+
ee as invertKeyToValue,
|
|
81
82
|
r as isArrNullOrEmpty,
|
|
82
|
-
|
|
83
|
+
oe as isEmptyObject,
|
|
83
84
|
C as isMobile,
|
|
84
85
|
M as isPromise,
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
86
|
+
y as isSafari,
|
|
87
|
+
P as isWindows,
|
|
88
|
+
S as isiOSDevice,
|
|
89
|
+
ae as observeOnce,
|
|
90
|
+
le as onNotificationsPermissionChange,
|
|
90
91
|
z as parseLocaleNumber,
|
|
91
92
|
Q as parseLocaleNumberAuto,
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
93
|
+
qe as parsePoints,
|
|
94
|
+
n as removeCookie,
|
|
95
|
+
Be as removeDuplicatePoints,
|
|
96
|
+
ue as replaceAll,
|
|
97
|
+
xe as replaceAllTokens,
|
|
97
98
|
a as rgba,
|
|
98
|
-
|
|
99
|
+
re as shallowCopyObjectTo,
|
|
99
100
|
D as showElem,
|
|
100
|
-
|
|
101
|
-
|
|
101
|
+
ge as stringToHyphened,
|
|
102
|
+
be as strip,
|
|
102
103
|
g as subtractDaysFromDate
|
|
103
104
|
};
|
|
@@ -1,5 +1,14 @@
|
|
|
1
1
|
import { Nullable, Optional } from '@wikicasa-dev/types';
|
|
2
2
|
import { FlatInvert, InvertKeyToValue } from '../types/ObjectUtilsTypes';
|
|
3
|
+
export type JsonValue = string | number | boolean | null | JsonValue[] | {
|
|
4
|
+
[key: string]: JsonValue;
|
|
5
|
+
};
|
|
6
|
+
export type JsonObject = {
|
|
7
|
+
[key: string]: JsonValue;
|
|
8
|
+
};
|
|
9
|
+
export type MergePatch<T> = T extends JsonValue[] ? T : T extends object ? {
|
|
10
|
+
[K in keyof T]?: MergePatch<T[K]> | null;
|
|
11
|
+
} : T;
|
|
3
12
|
export declare function shallowCopyObjectTo(from: Record<string, any> | undefined, to: Record<string, any>): void;
|
|
4
13
|
/**
|
|
5
14
|
* Checks if the given object is empty.
|
|
@@ -58,3 +67,43 @@ export declare const getOrDefault: <T>(value: T, defaultValue: NonNullable<T>) =
|
|
|
58
67
|
* @returns Returns true if the objects are deeply equal, false otherwise.
|
|
59
68
|
*/
|
|
60
69
|
export declare const areObjectsEqual: (obj1?: object, obj2?: object) => boolean;
|
|
70
|
+
/**
|
|
71
|
+
* Applies a JSON Merge Patch (RFC 7396) to a source JSON object.
|
|
72
|
+
*
|
|
73
|
+
* This function performs a deep, recursive merge between `source` and `patch`
|
|
74
|
+
* following the JSON Merge Patch specification:
|
|
75
|
+
*
|
|
76
|
+
* - Objects are merged recursively.
|
|
77
|
+
* - Arrays are replaced (not merged).
|
|
78
|
+
* - Primitive values are replaced.
|
|
79
|
+
* - `null` values in the patch explicitly remove the property.
|
|
80
|
+
*
|
|
81
|
+
* ### Example
|
|
82
|
+
* ```ts
|
|
83
|
+
* const source = {
|
|
84
|
+
* a: 1,
|
|
85
|
+
* b: { c: 2, d: 3 },
|
|
86
|
+
* };
|
|
87
|
+
*
|
|
88
|
+
* const patch = {
|
|
89
|
+
* a: null,
|
|
90
|
+
* b: { d: 4 },
|
|
91
|
+
* };
|
|
92
|
+
*
|
|
93
|
+
* const result = applyMergePatch(source, patch);
|
|
94
|
+
* // {
|
|
95
|
+
* // b: { c: 2, d: 4 }
|
|
96
|
+
* // }
|
|
97
|
+
* ```
|
|
98
|
+
*
|
|
99
|
+
* ### Notes
|
|
100
|
+
* - Only JSON-compatible values are supported.
|
|
101
|
+
* - The function does not mutate the input objects.
|
|
102
|
+
* - Non-object values (including arrays) are replaced entirely.
|
|
103
|
+
*
|
|
104
|
+
* @template T - Source object type
|
|
105
|
+
* @param source - The original JSON object to apply the patch to.
|
|
106
|
+
* @param patch - The JSON Merge Patch object describing changes.
|
|
107
|
+
* @returns A new object resulting from applying the patch.
|
|
108
|
+
*/
|
|
109
|
+
export declare const applyMergePatch: <T extends JsonObject>(source: T, patch: MergePatch<T>) => T;
|
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
function
|
|
1
|
+
function u(e, t) {
|
|
2
2
|
if (e)
|
|
3
3
|
for (const r in e)
|
|
4
4
|
t[r] = e[r];
|
|
5
5
|
}
|
|
6
|
-
const
|
|
7
|
-
function
|
|
6
|
+
const y = (e) => !e || !Object.keys(e).length;
|
|
7
|
+
function a(e) {
|
|
8
8
|
if (!e) return null;
|
|
9
9
|
for (const t in e) {
|
|
10
10
|
const r = e[t];
|
|
@@ -13,35 +13,49 @@ function f(e) {
|
|
|
13
13
|
}
|
|
14
14
|
return { ...e };
|
|
15
15
|
}
|
|
16
|
-
const
|
|
17
|
-
(t, [r,
|
|
16
|
+
const O = (e) => Object.entries(e).reduce(
|
|
17
|
+
(t, [r, n]) => (t[n] = r, t),
|
|
18
18
|
{}
|
|
19
|
-
),
|
|
19
|
+
), g = (e) => Object.keys(e).reduce(
|
|
20
20
|
(t, r) => (t[r] = r, t),
|
|
21
21
|
{}
|
|
22
|
-
),
|
|
22
|
+
), p = (e) => e ?? null, d = (e, t) => e ?? t, c = (e = {}, t = {}) => {
|
|
23
23
|
if (e === null || t === null || e === void 0 || t === void 0 || typeof e != "object" && typeof t != "object")
|
|
24
24
|
return e === t;
|
|
25
25
|
if (e instanceof Date && t instanceof Date)
|
|
26
26
|
return e.getTime() === t.getTime();
|
|
27
27
|
if (Array.isArray(e) && Array.isArray(t))
|
|
28
|
-
return e.length !== t.length ? !1 : e.every((
|
|
28
|
+
return e.length !== t.length ? !1 : e.every((s, i) => c(s, t[i]));
|
|
29
29
|
if (typeof e != typeof t) return !1;
|
|
30
|
-
const r = Object.keys(e),
|
|
31
|
-
return r.length !==
|
|
32
|
-
(
|
|
33
|
-
e[
|
|
34
|
-
t[
|
|
30
|
+
const r = Object.keys(e), n = Object.keys(t);
|
|
31
|
+
return r.length !== n.length ? !1 : r.every(
|
|
32
|
+
(s) => Object.prototype.hasOwnProperty.call(t, s) && c(
|
|
33
|
+
e[s],
|
|
34
|
+
t[s]
|
|
35
35
|
)
|
|
36
36
|
);
|
|
37
|
-
};
|
|
37
|
+
}, l = (e) => e !== null && typeof e == "object" && !Array.isArray(e);
|
|
38
|
+
function f(e, t) {
|
|
39
|
+
if (t === null)
|
|
40
|
+
return;
|
|
41
|
+
if (!l(e) || !l(t))
|
|
42
|
+
return t;
|
|
43
|
+
const r = { ...e };
|
|
44
|
+
for (const n of Object.keys(t)) {
|
|
45
|
+
const s = t[n], i = f(e[n], s);
|
|
46
|
+
i === void 0 ? delete r[n] : r[n] = i;
|
|
47
|
+
}
|
|
48
|
+
return r;
|
|
49
|
+
}
|
|
50
|
+
const k = (e, t) => f(e, t);
|
|
38
51
|
export {
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
52
|
+
k as applyMergePatch,
|
|
53
|
+
c as areObjectsEqual,
|
|
54
|
+
a as deepCopy,
|
|
55
|
+
d as getOrDefault,
|
|
56
|
+
p as getOrNull,
|
|
57
|
+
O as invertFlatObject,
|
|
58
|
+
g as invertKeyToValue,
|
|
59
|
+
y as isEmptyObject,
|
|
60
|
+
u as shallowCopyObjectTo
|
|
47
61
|
};
|