@carto/ps-utils 1.0.0 → 1.1.0
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/ps-utils.js +99 -0
- package/dist/types/colors/{hexToRgbaDeckGL.d.ts → hex-to-gba-deckgl/hex-to-gba-deckgl.d.ts} +0 -0
- package/dist/types/colors/{rgbaDeckGLToHex/rgbaDeckGLToHex.d.ts → rgba-deck-gl-to-hex/rgba-deck-gl-to-hex.d.ts} +0 -0
- package/dist/types/colors/{rgbaDeckGLToHex → rgba-deck-gl-to-hex}/types.d.ts +0 -0
- package/dist/types/formatters/constants.d.ts +1 -0
- package/dist/types/formatters/date/format-date.d.ts +12 -0
- package/dist/types/formatters/number/format-number.d.ts +34 -0
- package/dist/types/index.d.ts +8 -5
- package/dist/types/strings/{matchText/matchText.d.ts → match-text/match-text.d.ts} +0 -0
- package/dist/types/strings/{matchText → match-text}/types.d.ts +0 -0
- package/package.json +1 -1
- package/dist/ps-utils.es.js +0 -47
- package/dist/ps-utils.umd.js +0 -1
package/dist/ps-utils.js
ADDED
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
function f(t, n = 1) {
|
|
2
|
+
if (!t) {
|
|
3
|
+
console.warn(`hexToRgbaDeckGL: ${t} invalid hexadecimal format`);
|
|
4
|
+
return;
|
|
5
|
+
}
|
|
6
|
+
if (n < 0 || n > 1) {
|
|
7
|
+
console.warn(`hexToRgbaDeckGL: ${n} invalid alpha format`);
|
|
8
|
+
return;
|
|
9
|
+
}
|
|
10
|
+
if (t?.includes("#") && (t = t.slice(1)), !/[0-9A-Fa-f]{6}/g.test(t) && !/[0-9A-Fa-f]{3}/g.test(t) && !/[0-9A-Fa-f]{2}/g.test(t)) {
|
|
11
|
+
console.warn(`hexToRgbaDeckGL: ${t} invalid hexadecimal format`);
|
|
12
|
+
return;
|
|
13
|
+
}
|
|
14
|
+
const r = t.length;
|
|
15
|
+
r < 6 && (t = t.slice(0, 6 - r).repeat(6 / r));
|
|
16
|
+
const e = parseInt(
|
|
17
|
+
t.length === 3 ? t.slice(0, 1).repeat(2) : t.slice(0, 2),
|
|
18
|
+
16
|
|
19
|
+
), o = parseInt(
|
|
20
|
+
t.length === 3 ? t.slice(1, 2).repeat(2) : t.slice(2, 4),
|
|
21
|
+
16
|
|
22
|
+
), i = parseInt(
|
|
23
|
+
t.length === 3 ? t.slice(2, 3).repeat(2) : t.slice(4, 6),
|
|
24
|
+
16
|
|
25
|
+
);
|
|
26
|
+
return [e, o, i, n * 255];
|
|
27
|
+
}
|
|
28
|
+
function g(t, { withPrefix: n = !0 } = {}) {
|
|
29
|
+
if (!t || !t.length) {
|
|
30
|
+
console.warn("rgbaDeckGLToHex: invalid array or empty values");
|
|
31
|
+
return;
|
|
32
|
+
}
|
|
33
|
+
if (t.some((o) => o < 0 || o > 255)) {
|
|
34
|
+
console.warn(
|
|
35
|
+
`rgbaDeckGLToHex: [${t.toString()}] invalid array value format`
|
|
36
|
+
);
|
|
37
|
+
return;
|
|
38
|
+
}
|
|
39
|
+
const e = t.map((o) => o.toString(16).padStart(2, "0")).join("");
|
|
40
|
+
return `${n ? "#" : ""}${e}`;
|
|
41
|
+
}
|
|
42
|
+
function s(t, { format: n = "NFD", replaceUnicode: r = "[\u0300-\u036F]" } = {}) {
|
|
43
|
+
const e = new RegExp(r, "g");
|
|
44
|
+
return t.normalize(n).replace(e, "");
|
|
45
|
+
}
|
|
46
|
+
function l(t, n, { matchFn: r, normalizeOptions: e } = {}) {
|
|
47
|
+
const o = new RegExp(
|
|
48
|
+
s(t.toLowerCase(), e),
|
|
49
|
+
"gi"
|
|
50
|
+
);
|
|
51
|
+
return Array.isArray(n) ? n.filter((i) => {
|
|
52
|
+
const a = r ? r(i) : i;
|
|
53
|
+
return s(a).match(o);
|
|
54
|
+
}) : s(n).match(o) ? n : null;
|
|
55
|
+
}
|
|
56
|
+
function m(t, n, r) {
|
|
57
|
+
return Intl.DateTimeFormat(n, r).format(t);
|
|
58
|
+
}
|
|
59
|
+
const c = {
|
|
60
|
+
NUMBER: {
|
|
61
|
+
style: "decimal",
|
|
62
|
+
maximumFractionDigits: 1,
|
|
63
|
+
minimumFractionDigits: 0,
|
|
64
|
+
notation: "compact",
|
|
65
|
+
compactDisplay: "short"
|
|
66
|
+
},
|
|
67
|
+
CURRENCY: {
|
|
68
|
+
style: "currency",
|
|
69
|
+
currency: "USD",
|
|
70
|
+
maximumFractionDigits: 2,
|
|
71
|
+
minimumFractionDigits: 2,
|
|
72
|
+
notation: "compact",
|
|
73
|
+
compactDisplay: "short"
|
|
74
|
+
},
|
|
75
|
+
DATE: {
|
|
76
|
+
year: "numeric",
|
|
77
|
+
month: "2-digit",
|
|
78
|
+
day: "2-digit"
|
|
79
|
+
}
|
|
80
|
+
};
|
|
81
|
+
function u(t, n, r) {
|
|
82
|
+
return Intl.NumberFormat(n, r).format(t);
|
|
83
|
+
}
|
|
84
|
+
function D(t, n, r = {}) {
|
|
85
|
+
return u(t, n, { ...c.NUMBER, ...r });
|
|
86
|
+
}
|
|
87
|
+
function p(t, n, r = {}) {
|
|
88
|
+
return u(t, n, { ...c.CURRENCY, ...r });
|
|
89
|
+
}
|
|
90
|
+
export {
|
|
91
|
+
c as CONFIG,
|
|
92
|
+
p as formatCurrency,
|
|
93
|
+
m as formatDate,
|
|
94
|
+
D as formatNumber,
|
|
95
|
+
f as hexToRgbaDeckGL,
|
|
96
|
+
l as matchText,
|
|
97
|
+
s as normalize,
|
|
98
|
+
g as rgbaDeckGLToHex
|
|
99
|
+
};
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const CONFIG: Record<string, Intl.NumberFormatOptions | Intl.DateTimeFormatOptions>;
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Formats a Date or number to a string based on the given options.
|
|
3
|
+
* This function could be used to format a Date, in Date format or miliseconds, in specific locale and options.
|
|
4
|
+
* @public
|
|
5
|
+
*
|
|
6
|
+
* @export
|
|
7
|
+
* @param {number | Date} value
|
|
8
|
+
* @param {string | string[]} locales
|
|
9
|
+
* @param {Intl.DateTimeFormatOptions} [options]
|
|
10
|
+
* @return {string}
|
|
11
|
+
*/
|
|
12
|
+
export declare function formatDate(value: number | Date, locales: string | string[], options?: Intl.DateTimeFormatOptions): string;
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Formats a number to a string.
|
|
3
|
+
* @public
|
|
4
|
+
*
|
|
5
|
+
* @example
|
|
6
|
+
*
|
|
7
|
+
* ```ts
|
|
8
|
+
* formatNumber(3001, 'es-ES') // => '3 mil'
|
|
9
|
+
* ```
|
|
10
|
+
*
|
|
11
|
+
* @export
|
|
12
|
+
* @param {number} value - The number to be formatted.
|
|
13
|
+
* @param {string} locale - The locale to be used.
|
|
14
|
+
* @param {Intl.NumberFormatOptions} [options] - The options to be used.
|
|
15
|
+
* @return {string}
|
|
16
|
+
*/
|
|
17
|
+
export declare function formatNumber(value: number, locale: string, options?: Intl.NumberFormatOptions): string;
|
|
18
|
+
/**
|
|
19
|
+
* Formats a number to a currency string.
|
|
20
|
+
* @public
|
|
21
|
+
*
|
|
22
|
+
* @example
|
|
23
|
+
*
|
|
24
|
+
* ```ts
|
|
25
|
+
* formatCurrency(3001, 'en-US') // => '$3.00K'
|
|
26
|
+
* ```
|
|
27
|
+
*
|
|
28
|
+
* @export
|
|
29
|
+
* @param {number} value - The number to be formatted.
|
|
30
|
+
* @param {string} locale - The locale to be used.
|
|
31
|
+
* @param {Intl.NumberFormatOptions} [options] - The options to be used.
|
|
32
|
+
* @return {string}
|
|
33
|
+
*/
|
|
34
|
+
export declare function formatCurrency(value: number, locale: string, options?: Intl.NumberFormatOptions): string;
|
package/dist/types/index.d.ts
CHANGED
|
@@ -1,7 +1,10 @@
|
|
|
1
|
-
export { hexToRgbaDeckGL } from './colors/
|
|
2
|
-
export { rgbaDeckGLToHex } from './colors/
|
|
3
|
-
export * from './colors/
|
|
4
|
-
export { matchText } from './strings/
|
|
5
|
-
export * from './strings/
|
|
1
|
+
export { hexToRgbaDeckGL } from './colors/hex-to-gba-deckgl/hex-to-gba-deckgl';
|
|
2
|
+
export { rgbaDeckGLToHex } from './colors/rgba-deck-gl-to-hex/rgba-deck-gl-to-hex';
|
|
3
|
+
export * from './colors/rgba-deck-gl-to-hex/types';
|
|
4
|
+
export { matchText } from './strings/match-text/match-text';
|
|
5
|
+
export * from './strings/match-text/types';
|
|
6
6
|
export { normalize } from './strings/normalize/normalize';
|
|
7
7
|
export * from './strings/normalize/types';
|
|
8
|
+
export { formatDate } from './formatters/date/format-date';
|
|
9
|
+
export { formatNumber, formatCurrency } from './formatters/number/format-number';
|
|
10
|
+
export * from './formatters/constants';
|
|
File without changes
|
|
File without changes
|
package/package.json
CHANGED
package/dist/ps-utils.es.js
DELETED
|
@@ -1,47 +0,0 @@
|
|
|
1
|
-
function f(n, r = 1) {
|
|
2
|
-
if (!n) {
|
|
3
|
-
console.warn(`hexToRgbaDeckGL: ${n} invalid hexadecimal format`);
|
|
4
|
-
return;
|
|
5
|
-
}
|
|
6
|
-
if (r < 0 || r > 1) {
|
|
7
|
-
console.warn(`hexToRgbaDeckGL: ${r} invalid alpha format`);
|
|
8
|
-
return;
|
|
9
|
-
}
|
|
10
|
-
if (n != null && n.includes("#") && (n = n.slice(1)), !/[0-9A-Fa-f]{6}/g.test(n) && !/[0-9A-Fa-f]{3}/g.test(n) && !/[0-9A-Fa-f]{2}/g.test(n)) {
|
|
11
|
-
console.warn(`hexToRgbaDeckGL: ${n} invalid hexadecimal format`);
|
|
12
|
-
return;
|
|
13
|
-
}
|
|
14
|
-
const t = n.length;
|
|
15
|
-
t < 6 && (n = n.slice(0, 6 - t).repeat(6 / t));
|
|
16
|
-
const e = parseInt(n.length === 3 ? n.slice(0, 1).repeat(2) : n.slice(0, 2), 16), o = parseInt(n.length === 3 ? n.slice(1, 2).repeat(2) : n.slice(2, 4), 16), s = parseInt(n.length === 3 ? n.slice(2, 3).repeat(2) : n.slice(4, 6), 16);
|
|
17
|
-
return [e, o, s, r * 255];
|
|
18
|
-
}
|
|
19
|
-
function g(n, { withPrefix: r = !0 } = {}) {
|
|
20
|
-
if (!n || !n.length) {
|
|
21
|
-
console.warn("rgbaDeckGLToHex: invalid array or empty values");
|
|
22
|
-
return;
|
|
23
|
-
}
|
|
24
|
-
if (n.some((o) => o < 0 || o > 255)) {
|
|
25
|
-
console.warn(`rgbaDeckGLToHex: [${n.toString()}] invalid array value format`);
|
|
26
|
-
return;
|
|
27
|
-
}
|
|
28
|
-
const e = n.map((o) => o.toString(16).padStart(2, "0")).join("");
|
|
29
|
-
return `${r ? "#" : ""}${e}`;
|
|
30
|
-
}
|
|
31
|
-
function u(n, { format: r = "NFD", replaceUnicode: t = "[\u0300-\u036F]" } = {}) {
|
|
32
|
-
const e = new RegExp(t, "g");
|
|
33
|
-
return n.normalize(r).replace(e, "");
|
|
34
|
-
}
|
|
35
|
-
function c(n, r, { matchFn: t, normalizeOptions: e } = {}) {
|
|
36
|
-
const o = new RegExp(u(n.toLowerCase(), e), "gi");
|
|
37
|
-
return Array.isArray(r) ? r.filter((s) => {
|
|
38
|
-
const i = t ? t(s) : s;
|
|
39
|
-
return u(i).match(o);
|
|
40
|
-
}) : u(r).match(o) ? r : null;
|
|
41
|
-
}
|
|
42
|
-
export {
|
|
43
|
-
f as hexToRgbaDeckGL,
|
|
44
|
-
c as matchText,
|
|
45
|
-
u as normalize,
|
|
46
|
-
g as rgbaDeckGLToHex
|
|
47
|
-
};
|
package/dist/ps-utils.umd.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
(function(t,i){typeof exports=="object"&&typeof module<"u"?i(exports):typeof define=="function"&&define.amd?define(["exports"],i):(t=typeof globalThis<"u"?globalThis:t||self,i(t.PsUtils={}))})(this,function(t){"use strict";function i(n,e=1){if(!n){console.warn(`hexToRgbaDeckGL: ${n} invalid hexadecimal format`);return}if(e<0||e>1){console.warn(`hexToRgbaDeckGL: ${e} invalid alpha format`);return}if(n!=null&&n.includes("#")&&(n=n.slice(1)),!/[0-9A-Fa-f]{6}/g.test(n)&&!/[0-9A-Fa-f]{3}/g.test(n)&&!/[0-9A-Fa-f]{2}/g.test(n)){console.warn(`hexToRgbaDeckGL: ${n} invalid hexadecimal format`);return}const r=n.length;r<6&&(n=n.slice(0,6-r).repeat(6/r));const s=parseInt(n.length===3?n.slice(0,1).repeat(2):n.slice(0,2),16),o=parseInt(n.length===3?n.slice(1,2).repeat(2):n.slice(2,4),16),u=parseInt(n.length===3?n.slice(2,3).repeat(2):n.slice(4,6),16);return[s,o,u,e*255]}function c(n,{withPrefix:e=!0}={}){if(!n||!n.length){console.warn("rgbaDeckGLToHex: invalid array or empty values");return}if(n.some(o=>o<0||o>255)){console.warn(`rgbaDeckGLToHex: [${n.toString()}] invalid array value format`);return}const s=n.map(o=>o.toString(16).padStart(2,"0")).join("");return`${e?"#":""}${s}`}function f(n,{format:e="NFD",replaceUnicode:r="[\u0300-\u036F]"}={}){const s=new RegExp(r,"g");return n.normalize(e).replace(s,"")}function g(n,e,{matchFn:r,normalizeOptions:s}={}){const o=new RegExp(f(n.toLowerCase(),s),"gi");return Array.isArray(e)?e.filter(u=>{const l=r?r(u):u;return f(l).match(o)}):f(e).match(o)?e:null}t.hexToRgbaDeckGL=i,t.matchText=g,t.normalize=f,t.rgbaDeckGLToHex=c,Object.defineProperties(t,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}})});
|