@carto/ps-utils 1.7.1 → 2.0.0-canary.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/LICENSE.md ADDED
@@ -0,0 +1,29 @@
1
+ BSD 3-Clause License
2
+
3
+ Copyright (c) 2023, CARTO
4
+ All rights reserved.
5
+
6
+ Redistribution and use in source and binary forms, with or without
7
+ modification, are permitted provided that the following conditions are met:
8
+
9
+ 1. Redistributions of source code must retain the above copyright notice, this
10
+ list of conditions and the following disclaimer.
11
+
12
+ 2. Redistributions in binary form must reproduce the above copyright notice,
13
+ this list of conditions and the following disclaimer in the documentation
14
+ and/or other materials provided with the distribution.
15
+
16
+ 3. Neither the name of the copyright holder nor the names of its
17
+ contributors may be used to endorse or promote products derived from
18
+ this software without specific prior written permission.
19
+
20
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
21
+ AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
22
+ IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
23
+ DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
24
+ FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
25
+ DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
26
+ SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
27
+ CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
28
+ OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
29
+ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
package/README.md CHANGED
@@ -1,21 +1,24 @@
1
- # CARTO PS Library - Utils
1
+ # The CARTO PS Utils Library
2
2
 
3
- This repository contains the packages with utils helpers.
3
+ <a aria-label="NPM version" href="https://www.npmjs.com/package/@carto/ps-utils">
4
+ <img alt="" src="https://img.shields.io/npm/v/@carto/ps-utils.svg?style=flat-square&labelColor=000000">
5
+ </a>
6
+ <a aria-label="License" href="https://github.com/CartoDB/carto-ps-lib/blob/canary/LICENSE.md">
7
+ <img alt="" src="https://img.shields.io/npm/l/@carto/ps-utils.svg?style=flat-square&labelColor=000000">
8
+ </a>
9
+ <a aria-label="CI status" href="https://github.com/carto/ps-helpers/actions/workflows/pull-request.yml?query=event%3Apush+branch%3Amain">
10
+ <img alt="" src="https://img.shields.io/github/actions/workflow/status/carto/ps-helpers/pull-request.yml?event=push&branch=main&style=flat-square&labelColor=000000">
11
+ </a>
4
12
 
5
- ## Installation
13
+ ## Introduction
6
14
 
7
- Install @carto/ps-utils like dependence:
15
+ This package includes utility functions for JavaScript and TypeScript.
8
16
 
9
- ```bash
10
- npm install --save @carto/ps-utils
11
- ```
17
+ The following helpers are available:
12
18
 
13
- ## Usage
14
-
15
- The see what helpers are available, the functions and examples, see [docs](https://github.com/CartoDB/carto-ps-lib/blob/main/docs/modules/carto_ps_utils.md) section.
19
+ _To_develop_
16
20
 
17
21
  ## Contributing
18
22
 
19
- See [the contributing guide](https://github.com/CartoDB/carto-ps-lib/blob/main/CONTRIBUTING.md) for detailed instructions on how to get started with our project.
20
-
21
- If you're looking for a way to contribute, you can scan through our [existing issues](https://github.com/github/docs/issues) for something to work on. When ready, check out [Getting Started with Contributing](https://github.com/CartoDB/carto-ps-lib/blob/main/CONTRIBUTING.md) for detailed instructions.
23
+ Please read our [contributing](https://github.com/carto/carto-ps-lib/blob/main/CONTRIBUTING.md)
24
+ guide before creating a pull request.
package/dist/index.js CHANGED
@@ -1,5 +1,11 @@
1
- import { geomReduce as b } from "@turf/meta";
2
- function A(t, n = 1) {
1
+ async function l(t) {
2
+ try {
3
+ await navigator.clipboard.writeText(t);
4
+ } catch (n) {
5
+ throw new Error(n);
6
+ }
7
+ }
8
+ function p(t, n = 1) {
3
9
  if (!t) {
4
10
  console.warn(`hexToRgba: ${t} invalid hexadecimal format`);
5
11
  return;
@@ -8,117 +14,42 @@ function A(t, n = 1) {
8
14
  console.warn(`hexToRgba: ${n} invalid alpha format`);
9
15
  return;
10
16
  }
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)) {
17
+ if (t != null && 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)) {
12
18
  console.warn(`hexToRgba: ${t} invalid hexadecimal format`);
13
19
  return;
14
20
  }
15
- const e = t.length;
16
- e < 6 && (t = t.slice(0, 6 - e).repeat(6 / e));
17
- const o = parseInt(
21
+ const r = t.length;
22
+ r < 6 && (t = t.slice(0, 6 - r).repeat(6 / r));
23
+ const e = parseInt(
18
24
  t.length === 3 ? t.slice(0, 1).repeat(2) : t.slice(0, 2),
19
25
  16
20
- ), r = parseInt(
26
+ ), o = parseInt(
21
27
  t.length === 3 ? t.slice(1, 2).repeat(2) : t.slice(2, 4),
22
28
  16
23
29
  ), i = parseInt(
24
30
  t.length === 3 ? t.slice(2, 3).repeat(2) : t.slice(4, 6),
25
31
  16
26
32
  );
27
- return [o, r, i, n * 255];
33
+ return [e, o, i, n * 255];
28
34
  }
29
- function E(t, { withPrefix: n = !0 } = {}) {
30
- if (!t || !t.length) {
31
- console.warn("rgbaDeckGLToHex: invalid array or empty values");
35
+ function y(t, { withPrefix: n = !0 } = {}) {
36
+ if (!(t != null && t.length)) {
37
+ console.warn("rgbaToHex: invalid array or empty values");
32
38
  return;
33
39
  }
34
- if (t.some((r) => r < 0 || r > 255)) {
35
- console.warn(
36
- `rgbaDeckGLToHex: [${t.toString()}] invalid array value format`
37
- );
40
+ if (t.some((o) => o < 0 || o > 255)) {
41
+ console.warn(`rgbaToHex: [${t.toString()}] invalid array value format`);
38
42
  return;
39
43
  }
40
- const o = t.map((r) => r.toString(16).padStart(2, "0")).join("");
41
- return `${n ? "#" : ""}${o}`;
44
+ const e = t.map((o) => o.toString(16).padStart(2, "0")).join("");
45
+ return `${n ? "#" : ""}${e}`;
42
46
  }
43
- function C(t, n) {
44
- return (...r) => {
45
- clearTimeout(0), setTimeout(() => t(...r), n);
47
+ function T(t, n) {
48
+ return (...o) => {
49
+ clearTimeout(0), setTimeout(() => t(...o), n);
46
50
  };
47
51
  }
48
- const g = 63710088e-1;
49
- function I(t) {
50
- return b(
51
- t,
52
- function(n, e) {
53
- return n + R(e);
54
- },
55
- 0
56
- );
57
- }
58
- function R(t) {
59
- let n = 0, e;
60
- switch (t.type) {
61
- case "Polygon":
62
- return p(t.coordinates);
63
- case "MultiPolygon":
64
- for (e = 0; e < t.coordinates.length; e++)
65
- n += p(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 p(t) {
76
- let n = 0;
77
- if (t && t.length > 0) {
78
- n += Math.abs(m(t[0]));
79
- for (let e = 1; e < t.length; e++)
80
- n -= Math.abs(m(t[e]));
81
- }
82
- return n;
83
- }
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
- }
92
- return u;
93
- }
94
- function l(t) {
95
- return t * Math.PI / 180;
96
- }
97
- function v(t) {
98
- try {
99
- if (navigator.clipboard)
100
- navigator.clipboard.writeText(t);
101
- else {
102
- const n = document.createElement("input");
103
- n.innerHTML = t, T(n);
104
- }
105
- } catch (n) {
106
- throw new Error(n);
107
- }
108
- }
109
- function T(t) {
110
- const n = t.contentEditable, e = t.readOnly;
111
- try {
112
- t.contentEditable = "true", t.readOnly = !1, D(t);
113
- } finally {
114
- t.contentEditable = n, t.readOnly = e;
115
- }
116
- }
117
- function D(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 = {
52
+ const f = {
122
53
  NUMBER: {
123
54
  style: "decimal",
124
55
  maximumFractionDigits: 1,
@@ -140,60 +71,61 @@ const y = {
140
71
  day: "2-digit"
141
72
  }
142
73
  };
143
- function F(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 M(t, n, e = {}) {
150
- return d(t, n, { ...y.NUMBER, ...e });
151
- }
152
- function N(t, n, e = {}) {
153
- return d(t, n, { ...y.CURRENCY, ...e });
154
- }
155
- const w = /:+[a-z]+/gi;
156
- function S(t, n = []) {
157
- let e = t;
158
- const o = e.match(w) || [], r = Array.isArray(n);
159
- return o.forEach((i, a) => {
160
- let c;
161
- if (r)
162
- c = n[a];
74
+ function R(t, n, r) {
75
+ return Intl.DateTimeFormat(n, r).format(t);
76
+ }
77
+ function a(t, n, r) {
78
+ return Intl.NumberFormat(n, r).format(t);
79
+ }
80
+ function w(t, n, r = {}) {
81
+ return a(t, n, {
82
+ ...f.NUMBER,
83
+ ...r
84
+ });
85
+ }
86
+ function D(t, n, r = {}) {
87
+ return a(t, n, {
88
+ ...f.CURRENCY,
89
+ ...r
90
+ });
91
+ }
92
+ function u(t, { format: n = "NFD", replaceUnicode: r = "[̀-ͯ]" } = {}) {
93
+ const e = new RegExp(r, "g");
94
+ return t.normalize(n).replace(e, "");
95
+ }
96
+ function F(t, n, { matchFn: r, normalizeOptions: e } = {}) {
97
+ let o = t;
98
+ return typeof t == "string" && (o = new RegExp(u(t.toLowerCase(), e), "gi")), Array.isArray(n) ? n.filter((i) => {
99
+ const c = r ? r(i) : i;
100
+ return u(c).match(o);
101
+ }) : u(n).match(o) ? n : null;
102
+ }
103
+ const m = /:+[a-z]+/gi;
104
+ function A(t, n = []) {
105
+ let r = t;
106
+ const e = r.match(m) ?? [], o = Array.isArray(n);
107
+ return e.forEach((i, c) => {
108
+ let s;
109
+ if (o)
110
+ s = n[c];
163
111
  else {
164
- const u = i.substring(1);
165
- c = n[u];
112
+ const g = i.substring(1);
113
+ s = n[g];
166
114
  }
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 L(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;
115
+ r = r.replace(i, (s == null ? void 0 : s.toString()) ?? "");
116
+ }), r;
183
117
  }
184
118
  export {
185
- y as CONFIG,
186
- I as area,
187
- v as copy,
188
- C as debounce,
189
- N as formatCurrency,
190
- F as formatDate,
191
- M as formatNumber,
192
- A as hexToRgba,
193
- A as hexToRgbaDeckGL,
194
- L as matchText,
195
- f as normalize,
196
- S as replaceRoute,
197
- E as rgbaDeckGLToHex,
198
- E as rgbaToHex
119
+ f as DEFAULT_FORMATTERS_CONFIG,
120
+ l as copy,
121
+ T as debounce,
122
+ D as formatCurrency,
123
+ R as formatDate,
124
+ w as formatNumber,
125
+ p as hexToRgba,
126
+ F as matchText,
127
+ u as normalize,
128
+ A as replaceRoute,
129
+ y as rgbaToHex
199
130
  };
131
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sources":["../src/clipboard/copy.ts","../src/colors/hex-to-rgba/hex-to-rgba.ts","../src/colors/rgba-to-hex/rgba-to-hex.ts","../src/debounce/debounce.ts","../src/formatters/constants.ts","../src/formatters/date/format-date.ts","../src/formatters/number/format-number.ts","../src/strings/normalize/normalize.ts","../src/strings/match-text/match-text.ts","../src/strings/routes/replace-route.ts"],"sourcesContent":["/**\n * This function is a helper function to copy text to the clipboard.\n *\n * @param {string} text - The text to copy to the clipboard.\n *\n * @returns {void}\n *\n *\n * @example\n * ```ts\n * copy('Hello world!')\n * ```\n */\nexport async function copy(text: string): Promise<void> {\n try {\n await navigator.clipboard.writeText(text)\n } catch (e: unknown) {\n throw new Error(e as string) // copy failed.\n }\n}\n","/**\n * It converts a hexadecimal color to an array of numbers\n *\n * @param {string} hexadecimal - hexadecimal string, including # or not\n * @param {number} alpha - opacity of final color, value must be between 0-1\n *\n * @returns An array of numbers.\n *\n * @example\n *\n * 6 digits hexadecimal:\n * ```ts\n * hexToRgba('#d1d1d1', 1)\n * ```\n * 3 digits hexadecimal:\n * ```ts\n * hexToRgba('#d1d', 1)\n * ```\n * 2 digits hexadecimal:\n * ```ts\n * hexToRgba('#d1', 1)\n * ```\n */\nexport function hexToRgba(\n hexadecimal: string,\n alpha = 1,\n): [number, number, number, number] | undefined {\n if (!hexadecimal) {\n // eslint-disable-next-line no-console\n console.warn(`hexToRgba: ${hexadecimal} invalid hexadecimal format`)\n return\n }\n if (alpha < 0 || alpha > 1) {\n // eslint-disable-next-line no-console\n console.warn(`hexToRgba: ${alpha} invalid alpha format`)\n return\n }\n if (hexadecimal?.includes('#')) {\n hexadecimal = hexadecimal.slice(1)\n }\n if (\n !/[0-9A-Fa-f]{6}/g.test(hexadecimal) &&\n !/[0-9A-Fa-f]{3}/g.test(hexadecimal) &&\n !/[0-9A-Fa-f]{2}/g.test(hexadecimal)\n ) {\n // eslint-disable-next-line no-console\n console.warn(`hexToRgba: ${hexadecimal} invalid hexadecimal format`)\n return\n }\n\n const length = hexadecimal.length\n\n if (length < 6) {\n hexadecimal = hexadecimal.slice(0, 6 - length).repeat(6 / length)\n }\n\n const r = parseInt(\n hexadecimal.length === 3\n ? hexadecimal.slice(0, 1).repeat(2)\n : hexadecimal.slice(0, 2),\n 16,\n )\n const g = parseInt(\n hexadecimal.length === 3\n ? hexadecimal.slice(1, 2).repeat(2)\n : hexadecimal.slice(2, 4),\n 16,\n )\n const b = parseInt(\n hexadecimal.length === 3\n ? hexadecimal.slice(2, 3).repeat(2)\n : hexadecimal.slice(4, 6),\n 16,\n )\n return [r, g, b, alpha * 255]\n}\n","import type { RgbaToHexOptions } from './types'\n\n/**\n * It converts an array of RGBA values to a hexadecimal string.\n *\n * @param {number[]} rgba - rgba array, including alpha or not\n * @param {RgbaToHexOptions} options - options to parse\n *\n * @returns A string\n *\n * @example\n *\n * Without alpha value:\n * ```ts\n * rgbaDeckGLToHex([0, 0, 0]) // => '#000000'\n * ```\n *\n * With alpha value:\n * ```ts\n * rgbaDeckGLToHex([0, 0, 0, 1]) // => '#000000FF'\n * ```\n *\n * Without prefix:\n * ```ts\n * rgbaDeckGLToHex([0, 0, 0], { withPrefix: false }) // => '000000'\n * ```\n *\n */\nexport function rgbaToHex(\n rgba: number[] | undefined,\n { withPrefix = true }: RgbaToHexOptions = {},\n): string | undefined {\n if (!rgba?.length) {\n // eslint-disable-next-line no-console\n console.warn(`rgbaToHex: invalid array or empty values`)\n return\n }\n\n const hasInvalidValue = rgba.some((value) => value < 0 || value > 255)\n if (hasInvalidValue) {\n // eslint-disable-next-line no-console\n console.warn(`rgbaToHex: [${rgba.toString()}] invalid array value format`)\n return\n }\n\n const hexadecimal = rgba\n .map((value) => {\n const hex = value.toString(16)\n return hex.padStart(2, '0')\n })\n .join('')\n\n return `${withPrefix ? '#' : ''}${hexadecimal}`\n}\n","/**\n * Returns a debounced version of the provided function.\n * @param func - The function to debounce.\n * @param {number} waitFor - The number of milliseconds to wait before invoking the debounced function.\n * @returns A debounced version of the provided function.\n */\nexport function debounce<F extends (...args: unknown[]) => unknown>(\n func: F,\n waitFor: number,\n): (...args: Parameters<F>) => ReturnType<F> {\n const timeout = 0\n\n const debounced = (...args: Parameters<F>) => {\n clearTimeout(timeout)\n setTimeout(() => func(...args), waitFor)\n }\n\n return debounced as (...args: Parameters<F>) => ReturnType<F>\n}\n","export const DEFAULT_FORMATTERS_CONFIG: Record<\n string,\n Intl.NumberFormatOptions | Intl.DateTimeFormatOptions\n> = {\n NUMBER: {\n style: 'decimal',\n maximumFractionDigits: 1,\n minimumFractionDigits: 0,\n notation: 'compact',\n compactDisplay: 'short',\n },\n\n CURRENCY: {\n style: 'currency',\n currency: 'USD',\n maximumFractionDigits: 2,\n minimumFractionDigits: 2,\n notation: 'compact',\n compactDisplay: 'short',\n },\n DATE: {\n year: 'numeric',\n month: '2-digit',\n day: '2-digit',\n },\n} as const\n","/**\n * Formats a Date or number to a string based on the given options.\n * This function could be used to format a Date, in Date format or miliseconds, in specific locale and options.\n * @public\n *\n * @export\n * @param {number | Date} value\n * @param {string | string[]} locales\n * @param {Intl.DateTimeFormatOptions} [options]\n * @return {string}\n */\nexport function formatDate(\n value: number | Date,\n locales: string | string[],\n options?: Intl.DateTimeFormatOptions,\n): string {\n return Intl.DateTimeFormat(locales, options).format(value)\n}\n","import { DEFAULT_FORMATTERS_CONFIG } from '../constants'\n\n/**\n * Formats a number to a string based on the given options.\n * This function could be used to format a number as a percentage, currency or unit in specific locale.\n * @public\n *\n * @example\n *\n * Without specific locale:\n * ```ts\n * format(3001) // => '3,001'\n * ```\n *\n * With specific locale:\n * ```ts\n * format(3001, 'es-ES') // => '3001'\n * ```\n *\n * With specific style:\n * ```ts\n * format(45, 'es-ES', {\n * style: 'unit',\n * unit: 'liter',\n * unitDisplay: 'long',\n * }) // => '45 litros'\n * ```\n *\n * @export\n * @param {number} value - The number to be formatted.\n * @param {string} [locale] - The locale to be used.\n * @param {Intl.NumberFormatOptions} [options] - The options to be used.\n * @return {string}\n */\nfunction format(\n value: number,\n locale: string,\n options?: Intl.NumberFormatOptions,\n): string {\n return Intl.NumberFormat(locale, options).format(value)\n}\n\n/**\n * Formats a number to a string.\n * @public\n *\n * @example\n *\n * ```ts\n * formatNumber(3001, 'es-ES') // => '3 mil'\n * ```\n *\n * @export\n * @param {number} value - The number to be formatted.\n * @param {string} locale - The locale to be used.\n * @param {Intl.NumberFormatOptions} [options] - The options to be used.\n * @return {string}\n */\nexport function formatNumber(\n value: number,\n locale: string,\n options: Intl.NumberFormatOptions = {},\n): string {\n return format(value, locale, {\n ...DEFAULT_FORMATTERS_CONFIG.NUMBER,\n ...options,\n })\n}\n\n/**\n * Formats a number to a currency string.\n * @public\n *\n * @example\n *\n * ```ts\n * formatCurrency(3001, 'en-US') // => '$3.00K'\n * ```\n *\n * @export\n * @param {number} value - The number to be formatted.\n * @param {string} locale - The locale to be used.\n * @param {Intl.NumberFormatOptions} [options] - The options to be used.\n * @return {string}\n */\nexport function formatCurrency(\n value: number,\n locale: string,\n options: Intl.NumberFormatOptions = {},\n): string {\n return format(value, locale, {\n ...DEFAULT_FORMATTERS_CONFIG.CURRENCY,\n ...options,\n })\n}\n","import type { NormalizeOptions } from './types'\n\n/**\n * It takes a string and returns a string normalized.\n * @param {string} data - The data to be normalized.\n * @param {NormalizeOptions} options - data - The string to be normalized.\n * @returns A string\n *\n * @remarks\n * The normalization by default is NFD\n *\n * @example\n *\n * ```ts\n * normalize('foo bar')\n * ```\n *\n */\nexport function normalize(\n data: string,\n { format = 'NFD', replaceUnicode = '[\\u0300-\\u036f]' }: NormalizeOptions = {},\n): string {\n const unicode = new RegExp(replaceUnicode, 'g')\n return data.normalize(format).replace(unicode, '')\n}\n","import type { MatchTextOptions } from './types'\nimport { normalize } from '../normalize/normalize'\n\n/**\n * It takes a string, an array of strings, and an optional object of options, and returns an\n * array of strings that match the input string\n * @param {string | RegExp} text - The text to match against.\n * @param {T[] | string} data - The data to match against.\n * @param {MatchTextOptions} options - The options to use.\n *\n * @returns {T[] | string | null} - The matched data or null.\n *\n */\nexport function matchText<T>(\n value: string | RegExp,\n data: T[] | string,\n { matchFn, normalizeOptions }: MatchTextOptions<T> = {},\n): T[] | string | null {\n let regex = value\n if (typeof value === 'string') {\n regex = new RegExp(normalize(value.toLowerCase(), normalizeOptions), 'gi')\n }\n\n if (!Array.isArray(data)) {\n return normalize(data).match(regex) ? data : null\n }\n\n return data.filter((match) => {\n const newData = (matchFn ? matchFn(match) : match) as string\n return normalize(newData).match(regex)\n })\n}\n","import type { Route, Values } from './types'\n\nconst regex = /:+[a-z]+/gi\n\n/**\n * Replace route with values from array or object.\n * @param {Route} data\n * @param {Values} values\n *\n * @returns {Route}\n *\n * @example\n * ```ts\n * replaceRoute('/user/:id', { id: 1 }) // /user/1\n * replaceRoute('/user/:id/:name', [1, 'John']) // /user/1/John\n * ```\n *\n * @remarks\n * This function is used to replace the route with the values from the array or object. If the values are not found, it will replace it with `undefined`.\n *\n * ```ts\n * replaceRoute('/user/:id/:name', [1]) // /user/1/undefined\n * ```\n *\n **/\nexport function replaceRoute(data: Route, values: Values = []): Route {\n let _data = data\n const templates = _data.match(regex) ?? []\n const isArray = Array.isArray(values)\n\n templates.forEach((template, index) => {\n let value\n if (!isArray) {\n const key = template.substring(1)\n value = values[key]\n } else {\n value = values[index]\n }\n _data = _data.replace(template, value?.toString() ?? '')\n })\n\n return _data\n}\n"],"names":["copy","text","e","hexToRgba","hexadecimal","alpha","length","r","g","b","rgbaToHex","rgba","withPrefix","value","debounce","func","waitFor","args","DEFAULT_FORMATTERS_CONFIG","formatDate","locales","options","format","locale","formatNumber","formatCurrency","normalize","data","replaceUnicode","unicode","matchText","matchFn","normalizeOptions","regex","match","newData","replaceRoute","values","_data","templates","isArray","template","index","key"],"mappings":"AAaA,eAAsBA,EAAKC,GAA6B;AAClD,MAAA;AACI,UAAA,UAAU,UAAU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KAAA,gBAAAA,EAAO,eAAc,EAAE;AAAA,EAAA,CACxD,GAEMyB;AACT;"}
@@ -8,9 +8,7 @@
8
8
  *
9
9
  * @example
10
10
  * ```ts
11
- * import { copy } from '@carto/ps-utils'
12
- *
13
11
  * copy('Hello world!')
14
12
  * ```
15
13
  */
16
- export declare function copy(text: string): void;
14
+ export declare function copy(text: string): Promise<void>;
@@ -0,0 +1 @@
1
+ export {};
@@ -1,9 +1,9 @@
1
- import { RgbaDeckGLToHexOptions } from './types';
1
+ import { RgbaToHexOptions } from './types';
2
2
  /**
3
3
  * It converts an array of RGBA values to a hexadecimal string.
4
4
  *
5
5
  * @param {number[]} rgba - rgba array, including alpha or not
6
- * @param {RgbaDeckGLToHexOptions} options - options to parse
6
+ * @param {RgbaToHexOptions} options - options to parse
7
7
  *
8
8
  * @returns A string
9
9
  *
@@ -25,4 +25,4 @@ import { RgbaDeckGLToHexOptions } from './types';
25
25
  * ```
26
26
  *
27
27
  */
28
- export declare function rgbaToHex(rgba: number[], { withPrefix }?: RgbaDeckGLToHexOptions): string | undefined;
28
+ export declare function rgbaToHex(rgba: number[] | undefined, { withPrefix }?: RgbaToHexOptions): string | undefined;
@@ -1,9 +1,9 @@
1
1
  /**
2
- * `RgbaDeckGLToHexOptions` is an object with an optional property `withPrefix` of type
2
+ * `RgbaToHexOptions` is an object with an optional property `withPrefix` of type
3
3
  * `boolean`.
4
4
  * @property {boolean} withPrefix - boolean - Whether to include the '#' prefix in the hex
5
5
  * string.
6
6
  */
7
- export type RgbaDeckGLToHexOptions = {
7
+ export interface RgbaToHexOptions {
8
8
  withPrefix?: boolean;
9
- };
9
+ }
@@ -4,4 +4,4 @@
4
4
  * @param {number} waitFor - The number of milliseconds to wait before invoking the debounced function.
5
5
  * @returns A debounced version of the provided function.
6
6
  */
7
- export declare function debounce<F extends (...args: any[]) => any>(func: F, waitFor: number): (...args: Parameters<F>) => ReturnType<F>;
7
+ export declare function debounce<F extends (...args: unknown[]) => unknown>(func: F, waitFor: number): (...args: Parameters<F>) => ReturnType<F>;
@@ -0,0 +1 @@
1
+ export {};
@@ -1 +1 @@
1
- export declare const CONFIG: Record<string, Intl.NumberFormatOptions | Intl.DateTimeFormatOptions>;
1
+ export declare const DEFAULT_FORMATTERS_CONFIG: Record<string, Intl.NumberFormatOptions | Intl.DateTimeFormatOptions>;
@@ -0,0 +1 @@
1
+ export {};
@@ -1,14 +1,11 @@
1
- export * from './colors';
2
- export * from './debounce/debounce';
3
- export { area } from './features/area';
4
- export * from './features/types';
5
1
  export { copy } from './clipboard/copy';
6
- export * from './formatters/constants';
2
+ export { hexToRgba } from './colors/hex-to-rgba/hex-to-rgba';
3
+ export { rgbaToHex } from './colors/rgba-to-hex/rgba-to-hex';
4
+ export { debounce } from './debounce/debounce';
5
+ export { DEFAULT_FORMATTERS_CONFIG } from './formatters/constants';
7
6
  export { formatDate } from './formatters/date/format-date';
8
- export { formatNumber, formatCurrency } from './formatters/number/format-number';
9
- export * from './routes/replace-route';
10
- export * from './routes/types';
7
+ export { formatCurrency, formatNumber } from './formatters/number/format-number';
11
8
  export { matchText } from './strings/match-text/match-text';
12
9
  export { normalize } from './strings/normalize/normalize';
13
- export * from './strings/match-text/types';
14
- export * from './strings/normalize/types';
10
+ export type { Route, Values } from './strings/routes/types';
11
+ export { replaceRoute } from './strings/routes/replace-route';
@@ -2,11 +2,11 @@ import { MatchTextOptions } from './types';
2
2
  /**
3
3
  * It takes a string, an array of strings, and an optional object of options, and returns an
4
4
  * array of strings that match the input string
5
- * @param {string} text - The text to match against.
5
+ * @param {string | RegExp} text - The text to match against.
6
6
  * @param {T[] | string} data - The data to match against.
7
7
  * @param {MatchTextOptions} options - The options to use.
8
8
  *
9
9
  * @returns {T[] | string | null} - The matched data or null.
10
10
  *
11
11
  */
12
- export declare function matchText<T>(text: string, data: T[] | string, { matchFn, normalizeOptions }?: MatchTextOptions<T>): T[] | string | null;
12
+ export declare function matchText<T>(value: string | RegExp, data: T[] | string, { matchFn, normalizeOptions }?: MatchTextOptions<T>): T[] | string | null;
@@ -0,0 +1 @@
1
+ export {};
@@ -8,7 +8,7 @@ import { NormalizeOptions } from '../normalize/types';
8
8
  * @property {NormalizeOptions} normalizeOptions - This is an object that contains the
9
9
  * options for the normalize function.
10
10
  */
11
- export type MatchTextOptions<T> = {
11
+ export interface MatchTextOptions<T> {
12
12
  matchFn?: (data: T) => string;
13
13
  normalizeOptions?: NormalizeOptions;
14
- };
14
+ }
@@ -0,0 +1 @@
1
+ export {};
@@ -9,7 +9,7 @@
9
9
  * @property {string} replaceUnicode - The unicode character to replace the unicode
10
10
  * characters with. By default is `[\u0300-\u036f]`.
11
11
  */
12
- export type NormalizeOptions = {
12
+ export interface NormalizeOptions {
13
13
  format?: 'NFD' | 'NFKD' | 'NFC' | 'NFKC';
14
14
  replaceUnicode?: string;
15
- };
15
+ }
@@ -20,4 +20,4 @@ import { Route, Values } from './types';
20
20
  * ```
21
21
  *
22
22
  **/
23
- export declare function replaceRoute(data: Route, values?: Values): string;
23
+ export declare function replaceRoute(data: Route, values?: Values): Route;
@@ -0,0 +1 @@
1
+ export {};
package/package.json CHANGED
@@ -1,38 +1,47 @@
1
1
  {
2
2
  "name": "@carto/ps-utils",
3
- "version": "1.7.1",
4
- "description": "CARTO's Professional Service Utils library",
5
- "files": [
6
- "dist"
7
- ],
3
+ "version": "2.0.0-canary.0",
4
+ "description": "CARTO's Professional Service Helpers library",
8
5
  "type": "module",
9
- "types": "./dist/types/index.d.ts",
10
- "main": "./dist/index.cjs",
11
- "module": "./dist/index.js",
6
+ "dependencies": {},
7
+ "devDependencies": {},
8
+ "peerDependencies": {},
12
9
  "exports": {
13
10
  ".": {
14
- "types": "./dist/types/index.d.ts",
15
11
  "import": "./dist/index.js",
16
- "require": "./dist/index.cjs"
12
+ "require": "./dist/index.cjs",
13
+ "types": "./dist/types/index.d.ts"
17
14
  }
18
15
  },
19
- "scripts": {
20
- "prebuild": "npm exec rimraf dist",
21
- "build": "tsc && vite build",
22
- "lint": "eslint src --ext ts,tsx,js,jsx,json --ignore-path ../../.gitignore --fix",
23
- "format": "prettier --write . --ignore-path ../../.gitignore",
24
- "test:watch": "vitest",
25
- "test:related": "vitest --run --passWithNoTests",
26
- "test:coverage": "vitest run --coverage"
16
+ "publishConfig": {
17
+ "access": "public"
27
18
  },
28
- "dependencies": {
29
- "@turf/meta": "6.5.0"
19
+ "files": [
20
+ "dist"
21
+ ],
22
+ "keywords": [
23
+ "carto",
24
+ "ps",
25
+ "helpers"
26
+ ],
27
+ "eslintConfig": {},
28
+ "repository": {
29
+ "type": "git",
30
+ "url": "git+https://github.com/CartoDB/carto-ps-lib.git"
30
31
  },
31
- "devDependencies": {
32
- "@turf/helpers": "6.5.0",
33
- "@types/geojson": "7946.0.13"
32
+ "author": "CARTO frontend PS team <frontend-ps@carto.com>",
33
+ "license": "MIT",
34
+ "bugs": {
35
+ "url": "https://github.com/CartoDB/carto-ps-lib/issues"
34
36
  },
35
- "peerDependencies": {
36
- "@turf/meta": ">= 6.x < 7.x"
37
+ "homepage": "https://github.com/CartoDB/carto-ps-lib#readme",
38
+ "scripts": {
39
+ "dev": "vite build --watch --emptyOutDir=false",
40
+ "build": "vite build",
41
+ "lint": "eslint",
42
+ "typecheck": "tsc --noEmit",
43
+ "test": "vitest run",
44
+ "test:watch": "vitest",
45
+ "clean": "rm -rf .turbo && rm -rf node_modules && rm -rf dist"
37
46
  }
38
- }
47
+ }
package/dist/index.cjs DELETED
@@ -1 +0,0 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const T=require("@turf/meta");function d(t,e=1){if(!t){console.warn(`hexToRgba: ${t} invalid hexadecimal format`);return}if(e<0||e>1){console.warn(`hexToRgba: ${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(`hexToRgba: ${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 b(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 D(t,e){return(...r)=>{clearTimeout(0),setTimeout(()=>t(...r),e)}}const m=63710088e-1;function h(t){return T.geomReduce(t,function(e,n){return e+w(n)},0)}function w(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,c,a,s=0;const u=t.length;if(u>2){for(a=0;a<u;a++)a===u-2?(r=u-2,i=u-1,c=0):a===u-1?(r=u-1,i=0,c=1):(r=a,i=a+1,c=a+2),e=t[r],n=t[i],o=t[c],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 R(t,e,n){return Intl.NumberFormat(e,n).format(t)}function N(t,e,n={}){return R(t,e,{...g.NUMBER,...n})}function S(t,e,n={}){return R(t,e,{...g.CURRENCY,...n})}const v=/:+[a-z]+/gi;function F(t,e=[]){let n=t;const o=n.match(v)||[],r=Array.isArray(e);return o.forEach((i,c)=>{let a;if(r)a=e[c];else{const s=i.substring(1);a=e[s]}n=n.replace(i,a?.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 c=n?n(i):i;return l(c).match(r)}):l(e).match(r)?e:null}exports.CONFIG=g;exports.area=h;exports.copy=C;exports.debounce=D;exports.formatCurrency=S;exports.formatDate=I;exports.formatNumber=N;exports.hexToRgba=d;exports.hexToRgbaDeckGL=d;exports.matchText=M;exports.normalize=l;exports.replaceRoute=F;exports.rgbaDeckGLToHex=b;exports.rgbaToHex=b;
@@ -1,5 +0,0 @@
1
- export { hexToRgba } from './hex-to-rgba/hex-to-rgba';
2
- export { hexToRgba as hexToRgbaDeckGL } from './hex-to-rgba/hex-to-rgba';
3
- export { rgbaToHex } from './rgba-to-hex/rgba-to-hex';
4
- export { rgbaToHex as rgbaDeckGLToHex } from './rgba-to-hex/rgba-to-hex';
5
- export * from './rgba-to-hex/types';
@@ -1,17 +0,0 @@
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;
@@ -1,4 +0,0 @@
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>;