@wikicasa-dev/utilities 1.0.19 → 1.0.21
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/NumberUtils.cjs +1 -1
- package/dist/NumberUtils.js +26 -25
- package/dist/index.cjs +1 -1
- package/dist/index.js +69 -67
- package/dist/utils/NumberUtils.d.ts +23 -5
- package/package.json +1 -1
package/dist/NumberUtils.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const u=(r,t)=>{
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const u=(r,t="it-IT")=>{const e=Intl.NumberFormat(t).format(1111).replace(/\p{Number}/gu,""),a=Intl.NumberFormat(t).format(1.1).replace(/\p{Number}/gu,""),o=parseFloat(`${r}`.replace(new RegExp("\\"+e,"g"),"").replace(new RegExp("\\"+a),"."));return isNaN(o)?"":o},i=r=>u(r,navigator.language),c=(r,t,e="it-IT")=>{if(r==null)return;if(r=parseFloat(`${r}`),isNaN(r))return"";const a={style:"currency",currency:"EUR"};let n={...{maximumFractionDigits:0}};return t?.currency&&(n={...n,...a}),new Intl.NumberFormat(e,{...n}).format(r)},f=(r,t)=>c(r,t,navigator.language);function l(r,t=!1){return r==null?"":m(t?Math.round(r):Math.floor(r),0)}function m(r,t){return!r&&r!==0?"":r.toLocaleString("it-IT",{minimumFractionDigits:t,maximumFractionDigits:t})}function s(r,t=2){return m(r,t)}const p={formatFn:r=>c(r)??"",unFormatFn:r=>u(r)};exports.formatFloat=s;exports.formatInteger=l;exports.formatLocaleNumber=c;exports.formatLocaleNumberAuto=f;exports.formatNumber=m;exports.formatterNumberObj=p;exports.parseLocaleNumber=u;exports.parseLocaleNumberAuto=i;
|
package/dist/NumberUtils.js
CHANGED
|
@@ -1,29 +1,28 @@
|
|
|
1
|
-
const
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
`${r}`.replace(new RegExp("\\" + e, "g"), "").replace(new RegExp("\\" + a), ".")
|
|
1
|
+
const u = (r, t = "it-IT") => {
|
|
2
|
+
const e = Intl.NumberFormat(t).format(1111).replace(/\p{Number}/gu, ""), n = Intl.NumberFormat(t).format(1.1).replace(/\p{Number}/gu, ""), a = parseFloat(
|
|
3
|
+
`${r}`.replace(new RegExp("\\" + e, "g"), "").replace(new RegExp("\\" + n), ".")
|
|
5
4
|
);
|
|
6
|
-
return isNaN(
|
|
7
|
-
}, u = (r, t) => {
|
|
5
|
+
return isNaN(a) ? "" : a;
|
|
6
|
+
}, m = (r) => u(r, navigator.language), i = (r, t, e = "it-IT") => {
|
|
8
7
|
if (r == null)
|
|
9
8
|
return;
|
|
10
9
|
if (r = parseFloat(`${r}`), isNaN(r))
|
|
11
10
|
return "";
|
|
12
|
-
const
|
|
11
|
+
const n = {
|
|
13
12
|
style: "currency",
|
|
14
13
|
currency: "EUR"
|
|
15
14
|
};
|
|
16
|
-
let
|
|
15
|
+
let o = { ...{
|
|
17
16
|
maximumFractionDigits: 0
|
|
18
17
|
} };
|
|
19
|
-
return t?.currency && (
|
|
20
|
-
...
|
|
18
|
+
return t?.currency && (o = { ...o, ...n }), new Intl.NumberFormat(e, {
|
|
19
|
+
...o
|
|
21
20
|
}).format(r);
|
|
22
|
-
};
|
|
23
|
-
function
|
|
24
|
-
return r == null ? "" :
|
|
21
|
+
}, s = (r, t) => i(r, t, navigator.language);
|
|
22
|
+
function f(r, t = !1) {
|
|
23
|
+
return r == null ? "" : c(t ? Math.round(r) : Math.floor(r), 0);
|
|
25
24
|
}
|
|
26
|
-
function
|
|
25
|
+
function c(r, t) {
|
|
27
26
|
return !r && r !== 0 ? "" : r.toLocaleString(
|
|
28
27
|
"it-IT",
|
|
29
28
|
// usare una stringa tipo 'en-US' per sovrascrivere la lingua del browser
|
|
@@ -33,18 +32,20 @@ function o(r, t) {
|
|
|
33
32
|
}
|
|
34
33
|
);
|
|
35
34
|
}
|
|
36
|
-
function
|
|
37
|
-
return
|
|
35
|
+
function l(r, t = 2) {
|
|
36
|
+
return c(r, t);
|
|
38
37
|
}
|
|
39
|
-
const
|
|
40
|
-
formatFn: (r) =>
|
|
41
|
-
unFormatFn: (r) =>
|
|
38
|
+
const p = {
|
|
39
|
+
formatFn: (r) => i(r) ?? "",
|
|
40
|
+
unFormatFn: (r) => u(r)
|
|
42
41
|
};
|
|
43
42
|
export {
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
43
|
+
l as formatFloat,
|
|
44
|
+
f as formatInteger,
|
|
45
|
+
i as formatLocaleNumber,
|
|
46
|
+
s as formatLocaleNumberAuto,
|
|
47
|
+
c as formatNumber,
|
|
48
|
+
p as formatterNumberObj,
|
|
49
|
+
u as parseLocaleNumber,
|
|
50
|
+
m as parseLocaleNumberAuto
|
|
50
51
|
};
|
package/dist/index.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const O=require("./ArrayUtils.cjs"),
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const O=require("./ArrayUtils.cjs"),p=require("./ColorUtils.cjs"),i=require("./CookieUtils.cjs"),g=require("./CurrencyUtils.cjs"),l=require("./DateUtils.cjs"),s=require("./DeviceDetectionUtils.cjs"),a=require("./DOMUtils.cjs"),c=require("./EmailUtils.cjs"),E=require("./FunctionUtils.cjs"),u=require("./GenericUtils.cjs"),t=require("./NumberUtils.cjs"),r=require("./ObjectUtils.cjs"),A=require("./ObserverUtils.cjs"),m=require("./PermissionUtils.cjs"),n=require("./RESB_UrlBuilder.cjs"),o=require("./StringUtils.cjs"),C=require("./URLBuilderUtils.cjs"),e=require("./RegexUtils.cjs"),d=require("./GeolocationUtils.cjs"),b=require("./AdressUtils.cjs"),R=require("./GAutocompleteUtils.cjs"),S=require("./DownloadUtils.cjs");exports.isArrNullOrEmpty=O.isArrNullOrEmpty;exports.rgba=p.rgba;exports.decodeCookie=i.decodeCookie;exports.encodeCookie=i.encodeCookie;exports.getCookie=i.getCookie;exports.removeCookie=i.removeCookie;exports.formatCurrency=g.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=u.awaitableSetTimeout;exports.createCustomEvent=u.createCustomEvent;exports.formatFloat=t.formatFloat;exports.formatInteger=t.formatInteger;exports.formatLocaleNumber=t.formatLocaleNumber;exports.formatLocaleNumberAuto=t.formatLocaleNumberAuto;exports.formatNumber=t.formatNumber;exports.formatterNumberObj=t.formatterNumberObj;exports.parseLocaleNumber=t.parseLocaleNumber;exports.parseLocaleNumberAuto=t.parseLocaleNumberAuto;exports.deepCopy=r.deepCopy;exports.getOrNull=r.getOrNull;exports.invertFlatObject=r.invertFlatObject;exports.invertKeyToValue=r.invertKeyToValue;exports.isEmptyObject=r.isEmptyObject;exports.shallowCopyObjectTo=r.shallowCopyObjectTo;exports.observeOnce=A.observeOnce;exports.addPermissionStateListener=m.addPermissionStateListener;exports.onNotificationsPermissionChange=m.onNotificationsPermissionChange;exports.buildParams=n.buildParams;exports.buildParamsForAgency=n.buildParamsForAgency;exports.buildURL=n.buildURL;exports.capitalizeFirstLetter=o.capitalizeFirstLetter;exports.cleanASCII=o.cleanASCII;exports.decodeTextWithEntities=o.decodeTextWithEntities;exports.replaceAll=o.replaceAll;exports.replaceAllTokens=o.replaceAllTokens;exports.stringToHyphened=o.stringToHyphened;exports.appendQueryString=C.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=R.googlePlaceConverter;exports.downloadFile=S.downloadFile;
|
package/dist/index.js
CHANGED
|
@@ -1,89 +1,91 @@
|
|
|
1
1
|
import { isArrNullOrEmpty as r } from "./ArrayUtils.js";
|
|
2
2
|
import { rgba as m } from "./ColorUtils.js";
|
|
3
|
-
import { decodeCookie as i, encodeCookie as
|
|
3
|
+
import { decodeCookie as i, encodeCookie as p, getCookie as E, removeCookie as l } from "./CookieUtils.js";
|
|
4
4
|
import { formatCurrency as f } from "./CurrencyUtils.js";
|
|
5
|
-
import { formatDate as
|
|
6
|
-
import { getCurrentDeviceSize as
|
|
7
|
-
import { emptyElem as
|
|
8
|
-
import { hash256 as
|
|
9
|
-
import { debounce as
|
|
10
|
-
import { awaitableSetTimeout as
|
|
11
|
-
import { formatFloat as I, formatInteger as F, formatLocaleNumber as k,
|
|
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
|
|
5
|
+
import { formatDate as c, formatDateToddMMYYYY as d, subtractDaysFromDate as x } from "./DateUtils.js";
|
|
6
|
+
import { getCurrentDeviceSize as b, isMobile as O, isSafari as g, isiOSDevice as A } from "./DeviceDetectionUtils.js";
|
|
7
|
+
import { emptyElem as R, getSingleElement as S, hideElem as T, showElem as _ } from "./DOMUtils.js";
|
|
8
|
+
import { hash256 as L, hashEmail as N } from "./EmailUtils.js";
|
|
9
|
+
import { debounce as y, isPromise as P } from "./FunctionUtils.js";
|
|
10
|
+
import { awaitableSetTimeout as D, createCustomEvent as v } from "./GenericUtils.js";
|
|
11
|
+
import { formatFloat as I, formatInteger as F, formatLocaleNumber as k, formatLocaleNumberAuto as w, formatNumber as j, formatterNumberObj as Y, parseLocaleNumber as H, parseLocaleNumberAuto as U } from "./NumberUtils.js";
|
|
12
|
+
import { deepCopy as Q, getOrNull as W, invertFlatObject as B, invertKeyToValue as K, isEmptyObject as V, shallowCopyObjectTo as q } from "./ObjectUtils.js";
|
|
13
|
+
import { observeOnce as Z } from "./ObserverUtils.js";
|
|
14
|
+
import { addPermissionStateListener as ee, onNotificationsPermissionChange as oe } from "./PermissionUtils.js";
|
|
15
|
+
import { buildParams as te, buildParamsForAgency as me, buildURL as ae } from "./RESB_UrlBuilder.js";
|
|
16
|
+
import { capitalizeFirstLetter as pe, cleanASCII as Ee, decodeTextWithEntities as le, replaceAll as se, replaceAllTokens as fe, stringToHyphened as ne } from "./StringUtils.js";
|
|
17
|
+
import { appendQueryString as de } from "./URLBuilderUtils.js";
|
|
18
|
+
import { COMPETITOR_REGEX as ue, DATE_REGEX as be, EMAIL_REGEX as Oe, EMAIL_REGEX_INTO_TEXT as ge, EXCLUDED_REGEX as Ae, GLOBAL_PHONE_REGEX as Ce, PASSWORD_REGEX as Re, PHONE_REGEX as Se, ROOMS_REGEX as Te, SQM_REGEX as _e } from "./RegexUtils.js";
|
|
19
|
+
import { browserSupportGeolocation as Le, getUserPosition as Ne } from "./GeolocationUtils.js";
|
|
20
20
|
import { formatAddress as ye, formattedAddress as Pe } from "./AdressUtils.js";
|
|
21
21
|
import { googlePlaceConverter as De } from "./GAutocompleteUtils.js";
|
|
22
|
-
import { downloadFile as
|
|
22
|
+
import { downloadFile as Me } 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
|
-
|
|
24
|
+
ue as COMPETITOR_REGEX,
|
|
25
|
+
be as DATE_REGEX,
|
|
26
|
+
Oe as EMAIL_REGEX,
|
|
27
|
+
ge as EMAIL_REGEX_INTO_TEXT,
|
|
28
|
+
Ae as EXCLUDED_REGEX,
|
|
29
|
+
Ce as GLOBAL_PHONE_REGEX,
|
|
30
|
+
Re as PASSWORD_REGEX,
|
|
31
|
+
Se as PHONE_REGEX,
|
|
32
|
+
Te as ROOMS_REGEX,
|
|
33
|
+
_e as SQM_REGEX,
|
|
34
|
+
ee as addPermissionStateListener,
|
|
35
|
+
de as appendQueryString,
|
|
36
|
+
D as awaitableSetTimeout,
|
|
37
|
+
Le as browserSupportGeolocation,
|
|
38
|
+
te as buildParams,
|
|
39
|
+
me as buildParamsForAgency,
|
|
40
|
+
ae as buildURL,
|
|
41
|
+
pe as capitalizeFirstLetter,
|
|
42
|
+
Ee as cleanASCII,
|
|
43
43
|
v as createCustomEvent,
|
|
44
|
-
|
|
44
|
+
y as debounce,
|
|
45
45
|
i as decodeCookie,
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
46
|
+
le as decodeTextWithEntities,
|
|
47
|
+
Q as deepCopy,
|
|
48
|
+
Me as downloadFile,
|
|
49
|
+
R as emptyElem,
|
|
50
|
+
p as encodeCookie,
|
|
51
51
|
ye as formatAddress,
|
|
52
52
|
f as formatCurrency,
|
|
53
|
-
|
|
54
|
-
|
|
53
|
+
c as formatDate,
|
|
54
|
+
d as formatDateToddMMYYYY,
|
|
55
55
|
I as formatFloat,
|
|
56
56
|
F as formatInteger,
|
|
57
57
|
k as formatLocaleNumber,
|
|
58
|
-
w as
|
|
58
|
+
w as formatLocaleNumberAuto,
|
|
59
|
+
j as formatNumber,
|
|
59
60
|
Pe as formattedAddress,
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
61
|
+
Y as formatterNumberObj,
|
|
62
|
+
E as getCookie,
|
|
63
|
+
b as getCurrentDeviceSize,
|
|
64
|
+
W as getOrNull,
|
|
65
|
+
S as getSingleElement,
|
|
66
|
+
Ne as getUserPosition,
|
|
66
67
|
De as googlePlaceConverter,
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
68
|
+
L as hash256,
|
|
69
|
+
N as hashEmail,
|
|
70
|
+
T as hideElem,
|
|
71
|
+
B as invertFlatObject,
|
|
72
|
+
K as invertKeyToValue,
|
|
72
73
|
r as isArrNullOrEmpty,
|
|
73
|
-
|
|
74
|
+
V as isEmptyObject,
|
|
74
75
|
O as isMobile,
|
|
75
|
-
|
|
76
|
+
P as isPromise,
|
|
76
77
|
g as isSafari,
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
78
|
+
A as isiOSDevice,
|
|
79
|
+
Z as observeOnce,
|
|
80
|
+
oe as onNotificationsPermissionChange,
|
|
81
|
+
H as parseLocaleNumber,
|
|
82
|
+
U as parseLocaleNumberAuto,
|
|
81
83
|
l as removeCookie,
|
|
82
|
-
|
|
83
|
-
|
|
84
|
+
se as replaceAll,
|
|
85
|
+
fe as replaceAllTokens,
|
|
84
86
|
m as rgba,
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
87
|
+
q as shallowCopyObjectTo,
|
|
88
|
+
_ as showElem,
|
|
89
|
+
ne as stringToHyphened,
|
|
88
90
|
x as subtractDaysFromDate
|
|
89
91
|
};
|
|
@@ -1,12 +1,30 @@
|
|
|
1
|
+
export declare const parseLocaleNumber: (stringNumber: string, locale?: Intl.LocalesArgument) => number | string | null;
|
|
1
2
|
/**
|
|
2
|
-
*
|
|
3
|
-
*
|
|
4
|
-
*
|
|
3
|
+
* Automatically parses a string number to a number according to the user's locale settings.
|
|
4
|
+
*
|
|
5
|
+
* Utilizes `parseLocaleNumber` to parse the provided string number with optional currency parsing.
|
|
6
|
+
* The locale is determined using the user's browser language settings.
|
|
7
|
+
*
|
|
8
|
+
* @param stringNumber - The string number to parse
|
|
9
|
+
* @returns The parsed number, or undefined if the input is invalid
|
|
5
10
|
*/
|
|
6
|
-
export declare const
|
|
11
|
+
export declare const parseLocaleNumberAuto: (stringNumber: string) => string | number | null;
|
|
7
12
|
export declare const formatLocaleNumber: (numberToFormat?: number | string, props?: {
|
|
8
13
|
currency: boolean;
|
|
9
|
-
}) => string | undefined | null;
|
|
14
|
+
}, lang?: Intl.LocalesArgument) => string | undefined | null;
|
|
15
|
+
/**
|
|
16
|
+
* Automatically formats a number according to the user's locale settings.
|
|
17
|
+
*
|
|
18
|
+
* Utilizes `formatLocaleNumber` to format the provided number with optional currency formatting.
|
|
19
|
+
* The locale is determined using the user's browser language settings.
|
|
20
|
+
*
|
|
21
|
+
* @param numberToFormat - The number or string representation of a number to format.
|
|
22
|
+
* @param props - Optional properties to specify if currency formatting is required.
|
|
23
|
+
* @returns The formatted number string, or undefined if the input is invalid.
|
|
24
|
+
*/
|
|
25
|
+
export declare const formatLocaleNumberAuto: (numberToFormat?: number | string, props?: {
|
|
26
|
+
currency: boolean;
|
|
27
|
+
}) => string | null | undefined;
|
|
10
28
|
export declare function formatInteger(value: number | undefined, round?: boolean): string;
|
|
11
29
|
export declare function formatNumber(value: number | undefined, digits?: number): string;
|
|
12
30
|
export declare function formatFloat(value: number | undefined, digits?: number): string;
|