@wikicasa-dev/utilities 1.0.14 → 1.0.15

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.
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});function i(e,n){if(e)for(const t in e)n[t]=e[t]}function c(e){return!e||!Object.keys(e).length}function s(e){if(!e)return null;for(const n in e){const t=e[n];if(t&&(Array.isArray(t)||Object.keys(t).length>0))return JSON.parse(JSON.stringify(e))}return{...e}}const u=e=>Object.entries(e).reduce((n,[t,r])=>(n[r]=t,n),{});exports.deepCopy=s;exports.invertFlatObject=u;exports.isEmptyObject=c;exports.shallowCopyObjectTo=i;
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});function i(t,n){if(t)for(const e in t)n[e]=t[e]}const c=t=>!t||!Object.keys(t).length;function l(t){if(!t)return null;for(const n in t){const e=t[n];if(e&&(Array.isArray(e)||Object.keys(e).length>0))return JSON.parse(JSON.stringify(t))}return{...t}}const s=t=>Object.entries(t).reduce((n,[e,r])=>(n[r]=e,n),{}),u=t=>t??null;exports.deepCopy=l;exports.getOrNull=u;exports.invertFlatObject=s;exports.isEmptyObject=c;exports.shallowCopyObjectTo=i;
@@ -3,9 +3,7 @@ function i(t, n) {
3
3
  for (const e in t)
4
4
  n[e] = t[e];
5
5
  }
6
- function c(t) {
7
- return !t || !Object.keys(t).length;
8
- }
6
+ const c = (t) => !t || !Object.keys(t).length;
9
7
  function s(t) {
10
8
  if (!t)
11
9
  return null;
@@ -19,9 +17,10 @@ function s(t) {
19
17
  const u = (t) => Object.entries(t).reduce(
20
18
  (n, [e, r]) => (n[r] = e, n),
21
19
  {}
22
- );
20
+ ), l = (t) => t ?? null;
23
21
  export {
24
22
  s as deepCopy,
23
+ l as getOrNull,
25
24
  u as invertFlatObject,
26
25
  c as isEmptyObject,
27
26
  i as shallowCopyObjectTo
package/dist/index.cjs CHANGED
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const b=require("./ArrayUtils.cjs"),O=require("./ColorUtils.cjs"),i=require("./CookieUtils.cjs"),p=require("./CurrencyUtils.cjs"),C=require("./DateUtils.cjs"),o=require("./DeviceDetectionUtils.cjs"),s=require("./DOMUtils.cjs"),n=require("./EmailUtils.cjs"),E=require("./FunctionUtils.cjs"),c=require("./GenericUtils.cjs"),r=require("./NumberUtils.cjs"),l=require("./ObjectUtils.cjs"),R=require("./ObserverUtils.cjs"),m=require("./PermissionUtils.cjs"),a=require("./RESB_UrlBuilder.cjs"),t=require("./StringUtils.cjs"),g=require("./URLBuilderUtils.cjs"),e=require("./RegexUtils.cjs"),u=require("./GeolocationUtils.cjs"),d=require("./AdressUtils.cjs"),S=require("./GAutocompleteUtils.cjs"),U=require("./DownloadUtils.cjs");exports.isArrNullOrEmpty=b.isArrNullOrEmpty;exports.rgba=O.rgba;exports.decodeCookie=i.decodeCookie;exports.encodeCookie=i.encodeCookie;exports.getCookie=i.getCookie;exports.removeCookie=i.removeCookie;exports.formatCurrency=p.formatCurrency;exports.formatDate=C.formatDate;exports.getCurrentDeviceSize=o.getCurrentDeviceSize;exports.isMobile=o.isMobile;exports.isSafari=o.isSafari;exports.isiOSDevice=o.isiOSDevice;exports.emptyElem=s.emptyElem;exports.getSingleElement=s.getSingleElement;exports.hideElem=s.hideElem;exports.showElem=s.showElem;exports.hash256=n.hash256;exports.hashEmail=n.hashEmail;exports.debounce=E.debounce;exports.isPromise=E.isPromise;exports.awaitableSetTimeout=c.awaitableSetTimeout;exports.createCustomEvent=c.createCustomEvent;exports.formatFloat=r.formatFloat;exports.formatInteger=r.formatInteger;exports.formatLocaleNumber=r.formatLocaleNumber;exports.formatNumber=r.formatNumber;exports.formatterNumberObj=r.formatterNumberObj;exports.parseLocaleNumber=r.parseLocaleNumber;exports.deepCopy=l.deepCopy;exports.invertFlatObject=l.invertFlatObject;exports.isEmptyObject=l.isEmptyObject;exports.shallowCopyObjectTo=l.shallowCopyObjectTo;exports.observeOnce=R.observeOnce;exports.addPermissionStateListener=m.addPermissionStateListener;exports.onNotificationsPermissionChange=m.onNotificationsPermissionChange;exports.buildParams=a.buildParams;exports.buildParamsForAgency=a.buildParamsForAgency;exports.buildURL=a.buildURL;exports.capitalizeFirstLetter=t.capitalizeFirstLetter;exports.cleanASCII=t.cleanASCII;exports.decodeTextWithEntities=t.decodeTextWithEntities;exports.replaceAll=t.replaceAll;exports.replaceAllTokens=t.replaceAllTokens;exports.stringToHyphened=t.stringToHyphened;exports.appendQueryString=g.appendQueryString;exports.COMPETITOR_REGEX=e.COMPETITOR_REGEX;exports.DATE_REGEX=e.DATE_REGEX;exports.EMAIL_REGEX=e.EMAIL_REGEX;exports.EMAIL_REGEX_INTO_TEXT=e.EMAIL_REGEX_INTO_TEXT;exports.EXCLUDED_REGEX=e.EXCLUDED_REGEX;exports.GLOBAL_PHONE_REGEX=e.GLOBAL_PHONE_REGEX;exports.PASSWORD_REGEX=e.PASSWORD_REGEX;exports.PHONE_REGEX=e.PHONE_REGEX;exports.ROOMS_REGEX=e.ROOMS_REGEX;exports.SQM_REGEX=e.SQM_REGEX;exports.browserSupportGeolocation=u.browserSupportGeolocation;exports.getUserPosition=u.getUserPosition;exports.formatAddress=d.formatAddress;exports.formattedAddress=d.formattedAddress;exports.googlePlaceConverter=S.googlePlaceConverter;exports.downloadFile=U.downloadFile;
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const b=require("./ArrayUtils.cjs"),O=require("./ColorUtils.cjs"),o=require("./CookieUtils.cjs"),g=require("./CurrencyUtils.cjs"),p=require("./DateUtils.cjs"),s=require("./DeviceDetectionUtils.cjs"),l=require("./DOMUtils.cjs"),n=require("./EmailUtils.cjs"),E=require("./FunctionUtils.cjs"),c=require("./GenericUtils.cjs"),r=require("./NumberUtils.cjs"),i=require("./ObjectUtils.cjs"),C=require("./ObserverUtils.cjs"),m=require("./PermissionUtils.cjs"),a=require("./RESB_UrlBuilder.cjs"),t=require("./StringUtils.cjs"),R=require("./URLBuilderUtils.cjs"),e=require("./RegexUtils.cjs"),u=require("./GeolocationUtils.cjs"),d=require("./AdressUtils.cjs"),S=require("./GAutocompleteUtils.cjs"),U=require("./DownloadUtils.cjs");exports.isArrNullOrEmpty=b.isArrNullOrEmpty;exports.rgba=O.rgba;exports.decodeCookie=o.decodeCookie;exports.encodeCookie=o.encodeCookie;exports.getCookie=o.getCookie;exports.removeCookie=o.removeCookie;exports.formatCurrency=g.formatCurrency;exports.formatDate=p.formatDate;exports.getCurrentDeviceSize=s.getCurrentDeviceSize;exports.isMobile=s.isMobile;exports.isSafari=s.isSafari;exports.isiOSDevice=s.isiOSDevice;exports.emptyElem=l.emptyElem;exports.getSingleElement=l.getSingleElement;exports.hideElem=l.hideElem;exports.showElem=l.showElem;exports.hash256=n.hash256;exports.hashEmail=n.hashEmail;exports.debounce=E.debounce;exports.isPromise=E.isPromise;exports.awaitableSetTimeout=c.awaitableSetTimeout;exports.createCustomEvent=c.createCustomEvent;exports.formatFloat=r.formatFloat;exports.formatInteger=r.formatInteger;exports.formatLocaleNumber=r.formatLocaleNumber;exports.formatNumber=r.formatNumber;exports.formatterNumberObj=r.formatterNumberObj;exports.parseLocaleNumber=r.parseLocaleNumber;exports.deepCopy=i.deepCopy;exports.getOrNull=i.getOrNull;exports.invertFlatObject=i.invertFlatObject;exports.isEmptyObject=i.isEmptyObject;exports.shallowCopyObjectTo=i.shallowCopyObjectTo;exports.observeOnce=C.observeOnce;exports.addPermissionStateListener=m.addPermissionStateListener;exports.onNotificationsPermissionChange=m.onNotificationsPermissionChange;exports.buildParams=a.buildParams;exports.buildParamsForAgency=a.buildParamsForAgency;exports.buildURL=a.buildURL;exports.capitalizeFirstLetter=t.capitalizeFirstLetter;exports.cleanASCII=t.cleanASCII;exports.decodeTextWithEntities=t.decodeTextWithEntities;exports.replaceAll=t.replaceAll;exports.replaceAllTokens=t.replaceAllTokens;exports.stringToHyphened=t.stringToHyphened;exports.appendQueryString=R.appendQueryString;exports.COMPETITOR_REGEX=e.COMPETITOR_REGEX;exports.DATE_REGEX=e.DATE_REGEX;exports.EMAIL_REGEX=e.EMAIL_REGEX;exports.EMAIL_REGEX_INTO_TEXT=e.EMAIL_REGEX_INTO_TEXT;exports.EXCLUDED_REGEX=e.EXCLUDED_REGEX;exports.GLOBAL_PHONE_REGEX=e.GLOBAL_PHONE_REGEX;exports.PASSWORD_REGEX=e.PASSWORD_REGEX;exports.PHONE_REGEX=e.PHONE_REGEX;exports.ROOMS_REGEX=e.ROOMS_REGEX;exports.SQM_REGEX=e.SQM_REGEX;exports.browserSupportGeolocation=u.browserSupportGeolocation;exports.getUserPosition=u.getUserPosition;exports.formatAddress=d.formatAddress;exports.formattedAddress=d.formattedAddress;exports.googlePlaceConverter=S.googlePlaceConverter;exports.downloadFile=U.downloadFile;
package/dist/index.js CHANGED
@@ -1,85 +1,86 @@
1
1
  import { isArrNullOrEmpty as r } from "./ArrayUtils.js";
2
2
  import { rgba as m } from "./ColorUtils.js";
3
- import { decodeCookie as a, encodeCookie as E, getCookie as p, removeCookie as f } from "./CookieUtils.js";
4
- import { formatCurrency as l } from "./CurrencyUtils.js";
3
+ import { decodeCookie as a, encodeCookie as E, getCookie as p, removeCookie as l } from "./CookieUtils.js";
4
+ import { formatCurrency as s } from "./CurrencyUtils.js";
5
5
  import { formatDate as x } from "./DateUtils.js";
6
6
  import { getCurrentDeviceSize as d, isMobile as b, isSafari as O, isiOSDevice as u } from "./DeviceDetectionUtils.js";
7
- import { emptyElem as R, getSingleElement as g, hideElem as S, showElem as _ } from "./DOMUtils.js";
7
+ import { emptyElem as C, getSingleElement as R, hideElem as S, showElem as _ } from "./DOMUtils.js";
8
8
  import { hash256 as G, hashEmail as X } from "./EmailUtils.js";
9
9
  import { debounce as T, isPromise as h } from "./FunctionUtils.js";
10
- import { awaitableSetTimeout as y, createCustomEvent as N } from "./GenericUtils.js";
10
+ import { awaitableSetTimeout as N, createCustomEvent as y } from "./GenericUtils.js";
11
11
  import { formatFloat as D, formatInteger as I, formatLocaleNumber as M, formatNumber as k, formatterNumberObj as w, parseLocaleNumber as F } from "./NumberUtils.js";
12
- import { deepCopy as H, invertFlatObject as U, isEmptyObject as z, shallowCopyObjectTo as Q } from "./ObjectUtils.js";
13
- import { observeOnce as B } from "./ObserverUtils.js";
14
- import { addPermissionStateListener as J, onNotificationsPermissionChange as K } from "./PermissionUtils.js";
15
- import { buildParams as Y, buildParamsForAgency as Z, buildURL as $ } from "./RESB_UrlBuilder.js";
16
- import { capitalizeFirstLetter as oe, cleanASCII as re, decodeTextWithEntities as te, replaceAll as me, replaceAllTokens as ie, stringToHyphened as ae } from "./StringUtils.js";
17
- import { appendQueryString as pe } from "./URLBuilderUtils.js";
18
- import { COMPETITOR_REGEX as se, DATE_REGEX as le, EMAIL_REGEX as ne, EMAIL_REGEX_INTO_TEXT as xe, EXCLUDED_REGEX as ce, GLOBAL_PHONE_REGEX as de, PASSWORD_REGEX as be, PHONE_REGEX as Oe, ROOMS_REGEX as ue, SQM_REGEX as Ce } from "./RegexUtils.js";
19
- import { browserSupportGeolocation as ge, getUserPosition as Se } from "./GeolocationUtils.js";
20
- import { formatAddress as Ae, formattedAddress as Ge } from "./AdressUtils.js";
21
- import { googlePlaceConverter as Pe } from "./GAutocompleteUtils.js";
22
- import { downloadFile as he } from "./DownloadUtils.js";
12
+ import { deepCopy as H, getOrNull as U, invertFlatObject as z, isEmptyObject as Q, shallowCopyObjectTo as W } from "./ObjectUtils.js";
13
+ import { observeOnce as q } from "./ObserverUtils.js";
14
+ import { addPermissionStateListener as K, onNotificationsPermissionChange as V } from "./PermissionUtils.js";
15
+ import { buildParams as Z, buildParamsForAgency as $, buildURL as ee } from "./RESB_UrlBuilder.js";
16
+ import { capitalizeFirstLetter as re, cleanASCII as te, decodeTextWithEntities as me, replaceAll as ie, replaceAllTokens as ae, stringToHyphened as Ee } from "./StringUtils.js";
17
+ import { appendQueryString as le } from "./URLBuilderUtils.js";
18
+ import { COMPETITOR_REGEX as se, DATE_REGEX as ne, EMAIL_REGEX as xe, EMAIL_REGEX_INTO_TEXT as ce, EXCLUDED_REGEX as de, GLOBAL_PHONE_REGEX as be, PASSWORD_REGEX as Oe, PHONE_REGEX as ue, ROOMS_REGEX as ge, SQM_REGEX as Ce } from "./RegexUtils.js";
19
+ import { browserSupportGeolocation as Se, getUserPosition as _e } from "./GeolocationUtils.js";
20
+ import { formatAddress as Ge, formattedAddress as Xe } from "./AdressUtils.js";
21
+ import { googlePlaceConverter as Te } from "./GAutocompleteUtils.js";
22
+ import { downloadFile as Le } from "./DownloadUtils.js";
23
23
  export {
24
24
  se as COMPETITOR_REGEX,
25
- le as DATE_REGEX,
26
- ne as EMAIL_REGEX,
27
- xe as EMAIL_REGEX_INTO_TEXT,
28
- ce as EXCLUDED_REGEX,
29
- de as GLOBAL_PHONE_REGEX,
30
- be as PASSWORD_REGEX,
31
- Oe as PHONE_REGEX,
32
- ue as ROOMS_REGEX,
25
+ ne as DATE_REGEX,
26
+ xe as EMAIL_REGEX,
27
+ ce as EMAIL_REGEX_INTO_TEXT,
28
+ de as EXCLUDED_REGEX,
29
+ be as GLOBAL_PHONE_REGEX,
30
+ Oe as PASSWORD_REGEX,
31
+ ue as PHONE_REGEX,
32
+ ge as ROOMS_REGEX,
33
33
  Ce as SQM_REGEX,
34
- J as addPermissionStateListener,
35
- pe as appendQueryString,
36
- y as awaitableSetTimeout,
37
- ge as browserSupportGeolocation,
38
- Y as buildParams,
39
- Z as buildParamsForAgency,
40
- $ as buildURL,
41
- oe as capitalizeFirstLetter,
42
- re as cleanASCII,
43
- N as createCustomEvent,
34
+ K as addPermissionStateListener,
35
+ le as appendQueryString,
36
+ N as awaitableSetTimeout,
37
+ Se as browserSupportGeolocation,
38
+ Z as buildParams,
39
+ $ as buildParamsForAgency,
40
+ ee as buildURL,
41
+ re as capitalizeFirstLetter,
42
+ te as cleanASCII,
43
+ y as createCustomEvent,
44
44
  T as debounce,
45
45
  a as decodeCookie,
46
- te as decodeTextWithEntities,
46
+ me as decodeTextWithEntities,
47
47
  H as deepCopy,
48
- he as downloadFile,
49
- R as emptyElem,
48
+ Le as downloadFile,
49
+ C as emptyElem,
50
50
  E as encodeCookie,
51
- Ae as formatAddress,
52
- l as formatCurrency,
51
+ Ge as formatAddress,
52
+ s as formatCurrency,
53
53
  x as formatDate,
54
54
  D as formatFloat,
55
55
  I as formatInteger,
56
56
  M as formatLocaleNumber,
57
57
  k as formatNumber,
58
- Ge as formattedAddress,
58
+ Xe as formattedAddress,
59
59
  w as formatterNumberObj,
60
60
  p as getCookie,
61
61
  d as getCurrentDeviceSize,
62
- g as getSingleElement,
63
- Se as getUserPosition,
64
- Pe as googlePlaceConverter,
62
+ U as getOrNull,
63
+ R as getSingleElement,
64
+ _e as getUserPosition,
65
+ Te as googlePlaceConverter,
65
66
  G as hash256,
66
67
  X as hashEmail,
67
68
  S as hideElem,
68
- U as invertFlatObject,
69
+ z as invertFlatObject,
69
70
  r as isArrNullOrEmpty,
70
- z as isEmptyObject,
71
+ Q as isEmptyObject,
71
72
  b as isMobile,
72
73
  h as isPromise,
73
74
  O as isSafari,
74
75
  u as isiOSDevice,
75
- B as observeOnce,
76
- K as onNotificationsPermissionChange,
76
+ q as observeOnce,
77
+ V as onNotificationsPermissionChange,
77
78
  F as parseLocaleNumber,
78
- f as removeCookie,
79
- me as replaceAll,
80
- ie as replaceAllTokens,
79
+ l as removeCookie,
80
+ ie as replaceAll,
81
+ ae as replaceAllTokens,
81
82
  m as rgba,
82
- Q as shallowCopyObjectTo,
83
+ W as shallowCopyObjectTo,
83
84
  _ as showElem,
84
- ae as stringToHyphened
85
+ Ee as stringToHyphened
85
86
  };
@@ -1,11 +1,34 @@
1
+ import { Nullable, Optional } from '@wikicasa-dev/types';
1
2
  import { FlatInvert } from '../types/ObjectUtilsTypes';
2
3
 
3
4
  export declare function shallowCopyObjectTo(from: Record<string, any> | undefined, to: Record<string, any>): void;
4
- export declare function isEmptyObject(obj: any): boolean;
5
+ /**
6
+ * Checks if the given object is empty.
7
+ *
8
+ * @param {Optional<Nullable<T>>} obj - The object to check.
9
+ * @return {boolean} Returns true if the object is empty, false otherwise.
10
+ */
11
+ export declare const isEmptyObject: <T>(obj: Optional<Nullable<T>>) => boolean;
5
12
  /**
6
13
  * Makes the deep copy of the input object.
7
14
  * For performance purposes, if the values of the properties of the object to copy are all primitive types then we will use the spread operator (faster).
8
15
  * Otherwise, to ensure the deep copy of nested objects and arrays, we will use JSON.parse and JSON.stringify (slower).
9
16
  * */
10
17
  export declare function deepCopy<T>(objToCopy: T): T | null;
18
+ /**
19
+ * Inverts a flat object by swapping its keys and values.
20
+ *
21
+ * @template T - The type of the input object.
22
+ * @template TKey - The type of the keys in the input object.
23
+ * @template TValue - The type of the values in the input object.
24
+ * @param {T} obj - The object to be inverted.
25
+ * @return {FlatInvert<T>} - The inverted object.
26
+ */
11
27
  export declare const invertFlatObject: <T extends Record<TKey, TValue>, TKey extends PropertyKey = PropertyKey, TValue extends string | number = string | number>(obj: T) => FlatInvert<T>;
28
+ /**
29
+ * Returns the value if it is not null or undefined, otherwise returns null.
30
+ * @typeParam T - The type of the value.
31
+ * @param v - The value to check.
32
+ * @returns The value if it is not null or undefined, otherwise returns null.
33
+ */
34
+ export declare const getOrNull: <T>(v: T) => NonNullable<T> | null;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@wikicasa-dev/utilities",
3
- "version": "1.0.14",
3
+ "version": "1.0.15",
4
4
  "description": "Wikicasa frontend utilities",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",