@carto/ps-utils 1.4.0 → 1.5.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/index.cjs +1 -1
- package/dist/index.js +103 -97
- package/dist/types/colors/index.d.ts +3 -0
- package/dist/types/debounce/debounce.d.ts +7 -0
- package/dist/types/index.d.ts +9 -10
- package/package.json +1 -1
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 b=require("@turf/meta");function R(t,e=1){if(!t){console.warn(`hexToRgbaDeckGL: ${t} invalid hexadecimal format`);return}if(e<0||e>1){console.warn(`hexToRgbaDeckGL: ${e} invalid alpha format`);return}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)){console.warn(`hexToRgbaDeckGL: ${t} invalid hexadecimal format`);return}const n=t.length;n<6&&(t=t.slice(0,6-n).repeat(6/n));const o=parseInt(t.length===3?t.slice(0,1).repeat(2):t.slice(0,2),16),r=parseInt(t.length===3?t.slice(1,2).repeat(2):t.slice(2,4),16),i=parseInt(t.length===3?t.slice(2,3).repeat(2):t.slice(4,6),16);return[o,r,i,e*255]}function T(t,{withPrefix:e=!0}={}){if(!t||!t.length){console.warn("rgbaDeckGLToHex: invalid array or empty values");return}if(t.some(r=>r<0||r>255)){console.warn(`rgbaDeckGLToHex: [${t.toString()}] invalid array value format`);return}const o=t.map(r=>r.toString(16).padStart(2,"0")).join("");return`${e?"#":""}${o}`}function I(t,e){return(...r)=>{clearTimeout(0),setTimeout(()=>t(...r),e)}}const m=63710088e-1;function h(t){return b.geomReduce(t,function(e,n){return e+A(n)},0)}function A(t){let e=0,n;switch(t.type){case"Polygon":return p(t.coordinates);case"MultiPolygon":for(n=0;n<t.coordinates.length;n++)e+=p(t.coordinates[n]);return e;case"Point":case"MultiPoint":case"LineString":case"MultiLineString":return 0}return 0}function p(t){let e=0;if(t&&t.length>0){e+=Math.abs(y(t[0]));for(let n=1;n<t.length;n++)e-=Math.abs(y(t[n]))}return e}function y(t){let e,n,o,r,i,a,c,s=0;const u=t.length;if(u>2){for(c=0;c<u;c++)c===u-2?(r=u-2,i=u-1,a=0):c===u-1?(r=u-1,i=0,a=1):(r=c,i=c+1,a=c+2),e=t[r],n=t[i],o=t[a],s+=(f(o[0])-f(e[0]))*Math.sin(f(n[1]));s=s*m*m/2}return s}function f(t){return t*Math.PI/180}const g={NUMBER:{style:"decimal",maximumFractionDigits:1,minimumFractionDigits:0,notation:"compact",compactDisplay:"short"},CURRENCY:{style:"currency",currency:"USD",maximumFractionDigits:2,minimumFractionDigits:2,notation:"compact",compactDisplay:"short"},DATE:{year:"numeric",month:"2-digit",day:"2-digit"}};function L(t,e,n){return Intl.DateTimeFormat(e,n).format(t)}function D(t,e,n){return Intl.NumberFormat(e,n).format(t)}function w(t,e,n={}){return D(t,e,{...g.NUMBER,...n})}function F(t,e,n={}){return D(t,e,{...g.CURRENCY,...n})}const G=/:+[a-z]+/gi;function k(t,e=[]){let n=t;const o=n.match(G)||[],r=Array.isArray(e);return o.forEach((i,a)=>{let c;if(r)c=e[a];else{const s=i.substring(1);c=e[s]}n=n.replace(i,c?.toString())}),n}function l(t,{format:e="NFD",replaceUnicode:n="[̀-ͯ]"}={}){const o=new RegExp(n,"g");return t.normalize(e).replace(o,"")}function M(t,e,{matchFn:n,normalizeOptions:o}={}){const r=new RegExp(l(t.toLowerCase(),o),"gi");return Array.isArray(e)?e.filter(i=>{const a=n?n(i):i;return l(a).match(r)}):l(e).match(r)?e:null}exports.CONFIG=g;exports.area=h;exports.debounce=I;exports.formatCurrency=F;exports.formatDate=L;exports.formatNumber=w;exports.hexToRgbaDeckGL=R;exports.matchText=M;exports.normalize=l;exports.replaceRoute=k;exports.rgbaDeckGLToHex=T;
|
package/dist/index.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { geomReduce as R } from "@turf/meta";
|
|
2
|
-
function
|
|
2
|
+
function T(t, n = 1) {
|
|
3
3
|
if (!t) {
|
|
4
4
|
console.warn(`hexToRgbaDeckGL: ${t} invalid hexadecimal format`);
|
|
5
5
|
return;
|
|
@@ -12,50 +12,87 @@ function w(t, n = 1) {
|
|
|
12
12
|
console.warn(`hexToRgbaDeckGL: ${t} invalid hexadecimal format`);
|
|
13
13
|
return;
|
|
14
14
|
}
|
|
15
|
-
const
|
|
16
|
-
|
|
17
|
-
const
|
|
15
|
+
const e = t.length;
|
|
16
|
+
e < 6 && (t = t.slice(0, 6 - e).repeat(6 / e));
|
|
17
|
+
const o = parseInt(
|
|
18
18
|
t.length === 3 ? t.slice(0, 1).repeat(2) : t.slice(0, 2),
|
|
19
19
|
16
|
|
20
|
-
),
|
|
20
|
+
), r = parseInt(
|
|
21
21
|
t.length === 3 ? t.slice(1, 2).repeat(2) : t.slice(2, 4),
|
|
22
22
|
16
|
|
23
|
-
),
|
|
23
|
+
), i = parseInt(
|
|
24
24
|
t.length === 3 ? t.slice(2, 3).repeat(2) : t.slice(4, 6),
|
|
25
25
|
16
|
|
26
26
|
);
|
|
27
|
-
return [
|
|
27
|
+
return [o, r, i, n * 255];
|
|
28
28
|
}
|
|
29
|
-
function
|
|
29
|
+
function h(t, { withPrefix: n = !0 } = {}) {
|
|
30
30
|
if (!t || !t.length) {
|
|
31
31
|
console.warn("rgbaDeckGLToHex: invalid array or empty values");
|
|
32
32
|
return;
|
|
33
33
|
}
|
|
34
|
-
if (t.some((
|
|
34
|
+
if (t.some((r) => r < 0 || r > 255)) {
|
|
35
35
|
console.warn(
|
|
36
36
|
`rgbaDeckGLToHex: [${t.toString()}] invalid array value format`
|
|
37
37
|
);
|
|
38
38
|
return;
|
|
39
39
|
}
|
|
40
|
-
const
|
|
41
|
-
return `${n ? "#" : ""}${
|
|
40
|
+
const o = t.map((r) => r.toString(16).padStart(2, "0")).join("");
|
|
41
|
+
return `${n ? "#" : ""}${o}`;
|
|
42
42
|
}
|
|
43
|
-
function
|
|
44
|
-
|
|
45
|
-
|
|
43
|
+
function w(t, n) {
|
|
44
|
+
return (...r) => {
|
|
45
|
+
clearTimeout(0), setTimeout(() => t(...r), n);
|
|
46
|
+
};
|
|
46
47
|
}
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
48
|
+
const g = 63710088e-1;
|
|
49
|
+
function L(t) {
|
|
50
|
+
return R(
|
|
51
|
+
t,
|
|
52
|
+
function(n, e) {
|
|
53
|
+
return n + A(e);
|
|
54
|
+
},
|
|
55
|
+
0
|
|
51
56
|
);
|
|
52
|
-
return Array.isArray(n) ? n.filter((o) => {
|
|
53
|
-
const a = r ? r(o) : o;
|
|
54
|
-
return l(a).match(e);
|
|
55
|
-
}) : l(n).match(e) ? n : null;
|
|
56
57
|
}
|
|
57
|
-
function
|
|
58
|
-
|
|
58
|
+
function A(t) {
|
|
59
|
+
let n = 0, e;
|
|
60
|
+
switch (t.type) {
|
|
61
|
+
case "Polygon":
|
|
62
|
+
return m(t.coordinates);
|
|
63
|
+
case "MultiPolygon":
|
|
64
|
+
for (e = 0; e < t.coordinates.length; e++)
|
|
65
|
+
n += m(t.coordinates[e]);
|
|
66
|
+
return n;
|
|
67
|
+
case "Point":
|
|
68
|
+
case "MultiPoint":
|
|
69
|
+
case "LineString":
|
|
70
|
+
case "MultiLineString":
|
|
71
|
+
return 0;
|
|
72
|
+
}
|
|
73
|
+
return 0;
|
|
74
|
+
}
|
|
75
|
+
function m(t) {
|
|
76
|
+
let n = 0;
|
|
77
|
+
if (t && t.length > 0) {
|
|
78
|
+
n += Math.abs(p(t[0]));
|
|
79
|
+
for (let e = 1; e < t.length; e++)
|
|
80
|
+
n -= Math.abs(p(t[e]));
|
|
81
|
+
}
|
|
82
|
+
return n;
|
|
83
|
+
}
|
|
84
|
+
function p(t) {
|
|
85
|
+
let n, e, o, r, i, u, c, s = 0;
|
|
86
|
+
const a = t.length;
|
|
87
|
+
if (a > 2) {
|
|
88
|
+
for (c = 0; c < a; c++)
|
|
89
|
+
c === a - 2 ? (r = a - 2, i = a - 1, u = 0) : c === a - 1 ? (r = a - 1, i = 0, u = 1) : (r = c, i = c + 1, u = c + 2), n = t[r], e = t[i], o = t[u], s += (l(o[0]) - l(n[0])) * Math.sin(l(e[1]));
|
|
90
|
+
s = s * g * g / 2;
|
|
91
|
+
}
|
|
92
|
+
return s;
|
|
93
|
+
}
|
|
94
|
+
function l(t) {
|
|
95
|
+
return t * Math.PI / 180;
|
|
59
96
|
}
|
|
60
97
|
const y = {
|
|
61
98
|
NUMBER: {
|
|
@@ -79,88 +116,57 @@ const y = {
|
|
|
79
116
|
day: "2-digit"
|
|
80
117
|
}
|
|
81
118
|
};
|
|
82
|
-
function
|
|
83
|
-
return Intl.
|
|
119
|
+
function F(t, n, e) {
|
|
120
|
+
return Intl.DateTimeFormat(n, e).format(t);
|
|
84
121
|
}
|
|
85
|
-
function
|
|
86
|
-
return
|
|
122
|
+
function D(t, n, e) {
|
|
123
|
+
return Intl.NumberFormat(n, e).format(t);
|
|
87
124
|
}
|
|
88
|
-
function M(t, n,
|
|
89
|
-
return D(t, n, { ...y.
|
|
125
|
+
function M(t, n, e = {}) {
|
|
126
|
+
return D(t, n, { ...y.NUMBER, ...e });
|
|
90
127
|
}
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
128
|
+
function k(t, n, e = {}) {
|
|
129
|
+
return D(t, n, { ...y.CURRENCY, ...e });
|
|
130
|
+
}
|
|
131
|
+
const I = /:+[a-z]+/gi;
|
|
132
|
+
function E(t, n = []) {
|
|
133
|
+
let e = t;
|
|
134
|
+
const o = e.match(I) || [], r = Array.isArray(n);
|
|
135
|
+
return o.forEach((i, u) => {
|
|
96
136
|
let c;
|
|
97
|
-
if (
|
|
98
|
-
c = n[a];
|
|
99
|
-
else {
|
|
100
|
-
const u = o.substring(1);
|
|
137
|
+
if (r)
|
|
101
138
|
c = n[u];
|
|
139
|
+
else {
|
|
140
|
+
const s = i.substring(1);
|
|
141
|
+
c = n[s];
|
|
102
142
|
}
|
|
103
|
-
|
|
104
|
-
}),
|
|
143
|
+
e = e.replace(i, c?.toString());
|
|
144
|
+
}), e;
|
|
105
145
|
}
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
return
|
|
109
|
-
t,
|
|
110
|
-
function(n, r) {
|
|
111
|
-
return n + I(r);
|
|
112
|
-
},
|
|
113
|
-
0
|
|
114
|
-
);
|
|
115
|
-
}
|
|
116
|
-
function I(t) {
|
|
117
|
-
let n = 0, r;
|
|
118
|
-
switch (t.type) {
|
|
119
|
-
case "Polygon":
|
|
120
|
-
return p(t.coordinates);
|
|
121
|
-
case "MultiPolygon":
|
|
122
|
-
for (r = 0; r < t.coordinates.length; r++)
|
|
123
|
-
n += p(t.coordinates[r]);
|
|
124
|
-
return n;
|
|
125
|
-
case "Point":
|
|
126
|
-
case "MultiPoint":
|
|
127
|
-
case "LineString":
|
|
128
|
-
case "MultiLineString":
|
|
129
|
-
return 0;
|
|
130
|
-
}
|
|
131
|
-
return 0;
|
|
146
|
+
function f(t, { format: n = "NFD", replaceUnicode: e = "[̀-ͯ]" } = {}) {
|
|
147
|
+
const o = new RegExp(e, "g");
|
|
148
|
+
return t.normalize(n).replace(o, "");
|
|
132
149
|
}
|
|
133
|
-
function
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
}
|
|
142
|
-
function m(t) {
|
|
143
|
-
let n, r, i, e, o, a, c, u = 0;
|
|
144
|
-
const s = t.length;
|
|
145
|
-
if (s > 2) {
|
|
146
|
-
for (c = 0; c < s; c++)
|
|
147
|
-
c === s - 2 ? (e = s - 2, o = s - 1, a = 0) : c === s - 1 ? (e = s - 1, o = 0, a = 1) : (e = c, o = c + 1, a = c + 2), n = t[e], r = t[o], i = t[a], u += (f(i[0]) - f(n[0])) * Math.sin(f(r[1]));
|
|
148
|
-
u = u * g * g / 2;
|
|
149
|
-
}
|
|
150
|
-
return u;
|
|
151
|
-
}
|
|
152
|
-
function f(t) {
|
|
153
|
-
return t * Math.PI / 180;
|
|
150
|
+
function G(t, n, { matchFn: e, normalizeOptions: o } = {}) {
|
|
151
|
+
const r = new RegExp(
|
|
152
|
+
f(t.toLowerCase(), o),
|
|
153
|
+
"gi"
|
|
154
|
+
);
|
|
155
|
+
return Array.isArray(n) ? n.filter((i) => {
|
|
156
|
+
const u = e ? e(i) : i;
|
|
157
|
+
return f(u).match(r);
|
|
158
|
+
}) : f(n).match(r) ? n : null;
|
|
154
159
|
}
|
|
155
160
|
export {
|
|
156
161
|
y as CONFIG,
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
162
|
+
L as area,
|
|
163
|
+
w as debounce,
|
|
164
|
+
k as formatCurrency,
|
|
165
|
+
F as formatDate,
|
|
166
|
+
M as formatNumber,
|
|
167
|
+
T as hexToRgbaDeckGL,
|
|
168
|
+
G as matchText,
|
|
169
|
+
f as normalize,
|
|
170
|
+
E as replaceRoute,
|
|
171
|
+
h as rgbaDeckGLToHex
|
|
166
172
|
};
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Returns a debounced version of the provided function.
|
|
3
|
+
* @param func - The function to debounce.
|
|
4
|
+
* @param {number} waitFor - The number of milliseconds to wait before invoking the debounced function.
|
|
5
|
+
* @returns A debounced version of the provided function.
|
|
6
|
+
*/
|
|
7
|
+
export declare function debounce<F extends (...args: any[]) => any>(func: F, waitFor: number): (...args: Parameters<F>) => ReturnType<F>;
|
package/dist/types/index.d.ts
CHANGED
|
@@ -1,14 +1,13 @@
|
|
|
1
|
-
export
|
|
2
|
-
export
|
|
3
|
-
export
|
|
4
|
-
export
|
|
5
|
-
export * from './
|
|
6
|
-
export { normalize } from './strings/normalize/normalize';
|
|
7
|
-
export * from './strings/normalize/types';
|
|
1
|
+
export * from './colors';
|
|
2
|
+
export * from './debounce/debounce';
|
|
3
|
+
export { area } from './features/area';
|
|
4
|
+
export * from './features/types';
|
|
5
|
+
export * from './formatters/constants';
|
|
8
6
|
export { formatDate } from './formatters/date/format-date';
|
|
9
7
|
export { formatNumber, formatCurrency } from './formatters/number/format-number';
|
|
10
|
-
export * from './formatters/constants';
|
|
11
8
|
export * from './routes/replace-route';
|
|
12
9
|
export * from './routes/types';
|
|
13
|
-
export {
|
|
14
|
-
export
|
|
10
|
+
export { matchText } from './strings/match-text/match-text';
|
|
11
|
+
export { normalize } from './strings/normalize/normalize';
|
|
12
|
+
export * from './strings/match-text/types';
|
|
13
|
+
export * from './strings/normalize/types';
|