@wikicasa-dev/utilities 1.2.8 → 1.2.10

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
@@ -3,53 +3,52 @@ import { rgba as a } from "./utils/ColorUtils.js";
3
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 y, isWindows as P, isiOSDevice as S } from "./utils/DeviceDetectionUtils.js";
7
- import { emptyElem as L, getSingleElement as R, hideElem as T, showElem as D } from "./utils/DOMUtils.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";
6
+ import { getCurrentDeviceSize as O, isMobile as C, isSafari as S, isWindows as y, isiOSDevice as P } from "./utils/DeviceDetectionUtils.js";
7
+ import { emptyElem as D, getSingleElement as L, hideElem as R, showElem as T } 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";
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 { 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";
12
+ import { areObjectsEqual as B, deepCopy as K, getOrDefault as V, getOrNull as J, invertFlatObject as Z, invertKeyToValue as $, isEmptyObject as ee, mergeDeep as oe, shallowCopyObjectTo as re } from "./utils/ObjectUtils.js";
13
13
  import { observeOnce as ae } from "./utils/ObserverUtils.js";
14
14
  import { addPermissionStateListener as ie, onNotificationsPermissionChange as le } from "./utils/PermissionUtils.js";
15
15
  import { buildParams as ne, buildURL as se } from "./utils/RESB_UrlBuilder.js";
16
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
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";
18
+ import { COMPETITOR_REGEX as ye, DATE_REGEX as Pe, EMAIL_REGEX as Ae, EMAIL_REGEX_INTO_TEXT as De, EXCLUDED_REGEX as Le, GLOBAL_PHONE_REGEX as Re, PASSWORD_REGEX as Te, PHONE_REGEX as _e, ROOMS_REGEX as Ge, SQM_REGEX as Ne } from "./utils/RegexUtils.js";
19
+ import { browserSupportGeolocation as he, getUserPosition as Me } from "./utils/GeolocationUtils.js";
20
20
  import { formatAddress as Ie, formattedAddress as we } from "./utils/AdressUtils.js";
21
21
  import { googlePlaceConverter as ke } from "./utils/GAutocompleteUtils.js";
22
22
  import { downloadFile as Ue } from "./utils/DownloadUtils.js";
23
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
- Pe as COMPETITOR_REGEX,
26
- Se as DATE_REGEX,
25
+ ye as COMPETITOR_REGEX,
26
+ Pe as DATE_REGEX,
27
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,
28
+ De as EMAIL_REGEX_INTO_TEXT,
29
+ Le as EXCLUDED_REGEX,
30
+ Re as GLOBAL_PHONE_REGEX,
31
+ Te as PASSWORD_REGEX,
32
32
  _e as PHONE_REGEX,
33
- he as ROOMS_REGEX,
34
- Ge as SQM_REGEX,
33
+ Ge as ROOMS_REGEX,
34
+ Ne as SQM_REGEX,
35
35
  ie as addPermissionStateListener,
36
36
  Ce as appendQueryString,
37
- B as applyMergePatch,
38
- K as areObjectsEqual,
37
+ B as areObjectsEqual,
39
38
  I as awaitableSetTimeout,
40
- Xe as browserSupportGeolocation,
39
+ he as browserSupportGeolocation,
41
40
  ne as buildParams,
42
41
  se as buildURL,
43
42
  He as calcPolygonCenter,
44
43
  fe as capitalizeFirstLetter,
45
44
  ce as cleanASCII,
46
45
  w as createCustomEvent,
47
- X as debounce,
46
+ h as debounce,
48
47
  i as decodeCookie,
49
48
  de as decodeTextWithEntities,
50
- V as deepCopy,
49
+ K as deepCopy,
51
50
  Ue as downloadFile,
52
- L as emptyElem,
51
+ D as emptyElem,
53
52
  l as encodeCookie,
54
53
  We as encodePolygon,
55
54
  Ie as formatAddress,
@@ -67,25 +66,26 @@ export {
67
66
  p as getCookie,
68
67
  O as getCurrentDeviceSize,
69
68
  ze as getMinMaxLatLng,
70
- J as getOrDefault,
71
- Z as getOrNull,
69
+ V as getOrDefault,
70
+ J as getOrNull,
72
71
  Qe as getPolygonString,
73
- R as getSingleElement,
72
+ L as getSingleElement,
74
73
  x as getStartAndEndOfDayUTC,
75
74
  Me as getUserPosition,
76
75
  ke as googlePlaceConverter,
77
- h as hash256,
78
- G as hashEmail,
79
- T as hideElem,
80
- $ as invertFlatObject,
81
- ee as invertKeyToValue,
76
+ G as hash256,
77
+ N as hashEmail,
78
+ R as hideElem,
79
+ Z as invertFlatObject,
80
+ $ as invertKeyToValue,
82
81
  r as isArrNullOrEmpty,
83
- oe as isEmptyObject,
82
+ ee as isEmptyObject,
84
83
  C as isMobile,
85
84
  M as isPromise,
86
- y as isSafari,
87
- P as isWindows,
88
- S as isiOSDevice,
85
+ S as isSafari,
86
+ y as isWindows,
87
+ P as isiOSDevice,
88
+ oe as mergeDeep,
89
89
  ae as observeOnce,
90
90
  le as onNotificationsPermissionChange,
91
91
  z as parseLocaleNumber,
@@ -97,7 +97,7 @@ export {
97
97
  xe as replaceAllTokens,
98
98
  a as rgba,
99
99
  re as shallowCopyObjectTo,
100
- D as showElem,
100
+ T as showElem,
101
101
  ge as stringToHyphened,
102
102
  be as strip,
103
103
  g as subtractDaysFromDate
@@ -1,12 +1,8 @@
1
1
  import { Nullable, Optional } from '@wikicasa-dev/types';
2
2
  import { FlatInvert, InvertKeyToValue } from '../types/ObjectUtilsTypes';
3
3
  export type JsonPrimitive = string | number | boolean | null;
4
- export type JsonValue = JsonPrimitive | JsonValue[] | {
5
- [key: string]: unknown;
6
- };
7
- export type JsonObject = {
8
- [key: string]: JsonValue;
9
- };
4
+ export type JsonValue = JsonPrimitive | JsonValue[] | Record<string, unknown>;
5
+ export type JsonObject = Record<string, unknown>;
10
6
  export type MergePatch<T> = T extends JsonValue[] ? T : T extends object ? {
11
7
  [K in keyof T]?: MergePatch<T[K]> | null;
12
8
  } : T;
@@ -69,42 +65,51 @@ export declare const getOrDefault: <T>(value: T, defaultValue: NonNullable<T>) =
69
65
  */
70
66
  export declare const areObjectsEqual: (obj1?: object, obj2?: object) => boolean;
71
67
  /**
72
- * Applies a JSON Merge Patch (RFC 7396) to a source JSON object.
68
+ * Deeply merges a patch object into a source object.
73
69
  *
74
- * This function performs a deep, recursive merge between `source` and `patch`
75
- * following the JSON Merge Patch specification:
70
+ * This utility is designed for application state updates rather than API
71
+ * payload patching.
76
72
  *
73
+ * Merge rules:
74
+ *
75
+ * - `undefined` values remove the corresponding property.
76
+ * - `null` values are preserved and explicitly set the property to `null`.
77
77
  * - Objects are merged recursively.
78
- * - Arrays are replaced (not merged).
79
- * - Primitive values are replaced.
80
- * - `null` values in the patch explicitly remove the property.
78
+ * - Arrays are replaced entirely.
79
+ * - Primitive values replace the existing value.
80
+ *
81
+ * The function does not mutate the source object or the patch object.
81
82
  *
82
- * ### Example
83
+ * @example
83
84
  * ```ts
84
85
  * const source = {
85
- * a: 1,
86
- * b: { c: 2, d: 3 },
86
+ * name: "John",
87
+ * address: {
88
+ * city: "Rome",
89
+ * zip: "00100",
90
+ * },
87
91
  * };
88
92
  *
89
93
  * const patch = {
90
- * a: null,
91
- * b: { d: 4 },
94
+ * name: undefined,
95
+ * address: {
96
+ * city: null,
97
+ * },
92
98
  * };
93
99
  *
94
- * const result = applyMergePatch(source, patch);
100
+ * const result = mergeDeep(source, patch);
101
+ *
95
102
  * // {
96
- * // b: { c: 2, d: 4 }
103
+ * // address: {
104
+ * // city: null,
105
+ * // zip: "00100",
106
+ * // },
97
107
  * // }
98
108
  * ```
99
109
  *
100
- * ### Notes
101
- * - Only JSON-compatible values are supported.
102
- * - The function does not mutate the input objects.
103
- * - Non-object values (including arrays) are replaced entirely.
104
- *
105
- * @template T - Source object type
106
- * @param source - The original JSON object to apply the patch to.
107
- * @param patch - The JSON Merge Patch object describing changes.
108
- * @returns A new object resulting from applying the patch.
110
+ * @template T The source object type.
111
+ * @param source The original object to merge into.
112
+ * @param patch The partial update object.
113
+ * @returns A new object containing the merged result.
109
114
  */
110
- export declare const applyMergePatch: <T extends JsonObject>(source: T, patch: MergePatch<T>) => T;
115
+ export declare const mergeDeep: <T extends object>(source: T, patch: MergePatch<T>) => T;
@@ -4,7 +4,7 @@ function u(e, t) {
4
4
  t[r] = e[r];
5
5
  }
6
6
  const y = (e) => !e || !Object.keys(e).length;
7
- function a(e) {
7
+ function O(e) {
8
8
  if (!e) return null;
9
9
  for (const t in e) {
10
10
  const r = e[t];
@@ -13,13 +13,13 @@ function a(e) {
13
13
  }
14
14
  return { ...e };
15
15
  }
16
- const O = (e) => Object.entries(e).reduce(
16
+ const a = (e) => Object.entries(e).reduce(
17
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
- ), p = (e) => e ?? null, d = (e, t) => e ?? t, c = (e = {}, t = {}) => {
22
+ ), d = (e) => e ?? null, o = (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)
@@ -34,28 +34,26 @@ const O = (e) => Object.entries(e).reduce(
34
34
  t[s]
35
35
  )
36
36
  );
37
- }, l = (e) => e !== null && typeof e == "object" && !Array.isArray(e);
38
- function f(e, t) {
39
- if (t === null)
37
+ }, l = (e) => e !== null && typeof e == "object" && !Array.isArray(e), f = (e, t) => {
38
+ if (t === void 0)
40
39
  return;
41
40
  if (!l(e) || !l(t))
42
41
  return t;
43
42
  const r = { ...e };
44
43
  for (const n of Object.keys(t)) {
45
- const s = t[n], i = f(e[n], s);
44
+ const s = t[n], i = f(r[n], s);
46
45
  i === void 0 ? delete r[n] : r[n] = i;
47
46
  }
48
47
  return r;
49
- }
50
- const k = (e, t) => f(e, t);
48
+ }, p = (e, t) => f(e, t);
51
49
  export {
52
- k as applyMergePatch,
53
50
  c as areObjectsEqual,
54
- a as deepCopy,
55
- d as getOrDefault,
56
- p as getOrNull,
57
- O as invertFlatObject,
51
+ O as deepCopy,
52
+ o as getOrDefault,
53
+ d as getOrNull,
54
+ a as invertFlatObject,
58
55
  g as invertKeyToValue,
59
56
  y as isEmptyObject,
57
+ p as mergeDeep,
60
58
  u as shallowCopyObjectTo
61
59
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@wikicasa-dev/utilities",
3
- "version": "1.2.8",
3
+ "version": "1.2.10",
4
4
  "description": "Wikicasa frontend utilities",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",