@carto/ps-utils 1.3.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 +109 -52
- package/dist/types/colors/index.d.ts +3 -0
- package/dist/types/debounce/debounce.d.ts +7 -0
- package/dist/types/features/area.d.ts +17 -0
- package/dist/types/features/types.d.ts +4 -0
- package/dist/types/index.d.ts +9 -8
- package/package.json +11 -2
package/dist/index.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});function
|
|
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,62 +1,100 @@
|
|
|
1
|
-
|
|
1
|
+
import { geomReduce as R } from "@turf/meta";
|
|
2
|
+
function T(t, n = 1) {
|
|
2
3
|
if (!t) {
|
|
3
4
|
console.warn(`hexToRgbaDeckGL: ${t} invalid hexadecimal format`);
|
|
4
5
|
return;
|
|
5
6
|
}
|
|
6
|
-
if (
|
|
7
|
-
console.warn(`hexToRgbaDeckGL: ${
|
|
7
|
+
if (n < 0 || n > 1) {
|
|
8
|
+
console.warn(`hexToRgbaDeckGL: ${n} invalid alpha format`);
|
|
8
9
|
return;
|
|
9
10
|
}
|
|
10
11
|
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
12
|
console.warn(`hexToRgbaDeckGL: ${t} invalid hexadecimal format`);
|
|
12
13
|
return;
|
|
13
14
|
}
|
|
14
|
-
const
|
|
15
|
-
|
|
16
|
-
const
|
|
15
|
+
const e = t.length;
|
|
16
|
+
e < 6 && (t = t.slice(0, 6 - e).repeat(6 / e));
|
|
17
|
+
const o = parseInt(
|
|
17
18
|
t.length === 3 ? t.slice(0, 1).repeat(2) : t.slice(0, 2),
|
|
18
19
|
16
|
|
19
|
-
),
|
|
20
|
+
), r = parseInt(
|
|
20
21
|
t.length === 3 ? t.slice(1, 2).repeat(2) : t.slice(2, 4),
|
|
21
22
|
16
|
|
22
23
|
), i = parseInt(
|
|
23
24
|
t.length === 3 ? t.slice(2, 3).repeat(2) : t.slice(4, 6),
|
|
24
25
|
16
|
|
25
26
|
);
|
|
26
|
-
return [
|
|
27
|
+
return [o, r, i, n * 255];
|
|
27
28
|
}
|
|
28
|
-
function
|
|
29
|
+
function h(t, { withPrefix: n = !0 } = {}) {
|
|
29
30
|
if (!t || !t.length) {
|
|
30
31
|
console.warn("rgbaDeckGLToHex: invalid array or empty values");
|
|
31
32
|
return;
|
|
32
33
|
}
|
|
33
|
-
if (t.some((
|
|
34
|
+
if (t.some((r) => r < 0 || r > 255)) {
|
|
34
35
|
console.warn(
|
|
35
36
|
`rgbaDeckGLToHex: [${t.toString()}] invalid array value format`
|
|
36
37
|
);
|
|
37
38
|
return;
|
|
38
39
|
}
|
|
39
|
-
const
|
|
40
|
-
return `${
|
|
40
|
+
const o = t.map((r) => r.toString(16).padStart(2, "0")).join("");
|
|
41
|
+
return `${n ? "#" : ""}${o}`;
|
|
41
42
|
}
|
|
42
|
-
function
|
|
43
|
-
|
|
44
|
-
|
|
43
|
+
function w(t, n) {
|
|
44
|
+
return (...r) => {
|
|
45
|
+
clearTimeout(0), setTimeout(() => t(...r), n);
|
|
46
|
+
};
|
|
45
47
|
}
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
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
|
|
50
56
|
);
|
|
51
|
-
return Array.isArray(r) ? r.filter((i) => {
|
|
52
|
-
const s = n ? n(i) : i;
|
|
53
|
-
return u(s).match(o);
|
|
54
|
-
}) : u(r).match(o) ? r : null;
|
|
55
57
|
}
|
|
56
|
-
function
|
|
57
|
-
|
|
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;
|
|
58
96
|
}
|
|
59
|
-
const
|
|
97
|
+
const y = {
|
|
60
98
|
NUMBER: {
|
|
61
99
|
style: "decimal",
|
|
62
100
|
maximumFractionDigits: 1,
|
|
@@ -78,38 +116,57 @@ const a = {
|
|
|
78
116
|
day: "2-digit"
|
|
79
117
|
}
|
|
80
118
|
};
|
|
81
|
-
function
|
|
82
|
-
return Intl.
|
|
119
|
+
function F(t, n, e) {
|
|
120
|
+
return Intl.DateTimeFormat(n, e).format(t);
|
|
121
|
+
}
|
|
122
|
+
function D(t, n, e) {
|
|
123
|
+
return Intl.NumberFormat(n, e).format(t);
|
|
83
124
|
}
|
|
84
|
-
function
|
|
85
|
-
return
|
|
125
|
+
function M(t, n, e = {}) {
|
|
126
|
+
return D(t, n, { ...y.NUMBER, ...e });
|
|
86
127
|
}
|
|
87
|
-
function
|
|
88
|
-
return
|
|
128
|
+
function k(t, n, e = {}) {
|
|
129
|
+
return D(t, n, { ...y.CURRENCY, ...e });
|
|
89
130
|
}
|
|
90
|
-
const
|
|
91
|
-
function
|
|
92
|
-
let
|
|
93
|
-
const
|
|
94
|
-
return
|
|
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) => {
|
|
95
136
|
let c;
|
|
96
|
-
if (
|
|
97
|
-
c =
|
|
137
|
+
if (r)
|
|
138
|
+
c = n[u];
|
|
98
139
|
else {
|
|
99
|
-
const
|
|
100
|
-
c =
|
|
140
|
+
const s = i.substring(1);
|
|
141
|
+
c = n[s];
|
|
101
142
|
}
|
|
102
|
-
|
|
103
|
-
}),
|
|
143
|
+
e = e.replace(i, c?.toString());
|
|
144
|
+
}), e;
|
|
145
|
+
}
|
|
146
|
+
function f(t, { format: n = "NFD", replaceUnicode: e = "[̀-ͯ]" } = {}) {
|
|
147
|
+
const o = new RegExp(e, "g");
|
|
148
|
+
return t.normalize(n).replace(o, "");
|
|
149
|
+
}
|
|
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;
|
|
104
159
|
}
|
|
105
160
|
export {
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
161
|
+
y as CONFIG,
|
|
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
|
|
115
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>;
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import type { GeojsonAreaProps } from './types';
|
|
2
|
+
/**
|
|
3
|
+
* Takes one or more features and returns their area in square meters paying attention to earth radius.
|
|
4
|
+
* It's fixed in turf.js v7.0.0+ for previous versions of turf use this function instead turf.area
|
|
5
|
+
* @name area
|
|
6
|
+
* @param {GeojsonAreaProps>} geojson {GeoJSON} input GeoJSON feature(s)
|
|
7
|
+
* @returns {number} area in square meters
|
|
8
|
+
* @example
|
|
9
|
+
* let polygon = turf.polygon([[[125, -15], [113, -22], [154, -27], [144, -15], [125, -15]]]);
|
|
10
|
+
*
|
|
11
|
+
* let area = turf.area(polygon);
|
|
12
|
+
*
|
|
13
|
+
* //addToMap
|
|
14
|
+
* let addToMap = [polygon]
|
|
15
|
+
* polygon.properties.area = area
|
|
16
|
+
*/
|
|
17
|
+
export declare function area(geojson: GeojsonAreaProps): any;
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import type { Geometries } from '@turf/helpers';
|
|
2
|
+
import type { Feature, FeatureCollection, LineString, GeoJsonProperties, MultiLineString, MultiPoint, MultiPolygon, Point, Polygon } from 'geojson';
|
|
3
|
+
export type GeomAreaProps = Point | LineString | Polygon | MultiPoint | MultiLineString | MultiPolygon;
|
|
4
|
+
export type GeojsonAreaProps = Geometries | FeatureCollection<Geometries, GeoJsonProperties> | Feature<Geometries, GeoJsonProperties>;
|
package/dist/types/index.d.ts
CHANGED
|
@@ -1,12 +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';
|
|
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';
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@carto/ps-utils",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.5.0",
|
|
4
4
|
"description": "CARTO's Professional Service Utils library",
|
|
5
5
|
"files": [
|
|
6
6
|
"dist"
|
|
@@ -25,5 +25,14 @@
|
|
|
25
25
|
"test:related": "vitest --run --passWithNoTests",
|
|
26
26
|
"test:coverage": "vitest run --coverage"
|
|
27
27
|
},
|
|
28
|
-
"
|
|
28
|
+
"peerDependencies": {
|
|
29
|
+
"@turf/meta": ">= 6.x < 7.x"
|
|
30
|
+
},
|
|
31
|
+
"dependencies": {
|
|
32
|
+
"@turf/meta": "6.5.0"
|
|
33
|
+
},
|
|
34
|
+
"devDependencies": {
|
|
35
|
+
"@turf/helpers": "6.5.0",
|
|
36
|
+
"@types/geojson": "7946.0.11"
|
|
37
|
+
}
|
|
29
38
|
}
|