@wikicasa-dev/utilities 1.0.14 → 1.0.17
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/DateUtils.cjs +1 -1
- package/dist/DateUtils.js +1218 -4
- package/dist/ObjectUtils.cjs +1 -1
- package/dist/ObjectUtils.js +3 -4
- package/dist/index.cjs +1 -1
- package/dist/index.js +78 -75
- package/dist/utils/DateUtils.d.ts +15 -0
- package/dist/utils/ObjectUtils.d.ts +24 -1
- package/package.json +2 -1
package/dist/ObjectUtils.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});function 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;
|
package/dist/ObjectUtils.js
CHANGED
|
@@ -3,9 +3,7 @@ function i(t, n) {
|
|
|
3
3
|
for (const e in t)
|
|
4
4
|
n[e] = t[e];
|
|
5
5
|
}
|
|
6
|
-
|
|
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
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const O=require("./ArrayUtils.cjs"),g=require("./ColorUtils.cjs"),i=require("./CookieUtils.cjs"),p=require("./CurrencyUtils.cjs"),l=require("./DateUtils.cjs"),s=require("./DeviceDetectionUtils.cjs"),a=require("./DOMUtils.cjs"),c=require("./EmailUtils.cjs"),E=require("./FunctionUtils.cjs"),m=require("./GenericUtils.cjs"),t=require("./NumberUtils.cjs"),o=require("./ObjectUtils.cjs"),C=require("./ObserverUtils.cjs"),u=require("./PermissionUtils.cjs"),n=require("./RESB_UrlBuilder.cjs"),r=require("./StringUtils.cjs"),R=require("./URLBuilderUtils.cjs"),e=require("./RegexUtils.cjs"),d=require("./GeolocationUtils.cjs"),b=require("./AdressUtils.cjs"),S=require("./GAutocompleteUtils.cjs"),U=require("./DownloadUtils.cjs");exports.isArrNullOrEmpty=O.isArrNullOrEmpty;exports.rgba=g.rgba;exports.decodeCookie=i.decodeCookie;exports.encodeCookie=i.encodeCookie;exports.getCookie=i.getCookie;exports.removeCookie=i.removeCookie;exports.formatCurrency=p.formatCurrency;exports.formatDate=l.formatDate;exports.formatDateToddMMYYYY=l.formatDateToddMMYYYY;exports.subtractDaysFromDate=l.subtractDaysFromDate;exports.getCurrentDeviceSize=s.getCurrentDeviceSize;exports.isMobile=s.isMobile;exports.isSafari=s.isSafari;exports.isiOSDevice=s.isiOSDevice;exports.emptyElem=a.emptyElem;exports.getSingleElement=a.getSingleElement;exports.hideElem=a.hideElem;exports.showElem=a.showElem;exports.hash256=c.hash256;exports.hashEmail=c.hashEmail;exports.debounce=E.debounce;exports.isPromise=E.isPromise;exports.awaitableSetTimeout=m.awaitableSetTimeout;exports.createCustomEvent=m.createCustomEvent;exports.formatFloat=t.formatFloat;exports.formatInteger=t.formatInteger;exports.formatLocaleNumber=t.formatLocaleNumber;exports.formatNumber=t.formatNumber;exports.formatterNumberObj=t.formatterNumberObj;exports.parseLocaleNumber=t.parseLocaleNumber;exports.deepCopy=o.deepCopy;exports.getOrNull=o.getOrNull;exports.invertFlatObject=o.invertFlatObject;exports.isEmptyObject=o.isEmptyObject;exports.shallowCopyObjectTo=o.shallowCopyObjectTo;exports.observeOnce=C.observeOnce;exports.addPermissionStateListener=u.addPermissionStateListener;exports.onNotificationsPermissionChange=u.onNotificationsPermissionChange;exports.buildParams=n.buildParams;exports.buildParamsForAgency=n.buildParamsForAgency;exports.buildURL=n.buildURL;exports.capitalizeFirstLetter=r.capitalizeFirstLetter;exports.cleanASCII=r.cleanASCII;exports.decodeTextWithEntities=r.decodeTextWithEntities;exports.replaceAll=r.replaceAll;exports.replaceAllTokens=r.replaceAllTokens;exports.stringToHyphened=r.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=d.browserSupportGeolocation;exports.getUserPosition=d.getUserPosition;exports.formatAddress=b.formatAddress;exports.formattedAddress=b.formattedAddress;exports.googlePlaceConverter=S.googlePlaceConverter;exports.downloadFile=U.downloadFile;
|
package/dist/index.js
CHANGED
|
@@ -1,85 +1,88 @@
|
|
|
1
1
|
import { isArrNullOrEmpty as r } from "./ArrayUtils.js";
|
|
2
2
|
import { rgba as m } from "./ColorUtils.js";
|
|
3
|
-
import { decodeCookie as
|
|
3
|
+
import { decodeCookie as i, encodeCookie as E, getCookie as p, removeCookie as s } from "./CookieUtils.js";
|
|
4
4
|
import { formatCurrency as l } from "./CurrencyUtils.js";
|
|
5
|
-
import { formatDate as x } from "./DateUtils.js";
|
|
6
|
-
import { getCurrentDeviceSize as
|
|
7
|
-
import { emptyElem as
|
|
8
|
-
import { hash256 as
|
|
9
|
-
import { debounce as
|
|
10
|
-
import { awaitableSetTimeout as
|
|
11
|
-
import { formatFloat as
|
|
12
|
-
import { deepCopy as
|
|
13
|
-
import { observeOnce as
|
|
14
|
-
import { addPermissionStateListener as
|
|
15
|
-
import { buildParams as
|
|
16
|
-
import { capitalizeFirstLetter as
|
|
17
|
-
import { appendQueryString as
|
|
18
|
-
import { COMPETITOR_REGEX as
|
|
19
|
-
import { browserSupportGeolocation as
|
|
20
|
-
import { formatAddress as
|
|
21
|
-
import { googlePlaceConverter as
|
|
22
|
-
import { downloadFile as
|
|
5
|
+
import { formatDate as d, formatDateToddMMYYYY as c, subtractDaysFromDate as x } from "./DateUtils.js";
|
|
6
|
+
import { getCurrentDeviceSize as u, isMobile as O, isSafari as g, isiOSDevice as C } from "./DeviceDetectionUtils.js";
|
|
7
|
+
import { emptyElem as S, getSingleElement as _, hideElem as A, showElem as G } from "./DOMUtils.js";
|
|
8
|
+
import { hash256 as X, hashEmail as P } from "./EmailUtils.js";
|
|
9
|
+
import { debounce as y, isPromise as D } from "./FunctionUtils.js";
|
|
10
|
+
import { awaitableSetTimeout as N, createCustomEvent as M } from "./GenericUtils.js";
|
|
11
|
+
import { formatFloat as I, formatInteger as F, formatLocaleNumber as k, formatNumber as w, formatterNumberObj as j, parseLocaleNumber as Y } from "./NumberUtils.js";
|
|
12
|
+
import { deepCopy as U, getOrNull as z, invertFlatObject as Q, isEmptyObject as W, shallowCopyObjectTo as B } from "./ObjectUtils.js";
|
|
13
|
+
import { observeOnce as J } from "./ObserverUtils.js";
|
|
14
|
+
import { addPermissionStateListener as V, onNotificationsPermissionChange as Z } from "./PermissionUtils.js";
|
|
15
|
+
import { buildParams as ee, buildParamsForAgency as oe, buildURL as re } from "./RESB_UrlBuilder.js";
|
|
16
|
+
import { capitalizeFirstLetter as me, cleanASCII as ae, decodeTextWithEntities as ie, replaceAll as Ee, replaceAllTokens as pe, stringToHyphened as se } from "./StringUtils.js";
|
|
17
|
+
import { appendQueryString as le } from "./URLBuilderUtils.js";
|
|
18
|
+
import { COMPETITOR_REGEX as de, DATE_REGEX as ce, EMAIL_REGEX as xe, EMAIL_REGEX_INTO_TEXT as be, EXCLUDED_REGEX as ue, GLOBAL_PHONE_REGEX as Oe, PASSWORD_REGEX as ge, PHONE_REGEX as Ce, ROOMS_REGEX as Re, SQM_REGEX as Se } from "./RegexUtils.js";
|
|
19
|
+
import { browserSupportGeolocation as Ae, getUserPosition as Ge } from "./GeolocationUtils.js";
|
|
20
|
+
import { formatAddress as Xe, formattedAddress as Pe } from "./AdressUtils.js";
|
|
21
|
+
import { googlePlaceConverter as ye } from "./GAutocompleteUtils.js";
|
|
22
|
+
import { downloadFile as Le } from "./DownloadUtils.js";
|
|
23
23
|
export {
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
24
|
+
de as COMPETITOR_REGEX,
|
|
25
|
+
ce as DATE_REGEX,
|
|
26
|
+
xe as EMAIL_REGEX,
|
|
27
|
+
be as EMAIL_REGEX_INTO_TEXT,
|
|
28
|
+
ue as EXCLUDED_REGEX,
|
|
29
|
+
Oe as GLOBAL_PHONE_REGEX,
|
|
30
|
+
ge as PASSWORD_REGEX,
|
|
31
|
+
Ce as PHONE_REGEX,
|
|
32
|
+
Re as ROOMS_REGEX,
|
|
33
|
+
Se as SQM_REGEX,
|
|
34
|
+
V as addPermissionStateListener,
|
|
35
|
+
le as appendQueryString,
|
|
36
|
+
N as awaitableSetTimeout,
|
|
37
|
+
Ae as browserSupportGeolocation,
|
|
38
|
+
ee as buildParams,
|
|
39
|
+
oe as buildParamsForAgency,
|
|
40
|
+
re as buildURL,
|
|
41
|
+
me as capitalizeFirstLetter,
|
|
42
|
+
ae as cleanASCII,
|
|
43
|
+
M as createCustomEvent,
|
|
44
|
+
y as debounce,
|
|
45
|
+
i as decodeCookie,
|
|
46
|
+
ie as decodeTextWithEntities,
|
|
47
|
+
U as deepCopy,
|
|
48
|
+
Le as downloadFile,
|
|
49
|
+
S as emptyElem,
|
|
50
50
|
E as encodeCookie,
|
|
51
|
-
|
|
51
|
+
Xe as formatAddress,
|
|
52
52
|
l as formatCurrency,
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
I as
|
|
56
|
-
|
|
57
|
-
k as
|
|
58
|
-
|
|
59
|
-
|
|
53
|
+
d as formatDate,
|
|
54
|
+
c as formatDateToddMMYYYY,
|
|
55
|
+
I as formatFloat,
|
|
56
|
+
F as formatInteger,
|
|
57
|
+
k as formatLocaleNumber,
|
|
58
|
+
w as formatNumber,
|
|
59
|
+
Pe as formattedAddress,
|
|
60
|
+
j as formatterNumberObj,
|
|
60
61
|
p as getCookie,
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
X as
|
|
67
|
-
|
|
68
|
-
|
|
62
|
+
u as getCurrentDeviceSize,
|
|
63
|
+
z as getOrNull,
|
|
64
|
+
_ as getSingleElement,
|
|
65
|
+
Ge as getUserPosition,
|
|
66
|
+
ye as googlePlaceConverter,
|
|
67
|
+
X as hash256,
|
|
68
|
+
P as hashEmail,
|
|
69
|
+
A as hideElem,
|
|
70
|
+
Q as invertFlatObject,
|
|
69
71
|
r as isArrNullOrEmpty,
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
72
|
+
W as isEmptyObject,
|
|
73
|
+
O as isMobile,
|
|
74
|
+
D as isPromise,
|
|
75
|
+
g as isSafari,
|
|
76
|
+
C as isiOSDevice,
|
|
77
|
+
J as observeOnce,
|
|
78
|
+
Z as onNotificationsPermissionChange,
|
|
79
|
+
Y as parseLocaleNumber,
|
|
80
|
+
s as removeCookie,
|
|
81
|
+
Ee as replaceAll,
|
|
82
|
+
pe as replaceAllTokens,
|
|
81
83
|
m as rgba,
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
84
|
+
B as shallowCopyObjectTo,
|
|
85
|
+
G as showElem,
|
|
86
|
+
se as stringToHyphened,
|
|
87
|
+
x as subtractDaysFromDate
|
|
85
88
|
};
|
|
@@ -1 +1,16 @@
|
|
|
1
1
|
export declare function formatDate(date: Date, display?: boolean): string;
|
|
2
|
+
/**
|
|
3
|
+
* Formats a date string from a certain format to 'dd/MM/yyyy' format.
|
|
4
|
+
* @param {string} date - The input date string.
|
|
5
|
+
* @returns {string} The formatted date string in 'dd/MM/yyyy' format.
|
|
6
|
+
*/
|
|
7
|
+
export declare const formatDateToddMMYYYY: (date: Date | string) => string;
|
|
8
|
+
/**
|
|
9
|
+
* Subtracts a specified number of days from a given date.
|
|
10
|
+
* If no initial date is provided, the current date is used as the default.
|
|
11
|
+
* If the number of days is less than zero, it defaults to 0.
|
|
12
|
+
* @param {Date} initialDate - The initial date to subtract days from (default: current date).
|
|
13
|
+
* @param {number} days - The number of days to subtract.
|
|
14
|
+
* @returns {Date} A new Date object representing the result of subtracting the specified days from the initial date.
|
|
15
|
+
*/
|
|
16
|
+
export declare const subtractDaysFromDate: (initialDate: Date | undefined, days: number) => Date;
|
|
@@ -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
|
-
|
|
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.
|
|
3
|
+
"version": "1.0.17",
|
|
4
4
|
"description": "Wikicasa frontend utilities",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "dist/index.js",
|
|
@@ -45,6 +45,7 @@
|
|
|
45
45
|
},
|
|
46
46
|
"dependencies": {
|
|
47
47
|
"axios": "^1.4.0",
|
|
48
|
+
"date-fns": "^3.6.0",
|
|
48
49
|
"google-polyline": "^1.0.3",
|
|
49
50
|
"jest": "^29.7.0",
|
|
50
51
|
"js-cookie": "^3.0.5",
|