@carto/ps-utils 1.5.0 → 1.6.1

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 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;
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 R } from "@turf/meta";
2
- function T(t, n = 1) {
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;
@@ -40,29 +40,29 @@ function h(t, { withPrefix: n = !0 } = {}) {
40
40
  const o = t.map((r) => r.toString(16).padStart(2, "0")).join("");
41
41
  return `${n ? "#" : ""}${o}`;
42
42
  }
43
- function w(t, n) {
43
+ function C(t, n) {
44
44
  return (...r) => {
45
45
  clearTimeout(0), setTimeout(() => t(...r), n);
46
46
  };
47
47
  }
48
48
  const g = 63710088e-1;
49
- function L(t) {
50
- return R(
49
+ function I(t) {
50
+ return b(
51
51
  t,
52
52
  function(n, e) {
53
- return n + A(e);
53
+ return n + D(e);
54
54
  },
55
55
  0
56
56
  );
57
57
  }
58
- function A(t) {
58
+ function D(t) {
59
59
  let n = 0, e;
60
60
  switch (t.type) {
61
61
  case "Polygon":
62
- return m(t.coordinates);
62
+ return p(t.coordinates);
63
63
  case "MultiPolygon":
64
64
  for (e = 0; e < t.coordinates.length; e++)
65
- n += m(t.coordinates[e]);
65
+ n += p(t.coordinates[e]);
66
66
  return n;
67
67
  case "Point":
68
68
  case "MultiPoint":
@@ -72,28 +72,52 @@ function A(t) {
72
72
  }
73
73
  return 0;
74
74
  }
75
- function m(t) {
75
+ function p(t) {
76
76
  let n = 0;
77
77
  if (t && t.length > 0) {
78
- n += Math.abs(p(t[0]));
78
+ n += Math.abs(m(t[0]));
79
79
  for (let e = 1; e < t.length; e++)
80
- n -= Math.abs(p(t[e]));
80
+ n -= Math.abs(m(t[e]));
81
81
  }
82
82
  return n;
83
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;
84
+ function m(t) {
85
+ let n, e, o, r, i, a, c, u = 0;
86
+ const s = t.length;
87
+ if (s > 2) {
88
+ for (c = 0; c < s; c++)
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]));
90
+ u = u * g * g / 2;
91
91
  }
92
- return s;
92
+ return u;
93
93
  }
94
94
  function l(t) {
95
95
  return t * Math.PI / 180;
96
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
+ }
97
121
  const y = {
98
122
  NUMBER: {
99
123
  style: "decimal",
@@ -116,29 +140,29 @@ const y = {
116
140
  day: "2-digit"
117
141
  }
118
142
  };
119
- function F(t, n, e) {
143
+ function v(t, n, e) {
120
144
  return Intl.DateTimeFormat(n, e).format(t);
121
145
  }
122
- function D(t, n, e) {
146
+ function d(t, n, e) {
123
147
  return Intl.NumberFormat(n, e).format(t);
124
148
  }
125
- function M(t, n, e = {}) {
126
- return D(t, n, { ...y.NUMBER, ...e });
149
+ function F(t, n, e = {}) {
150
+ return d(t, n, { ...y.NUMBER, ...e });
127
151
  }
128
- function k(t, n, e = {}) {
129
- return D(t, n, { ...y.CURRENCY, ...e });
152
+ function M(t, n, e = {}) {
153
+ return d(t, n, { ...y.CURRENCY, ...e });
130
154
  }
131
- const I = /:+[a-z]+/gi;
132
- function E(t, n = []) {
155
+ const T = /:+[a-z]+/gi;
156
+ function N(t, n = []) {
133
157
  let e = t;
134
- const o = e.match(I) || [], r = Array.isArray(n);
135
- return o.forEach((i, u) => {
158
+ const o = e.match(T) || [], r = Array.isArray(n);
159
+ return o.forEach((i, a) => {
136
160
  let c;
137
161
  if (r)
138
- c = n[u];
162
+ c = n[a];
139
163
  else {
140
- const s = i.substring(1);
141
- c = n[s];
164
+ const u = i.substring(1);
165
+ c = n[u];
142
166
  }
143
167
  e = e.replace(i, c?.toString());
144
168
  }), e;
@@ -147,26 +171,27 @@ function f(t, { format: n = "NFD", replaceUnicode: e = "[̀-ͯ]" } = {}) {
147
171
  const o = new RegExp(e, "g");
148
172
  return t.normalize(n).replace(o, "");
149
173
  }
150
- function G(t, n, { matchFn: e, normalizeOptions: o } = {}) {
174
+ function S(t, n, { matchFn: e, normalizeOptions: o } = {}) {
151
175
  const r = new RegExp(
152
176
  f(t.toLowerCase(), o),
153
177
  "gi"
154
178
  );
155
179
  return Array.isArray(n) ? n.filter((i) => {
156
- const u = e ? e(i) : i;
157
- return f(u).match(r);
180
+ const a = e ? e(i) : i;
181
+ return f(a).match(r);
158
182
  }) : f(n).match(r) ? n : null;
159
183
  }
160
184
  export {
161
185
  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,
186
+ I as area,
187
+ L as copy,
188
+ C as debounce,
189
+ M as formatCurrency,
190
+ v as formatDate,
191
+ F as formatNumber,
192
+ E as hexToRgbaDeckGL,
193
+ S as matchText,
169
194
  f as normalize,
170
- E as replaceRoute,
195
+ N as replaceRoute,
171
196
  h as rgbaDeckGLToHex
172
197
  };
@@ -20,7 +20,5 @@
20
20
  * ```ts
21
21
  * hexToRgbaDeckGL('#d1', 1)
22
22
  * ```
23
- *
24
- * @deprecated use `hexToRgb` from `@deck.gl/carto/typed/style/palette` instead
25
23
  */
26
24
  export declare function hexToRgbaDeckGL(hexadecimal: string, alpha?: number): number[] | undefined;
@@ -1,3 +1,3 @@
1
- export { hexToRgbaDeckGL } from './hex-to-gba-deckgl/hex-to-gba-deckgl';
1
+ export { hexToRgbaDeckGL } from './hex-to-rgba-deckgl/hex-to-rgba-deckgl';
2
2
  export { rgbaDeckGLToHex } from './rgba-deck-gl-to-hex/rgba-deck-gl-to-hex';
3
3
  export * from './rgba-deck-gl-to-hex/types';
@@ -2,6 +2,7 @@ export * from './colors';
2
2
  export * from './debounce/debounce';
3
3
  export { area } from './features/area';
4
4
  export * from './features/types';
5
+ export { copy } from './clipboard/copy';
5
6
  export * from './formatters/constants';
6
7
  export { formatDate } from './formatters/date/format-date';
7
8
  export { formatNumber, formatCurrency } from './formatters/number/format-number';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@carto/ps-utils",
3
- "version": "1.5.0",
3
+ "version": "1.6.1",
4
4
  "description": "CARTO's Professional Service Utils library",
5
5
  "files": [
6
6
  "dist"