@wikicasa-dev/utilities 1.2.4 → 1.2.6

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 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 n, removeCookie as p } from "./utils/CookieUtils.js";
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 S, isWindows as y, isiOSDevice as P } from "./utils/DeviceDetectionUtils.js";
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 G, hashEmail as N } from "./utils/EmailUtils.js";
9
- import { debounce as h, isPromise as M } from "./utils/FunctionUtils.js";
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 { areObjectsEqual as B, deepCopy as K, getOrDefault as V, getOrNull as J, invertFlatObject as Z, invertKeyToValue as $, isEmptyObject as ee, shallowCopyObjectTo as oe } from "./utils/ObjectUtils.js";
13
- import { observeOnce as te } from "./utils/ObserverUtils.js";
14
- import { addPermissionStateListener as me, onNotificationsPermissionChange as ie } from "./utils/PermissionUtils.js";
15
- import { buildParams as ne, buildURL as pe } from "./utils/RESB_UrlBuilder.js";
16
- import { capitalizeFirstLetter as Ee, cleanASCII as fe, decodeTextWithEntities as ce, replaceAll as de, replaceAllTokens as ue, stringToHyphened as xe, strip as ge } from "./utils/StringUtils.js";
17
- import { appendQueryString as Oe } from "./utils/URLBuilderUtils.js";
18
- import { COMPETITOR_REGEX as Se, DATE_REGEX as ye, EMAIL_REGEX as Pe, EMAIL_REGEX_INTO_TEXT as Ae, EXCLUDED_REGEX as Le, GLOBAL_PHONE_REGEX as Re, PASSWORD_REGEX as Te, PHONE_REGEX as De, ROOMS_REGEX as _e, SQM_REGEX as Ge } from "./utils/RegexUtils.js";
19
- import { browserSupportGeolocation as Xe, getUserPosition as he } from "./utils/GeolocationUtils.js";
20
- import { formatAddress as ve, formattedAddress as Ie } from "./utils/AdressUtils.js";
21
- import { googlePlaceConverter as je } from "./utils/GAutocompleteUtils.js";
22
- import { downloadFile as Fe } from "./utils/DownloadUtils.js";
23
- import { calcPolygonCenter as Ye, encodePolygon as He, getMinMaxLatLng as We, getPolygonString as ze, parsePoints as Qe, removeDuplicatePoints as qe } from "./utils/MapUtils.js";
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
- Se as COMPETITOR_REGEX,
26
- ye as DATE_REGEX,
27
- Pe as EMAIL_REGEX,
28
- Ae as EMAIL_REGEX_INTO_TEXT,
29
- Le as EXCLUDED_REGEX,
30
- Re as GLOBAL_PHONE_REGEX,
31
- Te as PASSWORD_REGEX,
32
- De as PHONE_REGEX,
33
- _e as ROOMS_REGEX,
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
- me as addPermissionStateListener,
36
- Oe as appendQueryString,
37
- B as areObjectsEqual,
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
- pe as buildURL,
42
- Ye as calcPolygonCenter,
43
- Ee as capitalizeFirstLetter,
44
- fe as cleanASCII,
42
+ se as buildURL,
43
+ He as calcPolygonCenter,
44
+ fe as capitalizeFirstLetter,
45
+ ce as cleanASCII,
45
46
  w as createCustomEvent,
46
- h as debounce,
47
+ X as debounce,
47
48
  i as decodeCookie,
48
- ce as decodeTextWithEntities,
49
- K as deepCopy,
50
- Fe as downloadFile,
49
+ de as decodeTextWithEntities,
50
+ V as deepCopy,
51
+ Ue as downloadFile,
51
52
  L as emptyElem,
52
53
  l as encodeCookie,
53
- He as encodePolygon,
54
- ve as formatAddress,
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
- Ie as formattedAddress,
65
+ we as formattedAddress,
65
66
  W as formatterNumberObj,
66
- n as getCookie,
67
+ p as getCookie,
67
68
  O as getCurrentDeviceSize,
68
- We as getMinMaxLatLng,
69
- V as getOrDefault,
70
- J as getOrNull,
71
- ze as getPolygonString,
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
- he as getUserPosition,
75
- je as googlePlaceConverter,
76
- G as hash256,
77
- N as hashEmail,
75
+ Me as getUserPosition,
76
+ ke as googlePlaceConverter,
77
+ h as hash256,
78
+ G as hashEmail,
78
79
  T as hideElem,
79
- Z as invertFlatObject,
80
- $ as invertKeyToValue,
80
+ $ as invertFlatObject,
81
+ ee as invertKeyToValue,
81
82
  r as isArrNullOrEmpty,
82
- ee as isEmptyObject,
83
+ oe as isEmptyObject,
83
84
  C as isMobile,
84
85
  M as isPromise,
85
- S as isSafari,
86
- y as isWindows,
87
- P as isiOSDevice,
88
- te as observeOnce,
89
- ie as onNotificationsPermissionChange,
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
- Qe as parsePoints,
93
- p as removeCookie,
94
- qe as removeDuplicatePoints,
95
- de as replaceAll,
96
- ue as replaceAllTokens,
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
- oe as shallowCopyObjectTo,
99
+ re as shallowCopyObjectTo,
99
100
  D as showElem,
100
- xe as stringToHyphened,
101
- ge as strip,
101
+ ge as stringToHyphened,
102
+ be as strip,
102
103
  g as subtractDaysFromDate
103
104
  };
@@ -1,5 +1,22 @@
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
+ /**
10
+ * Recursive JSON Merge Patch type (RFC 7396).
11
+ *
12
+ * Key idea:
13
+ * - `null` = delete field
14
+ * - object = recurse
15
+ * - other values = replace
16
+ */
17
+ export type JsonMergePatch<T> = T extends JsonValue[] ? JsonValue[] : T extends object ? {
18
+ [K in keyof T]?: JsonMergePatch<T[K]> | null;
19
+ } : T;
3
20
  export declare function shallowCopyObjectTo(from: Record<string, any> | undefined, to: Record<string, any>): void;
4
21
  /**
5
22
  * Checks if the given object is empty.
@@ -58,3 +75,43 @@ export declare const getOrDefault: <T>(value: T, defaultValue: NonNullable<T>) =
58
75
  * @returns Returns true if the objects are deeply equal, false otherwise.
59
76
  */
60
77
  export declare const areObjectsEqual: (obj1?: object, obj2?: object) => boolean;
78
+ /**
79
+ * Applies a JSON Merge Patch (RFC 7396) to a source JSON object.
80
+ *
81
+ * This function performs a deep, recursive merge between `source` and `patch`
82
+ * following the JSON Merge Patch specification:
83
+ *
84
+ * - Objects are merged recursively.
85
+ * - Arrays are replaced (not merged).
86
+ * - Primitive values are replaced.
87
+ * - `null` values in the patch explicitly remove the property.
88
+ *
89
+ * ### Example
90
+ * ```ts
91
+ * const source = {
92
+ * a: 1,
93
+ * b: { c: 2, d: 3 },
94
+ * };
95
+ *
96
+ * const patch = {
97
+ * a: null,
98
+ * b: { d: 4 },
99
+ * };
100
+ *
101
+ * const result = applyMergePatch(source, patch);
102
+ * // {
103
+ * // b: { c: 2, d: 4 }
104
+ * // }
105
+ * ```
106
+ *
107
+ * ### Notes
108
+ * - Only JSON-compatible values are supported.
109
+ * - The function does not mutate the input objects.
110
+ * - Non-object values (including arrays) are replaced entirely.
111
+ *
112
+ * @template T - Source object type
113
+ * @param source - The original JSON object to apply the patch to.
114
+ * @param patch - The JSON Merge Patch object describing changes.
115
+ * @returns A new object resulting from applying the patch.
116
+ */
117
+ export declare function applyMergePatch<T extends JsonObject>(source: T, patch: JsonMergePatch<T>): T;
@@ -1,10 +1,10 @@
1
- function l(e, t) {
1
+ function f(e, t) {
2
2
  if (e)
3
3
  for (const r in e)
4
4
  t[r] = e[r];
5
5
  }
6
- const u = (e) => !e || !Object.keys(e).length;
7
- function f(e) {
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,50 @@ function f(e) {
13
13
  }
14
14
  return { ...e };
15
15
  }
16
- const y = (e) => Object.entries(e).reduce(
17
- (t, [r, s]) => (t[s] = r, t),
16
+ const O = (e) => Object.entries(e).reduce(
17
+ (t, [r, n]) => (t[n] = r, t),
18
18
  {}
19
- ), a = (e) => Object.keys(e).reduce(
19
+ ), g = (e) => Object.keys(e).reduce(
20
20
  (t, r) => (t[r] = r, t),
21
21
  {}
22
- ), O = (e) => e ?? null, g = (e, t) => e ?? t, i = (e = {}, t = {}) => {
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((n, c) => i(n, t[c]));
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), s = Object.keys(t);
31
- return r.length !== s.length ? !1 : r.every(
32
- (n) => Object.prototype.hasOwnProperty.call(t, n) && i(
33
- e[n],
34
- t[n]
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
+ }, l = (e) => e !== null && typeof e == "object" && !Array.isArray(e), u = (e, t) => {
38
+ if (t === null)
39
+ return;
40
+ if (!l(e) || !l(t))
41
+ return t;
42
+ const r = { ...e };
43
+ for (const n of Object.keys(t)) {
44
+ const s = t[n], i = u(e[n], s);
45
+ i === void 0 ? delete r[n] : r[n] = i;
46
+ }
47
+ return r;
37
48
  };
49
+ function k(e, t) {
50
+ return u(e, t);
51
+ }
38
52
  export {
39
- i as areObjectsEqual,
40
- f as deepCopy,
41
- g as getOrDefault,
42
- O as getOrNull,
43
- y as invertFlatObject,
44
- a as invertKeyToValue,
45
- u as isEmptyObject,
46
- l as shallowCopyObjectTo
53
+ k as applyMergePatch,
54
+ c as areObjectsEqual,
55
+ a as deepCopy,
56
+ d as getOrDefault,
57
+ p as getOrNull,
58
+ O as invertFlatObject,
59
+ g as invertKeyToValue,
60
+ y as isEmptyObject,
61
+ f as shallowCopyObjectTo
47
62
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@wikicasa-dev/utilities",
3
- "version": "1.2.4",
3
+ "version": "1.2.6",
4
4
  "description": "Wikicasa frontend utilities",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",
@@ -35,7 +35,7 @@
35
35
  "@types/js-cookie": "^3.0.6",
36
36
  "@types/leaflet": "^1.9.21",
37
37
  "@types/node": "^25.9.1",
38
- "@wikicasa-dev/types": "2.5.8-alpha.1",
38
+ "@wikicasa-dev/types": "^2.5.8",
39
39
  "glob": "^13.0.6",
40
40
  "jest-environment-jsdom": "^30.4.1",
41
41
  "ts-jest": "^29.4.11",
@@ -44,7 +44,7 @@
44
44
  "vite": "^7.2.6"
45
45
  },
46
46
  "peerDependencies": {
47
- "@wikicasa-dev/types": "2.5.8-alpha.1",
47
+ "@wikicasa-dev/types": "2.5.8",
48
48
  "date-fns": "^4.0.0",
49
49
  "google-polyline": "^1.0.0",
50
50
  "js-cookie": "^3.0.0"