@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 CHANGED
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const R=require("@turf/meta");function b(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 i=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),o=parseInt(t.length===3?t.slice(2,3).repeat(2):t.slice(4,6),16);return[i,r,o,e*255]}function I(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 i=t.map(r=>r.toString(16).padStart(2,"0")).join("");return`${e?"#":""}${i}`}function l(t,{format:e="NFD",replaceUnicode:n="[̀-ͯ]"}={}){const i=new RegExp(n,"g");return t.normalize(e).replace(i,"")}function T(t,e,{matchFn:n,normalizeOptions:i}={}){const r=new RegExp(l(t.toLowerCase(),i),"gi");return Array.isArray(e)?e.filter(o=>{const c=n?n(o):o;return l(c).match(r)}):l(e).match(r)?e:null}function h(t,e,n){return Intl.DateTimeFormat(e,n).format(t)}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 D(t,e,n){return Intl.NumberFormat(e,n).format(t)}function A(t,e,n={}){return D(t,e,{...g.NUMBER,...n})}function L(t,e,n={}){return D(t,e,{...g.CURRENCY,...n})}const w=/:+[a-z]+/gi;function F(t,e=[]){let n=t;const i=n.match(w)||[],r=Array.isArray(e);return i.forEach((o,c)=>{let a;if(r)a=e[c];else{const s=o.substring(1);a=e[s]}n=n.replace(o,a?.toString())}),n}const m=63710088e-1;function G(t){return R.geomReduce(t,function(e,n){return e+k(n)},0)}function k(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,i,r,o,c,a,s=0;const u=t.length;if(u>2){for(a=0;a<u;a++)a===u-2?(r=u-2,o=u-1,c=0):a===u-1?(r=u-1,o=0,c=1):(r=a,o=a+1,c=a+2),e=t[r],n=t[o],i=t[c],s+=(f(i[0])-f(e[0]))*Math.sin(f(n[1]));s=s*m*m/2}return s}function f(t){return t*Math.PI/180}exports.CONFIG=g;exports.area=G;exports.formatCurrency=L;exports.formatDate=h;exports.formatNumber=A;exports.hexToRgbaDeckGL=b;exports.matchText=T;exports.normalize=l;exports.replaceRoute=F;exports.rgbaDeckGLToHex=I;
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 w(t, n = 1) {
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 r = t.length;
16
- r < 6 && (t = t.slice(0, 6 - r).repeat(6 / r));
17
- const i = parseInt(
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
- ), e = parseInt(
20
+ ), r = parseInt(
21
21
  t.length === 3 ? t.slice(1, 2).repeat(2) : t.slice(2, 4),
22
22
  16
23
- ), o = parseInt(
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 [i, e, o, n * 255];
27
+ return [o, r, i, n * 255];
28
28
  }
29
- function L(t, { withPrefix: n = !0 } = {}) {
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((e) => e < 0 || e > 255)) {
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 i = t.map((e) => e.toString(16).padStart(2, "0")).join("");
41
- return `${n ? "#" : ""}${i}`;
40
+ const o = t.map((r) => r.toString(16).padStart(2, "0")).join("");
41
+ return `${n ? "#" : ""}${o}`;
42
42
  }
43
- function l(t, { format: n = "NFD", replaceUnicode: r = "[̀-ͯ]" } = {}) {
44
- const i = new RegExp(r, "g");
45
- return t.normalize(n).replace(i, "");
43
+ function w(t, n) {
44
+ return (...r) => {
45
+ clearTimeout(0), setTimeout(() => t(...r), n);
46
+ };
46
47
  }
47
- function F(t, n, { matchFn: r, normalizeOptions: i } = {}) {
48
- const e = new RegExp(
49
- l(t.toLowerCase(), i),
50
- "gi"
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 T(t, n, r) {
58
- return Intl.DateTimeFormat(n, r).format(t);
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 D(t, n, r) {
83
- return Intl.NumberFormat(n, r).format(t);
119
+ function F(t, n, e) {
120
+ return Intl.DateTimeFormat(n, e).format(t);
84
121
  }
85
- function b(t, n, r = {}) {
86
- return D(t, n, { ...y.NUMBER, ...r });
122
+ function D(t, n, e) {
123
+ return Intl.NumberFormat(n, e).format(t);
87
124
  }
88
- function M(t, n, r = {}) {
89
- return D(t, n, { ...y.CURRENCY, ...r });
125
+ function M(t, n, e = {}) {
126
+ return D(t, n, { ...y.NUMBER, ...e });
90
127
  }
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) => {
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 (e)
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
- r = r.replace(o, c?.toString());
104
- }), r;
143
+ e = e.replace(i, c?.toString());
144
+ }), e;
105
145
  }
106
- const g = 63710088e-1;
107
- function E(t) {
108
- return R(
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 p(t) {
134
- let n = 0;
135
- if (t && t.length > 0) {
136
- n += Math.abs(m(t[0]));
137
- for (let r = 1; r < t.length; r++)
138
- n -= Math.abs(m(t[r]));
139
- }
140
- return n;
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
- E as area,
158
- M as formatCurrency,
159
- T as formatDate,
160
- b as formatNumber,
161
- w as hexToRgbaDeckGL,
162
- F as matchText,
163
- l as normalize,
164
- k as replaceRoute,
165
- L as rgbaDeckGLToHex
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,3 @@
1
+ export { hexToRgbaDeckGL } from './hex-to-gba-deckgl/hex-to-gba-deckgl';
2
+ export { rgbaDeckGLToHex } from './rgba-deck-gl-to-hex/rgba-deck-gl-to-hex';
3
+ export * from './rgba-deck-gl-to-hex/types';
@@ -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>;
@@ -1,14 +1,13 @@
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
- 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 { area } from './features/area';
14
- export * from './features/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.4.0",
3
+ "version": "1.5.0",
4
4
  "description": "CARTO's Professional Service Utils library",
5
5
  "files": [
6
6
  "dist"