@carto/ps-utils 1.4.0 → 1.6.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 +126 -95
- package/dist/types/colors/index.d.ts +3 -0
- package/dist/types/debounce/debounce.d.ts +7 -0
- package/dist/types/index.d.ts +10 -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 D(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 R(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 T(t,e){return(...r)=>{clearTimeout(0),setTimeout(()=>t(...r),e)}}const m=63710088e-1;function w(t){return b.geomReduce(t,function(e,n){return e+h(n)},0)}function h(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}function C(t){try{if(navigator.clipboard)navigator.clipboard.writeText(t);else{const e=document.createElement("input");e.innerHTML=t,A(e)}}catch(e){throw new Error(e)}}function A(t){const e=t.contentEditable,n=t.readOnly;try{t.contentEditable="true",t.readOnly=!1,E(t)}finally{t.contentEditable=e,t.readOnly=n}}function E(t){const e=document.createRange(),n=window.getSelection();e.selectNodeContents(t),n?.removeAllRanges(),n?.addRange(e),t.setSelectionRange(0,999999),document.execCommand("copy")}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 I(t,e,n){return Intl.DateTimeFormat(e,n).format(t)}function d(t,e,n){return Intl.NumberFormat(e,n).format(t)}function L(t,e,n={}){return d(t,e,{...g.NUMBER,...n})}function N(t,e,n={}){return d(t,e,{...g.CURRENCY,...n})}const S=/:+[a-z]+/gi;function v(t,e=[]){let n=t;const o=n.match(S)||[],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 F(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=w;exports.copy=C;exports.debounce=T;exports.formatCurrency=N;exports.formatDate=I;exports.formatNumber=L;exports.hexToRgbaDeckGL=D;exports.matchText=F;exports.normalize=l;exports.replaceRoute=v;exports.rgbaDeckGLToHex=R;
|
package/dist/index.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { geomReduce as
|
|
2
|
-
function
|
|
1
|
+
import { geomReduce as b } from "@turf/meta";
|
|
2
|
+
function E(t, n = 1) {
|
|
3
3
|
if (!t) {
|
|
4
4
|
console.warn(`hexToRgbaDeckGL: ${t} invalid hexadecimal format`);
|
|
5
5
|
return;
|
|
@@ -12,115 +12,57 @@ 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
|
-
|
|
46
|
-
}
|
|
47
|
-
function F(t, n, { matchFn: r, normalizeOptions: i } = {}) {
|
|
48
|
-
const e = new RegExp(
|
|
49
|
-
l(t.toLowerCase(), i),
|
|
50
|
-
"gi"
|
|
51
|
-
);
|
|
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
|
-
function T(t, n, r) {
|
|
58
|
-
return Intl.DateTimeFormat(n, r).format(t);
|
|
59
|
-
}
|
|
60
|
-
const y = {
|
|
61
|
-
NUMBER: {
|
|
62
|
-
style: "decimal",
|
|
63
|
-
maximumFractionDigits: 1,
|
|
64
|
-
minimumFractionDigits: 0,
|
|
65
|
-
notation: "compact",
|
|
66
|
-
compactDisplay: "short"
|
|
67
|
-
},
|
|
68
|
-
CURRENCY: {
|
|
69
|
-
style: "currency",
|
|
70
|
-
currency: "USD",
|
|
71
|
-
maximumFractionDigits: 2,
|
|
72
|
-
minimumFractionDigits: 2,
|
|
73
|
-
notation: "compact",
|
|
74
|
-
compactDisplay: "short"
|
|
75
|
-
},
|
|
76
|
-
DATE: {
|
|
77
|
-
year: "numeric",
|
|
78
|
-
month: "2-digit",
|
|
79
|
-
day: "2-digit"
|
|
80
|
-
}
|
|
81
|
-
};
|
|
82
|
-
function D(t, n, r) {
|
|
83
|
-
return Intl.NumberFormat(n, r).format(t);
|
|
84
|
-
}
|
|
85
|
-
function b(t, n, r = {}) {
|
|
86
|
-
return D(t, n, { ...y.NUMBER, ...r });
|
|
87
|
-
}
|
|
88
|
-
function M(t, n, r = {}) {
|
|
89
|
-
return D(t, n, { ...y.CURRENCY, ...r });
|
|
90
|
-
}
|
|
91
|
-
const A = /:+[a-z]+/gi;
|
|
92
|
-
function k(t, n = []) {
|
|
93
|
-
let r = t;
|
|
94
|
-
const i = r.match(A) || [], e = Array.isArray(n);
|
|
95
|
-
return i.forEach((o, a) => {
|
|
96
|
-
let c;
|
|
97
|
-
if (e)
|
|
98
|
-
c = n[a];
|
|
99
|
-
else {
|
|
100
|
-
const u = o.substring(1);
|
|
101
|
-
c = n[u];
|
|
102
|
-
}
|
|
103
|
-
r = r.replace(o, c?.toString());
|
|
104
|
-
}), r;
|
|
43
|
+
function C(t, n) {
|
|
44
|
+
return (...r) => {
|
|
45
|
+
clearTimeout(0), setTimeout(() => t(...r), n);
|
|
46
|
+
};
|
|
105
47
|
}
|
|
106
48
|
const g = 63710088e-1;
|
|
107
|
-
function
|
|
108
|
-
return
|
|
49
|
+
function I(t) {
|
|
50
|
+
return b(
|
|
109
51
|
t,
|
|
110
|
-
function(n,
|
|
111
|
-
return n +
|
|
52
|
+
function(n, e) {
|
|
53
|
+
return n + D(e);
|
|
112
54
|
},
|
|
113
55
|
0
|
|
114
56
|
);
|
|
115
57
|
}
|
|
116
|
-
function
|
|
117
|
-
let n = 0,
|
|
58
|
+
function D(t) {
|
|
59
|
+
let n = 0, e;
|
|
118
60
|
switch (t.type) {
|
|
119
61
|
case "Polygon":
|
|
120
62
|
return p(t.coordinates);
|
|
121
63
|
case "MultiPolygon":
|
|
122
|
-
for (
|
|
123
|
-
n += p(t.coordinates[
|
|
64
|
+
for (e = 0; e < t.coordinates.length; e++)
|
|
65
|
+
n += p(t.coordinates[e]);
|
|
124
66
|
return n;
|
|
125
67
|
case "Point":
|
|
126
68
|
case "MultiPoint":
|
|
@@ -134,33 +76,122 @@ function p(t) {
|
|
|
134
76
|
let n = 0;
|
|
135
77
|
if (t && t.length > 0) {
|
|
136
78
|
n += Math.abs(m(t[0]));
|
|
137
|
-
for (let
|
|
138
|
-
n -= Math.abs(m(t[
|
|
79
|
+
for (let e = 1; e < t.length; e++)
|
|
80
|
+
n -= Math.abs(m(t[e]));
|
|
139
81
|
}
|
|
140
82
|
return n;
|
|
141
83
|
}
|
|
142
84
|
function m(t) {
|
|
143
|
-
let n,
|
|
85
|
+
let n, e, o, r, i, a, c, u = 0;
|
|
144
86
|
const s = t.length;
|
|
145
87
|
if (s > 2) {
|
|
146
88
|
for (c = 0; c < s; c++)
|
|
147
|
-
c === s - 2 ? (
|
|
89
|
+
c === s - 2 ? (r = s - 2, i = s - 1, a = 0) : c === s - 1 ? (r = s - 1, i = 0, a = 1) : (r = c, i = c + 1, a = c + 2), n = t[r], e = t[i], o = t[a], u += (l(o[0]) - l(n[0])) * Math.sin(l(e[1]));
|
|
148
90
|
u = u * g * g / 2;
|
|
149
91
|
}
|
|
150
92
|
return u;
|
|
151
93
|
}
|
|
152
|
-
function
|
|
94
|
+
function l(t) {
|
|
153
95
|
return t * Math.PI / 180;
|
|
154
96
|
}
|
|
97
|
+
function L(t) {
|
|
98
|
+
try {
|
|
99
|
+
if (navigator.clipboard)
|
|
100
|
+
navigator.clipboard.writeText(t);
|
|
101
|
+
else {
|
|
102
|
+
const n = document.createElement("input");
|
|
103
|
+
n.innerHTML = t, R(n);
|
|
104
|
+
}
|
|
105
|
+
} catch (n) {
|
|
106
|
+
throw new Error(n);
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
function R(t) {
|
|
110
|
+
const n = t.contentEditable, e = t.readOnly;
|
|
111
|
+
try {
|
|
112
|
+
t.contentEditable = "true", t.readOnly = !1, w(t);
|
|
113
|
+
} finally {
|
|
114
|
+
t.contentEditable = n, t.readOnly = e;
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
function w(t) {
|
|
118
|
+
const n = document.createRange(), e = window.getSelection();
|
|
119
|
+
n.selectNodeContents(t), e?.removeAllRanges(), e?.addRange(n), t.setSelectionRange(0, 999999), document.execCommand("copy");
|
|
120
|
+
}
|
|
121
|
+
const y = {
|
|
122
|
+
NUMBER: {
|
|
123
|
+
style: "decimal",
|
|
124
|
+
maximumFractionDigits: 1,
|
|
125
|
+
minimumFractionDigits: 0,
|
|
126
|
+
notation: "compact",
|
|
127
|
+
compactDisplay: "short"
|
|
128
|
+
},
|
|
129
|
+
CURRENCY: {
|
|
130
|
+
style: "currency",
|
|
131
|
+
currency: "USD",
|
|
132
|
+
maximumFractionDigits: 2,
|
|
133
|
+
minimumFractionDigits: 2,
|
|
134
|
+
notation: "compact",
|
|
135
|
+
compactDisplay: "short"
|
|
136
|
+
},
|
|
137
|
+
DATE: {
|
|
138
|
+
year: "numeric",
|
|
139
|
+
month: "2-digit",
|
|
140
|
+
day: "2-digit"
|
|
141
|
+
}
|
|
142
|
+
};
|
|
143
|
+
function v(t, n, e) {
|
|
144
|
+
return Intl.DateTimeFormat(n, e).format(t);
|
|
145
|
+
}
|
|
146
|
+
function d(t, n, e) {
|
|
147
|
+
return Intl.NumberFormat(n, e).format(t);
|
|
148
|
+
}
|
|
149
|
+
function F(t, n, e = {}) {
|
|
150
|
+
return d(t, n, { ...y.NUMBER, ...e });
|
|
151
|
+
}
|
|
152
|
+
function M(t, n, e = {}) {
|
|
153
|
+
return d(t, n, { ...y.CURRENCY, ...e });
|
|
154
|
+
}
|
|
155
|
+
const T = /:+[a-z]+/gi;
|
|
156
|
+
function N(t, n = []) {
|
|
157
|
+
let e = t;
|
|
158
|
+
const o = e.match(T) || [], r = Array.isArray(n);
|
|
159
|
+
return o.forEach((i, a) => {
|
|
160
|
+
let c;
|
|
161
|
+
if (r)
|
|
162
|
+
c = n[a];
|
|
163
|
+
else {
|
|
164
|
+
const u = i.substring(1);
|
|
165
|
+
c = n[u];
|
|
166
|
+
}
|
|
167
|
+
e = e.replace(i, c?.toString());
|
|
168
|
+
}), e;
|
|
169
|
+
}
|
|
170
|
+
function f(t, { format: n = "NFD", replaceUnicode: e = "[̀-ͯ]" } = {}) {
|
|
171
|
+
const o = new RegExp(e, "g");
|
|
172
|
+
return t.normalize(n).replace(o, "");
|
|
173
|
+
}
|
|
174
|
+
function S(t, n, { matchFn: e, normalizeOptions: o } = {}) {
|
|
175
|
+
const r = new RegExp(
|
|
176
|
+
f(t.toLowerCase(), o),
|
|
177
|
+
"gi"
|
|
178
|
+
);
|
|
179
|
+
return Array.isArray(n) ? n.filter((i) => {
|
|
180
|
+
const a = e ? e(i) : i;
|
|
181
|
+
return f(a).match(r);
|
|
182
|
+
}) : f(n).match(r) ? n : null;
|
|
183
|
+
}
|
|
155
184
|
export {
|
|
156
185
|
y as CONFIG,
|
|
157
|
-
|
|
186
|
+
I as area,
|
|
187
|
+
L as copy,
|
|
188
|
+
C as debounce,
|
|
158
189
|
M as formatCurrency,
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
190
|
+
v as formatDate,
|
|
191
|
+
F as formatNumber,
|
|
192
|
+
E as hexToRgbaDeckGL,
|
|
193
|
+
S as matchText,
|
|
194
|
+
f as normalize,
|
|
195
|
+
N as replaceRoute,
|
|
196
|
+
h as rgbaDeckGLToHex
|
|
166
197
|
};
|
|
@@ -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,14 @@
|
|
|
1
|
-
export
|
|
2
|
-
export
|
|
3
|
-
export
|
|
4
|
-
export
|
|
5
|
-
export
|
|
6
|
-
export
|
|
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 { copy } from './clipboard/copy';
|
|
6
|
+
export * from './formatters/constants';
|
|
8
7
|
export { formatDate } from './formatters/date/format-date';
|
|
9
8
|
export { formatNumber, formatCurrency } from './formatters/number/format-number';
|
|
10
|
-
export * from './formatters/constants';
|
|
11
9
|
export * from './routes/replace-route';
|
|
12
10
|
export * from './routes/types';
|
|
13
|
-
export {
|
|
14
|
-
export
|
|
11
|
+
export { matchText } from './strings/match-text/match-text';
|
|
12
|
+
export { normalize } from './strings/normalize/normalize';
|
|
13
|
+
export * from './strings/match-text/types';
|
|
14
|
+
export * from './strings/normalize/types';
|