@carto/ps-utils 1.1.4 → 1.3.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 +50 -34
- package/dist/types/clipboard/copy.d.ts +16 -0
- package/dist/types/colors/hex-to-gba-deckgl/hex-to-gba-deckgl.d.ts +1 -1
- package/dist/types/colors/rgba-deck-gl-to-hex/rgba-deck-gl-to-hex.d.ts +0 -2
- package/dist/types/index.d.ts +2 -0
- package/dist/types/routes/replace-route.d.ts +23 -0
- package/dist/types/routes/types.d.ts +2 -0
- package/dist/types/strings/match-text/match-text.d.ts +0 -1
- package/dist/types/strings/normalize/normalize.d.ts +0 -1
- package/package.json +4 -6
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"});function l(t,r=1){if(!t){console.warn(`hexToRgbaDeckGL: ${t} invalid hexadecimal format`);return}if(r<0||r>1){console.warn(`hexToRgbaDeckGL: ${r} 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),e=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,e,i,r*255]}function m(t,{withPrefix:r=!0}={}){if(!t||!t.length){console.warn("rgbaDeckGLToHex: invalid array or empty values");return}if(t.some(e=>e<0||e>255)){console.warn(`rgbaDeckGLToHex: [${t.toString()}] invalid array value format`);return}const o=t.map(e=>e.toString(16).padStart(2,"0")).join("");return`${r?"#":""}${o}`}function c(t,{format:r="NFD",replaceUnicode:n="[̀-ͯ]"}={}){const o=new RegExp(n,"g");return t.normalize(r).replace(o,"")}function D(t,r,{matchFn:n,normalizeOptions:o}={}){const e=new RegExp(c(t.toLowerCase(),o),"gi");return Array.isArray(r)?r.filter(i=>{const s=n?n(i):i;return c(s).match(e)}):c(r).match(e)?r:null}function p(t,r,n){return Intl.DateTimeFormat(r,n).format(t)}const u={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 f(t,r,n){return Intl.NumberFormat(r,n).format(t)}function y(t,r,n={}){return f(t,r,{...u.NUMBER,...n})}function R(t,r,n={}){return f(t,r,{...u.CURRENCY,...n})}const T=/:+[a-z]+/gi;function b(t,r=[]){let n=t;const o=n.match(T)||[],e=Array.isArray(r);return o.forEach((i,s)=>{let a;if(e)a=r[s];else{const g=i.substring(1);a=r[g]}n=n.replace(i,a?.toString())}),n}exports.CONFIG=u;exports.formatCurrency=R;exports.formatDate=p;exports.formatNumber=y;exports.hexToRgbaDeckGL=l;exports.matchText=D;exports.normalize=c;exports.replaceRoute=b;exports.rgbaDeckGLToHex=m;
|
package/dist/index.js
CHANGED
|
@@ -1,18 +1,18 @@
|
|
|
1
|
-
function
|
|
1
|
+
function m(t, r = 1) {
|
|
2
2
|
if (!t) {
|
|
3
3
|
console.warn(`hexToRgbaDeckGL: ${t} invalid hexadecimal format`);
|
|
4
4
|
return;
|
|
5
5
|
}
|
|
6
|
-
if (
|
|
7
|
-
console.warn(`hexToRgbaDeckGL: ${
|
|
6
|
+
if (r < 0 || r > 1) {
|
|
7
|
+
console.warn(`hexToRgbaDeckGL: ${r} invalid alpha format`);
|
|
8
8
|
return;
|
|
9
9
|
}
|
|
10
10
|
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
11
|
console.warn(`hexToRgbaDeckGL: ${t} invalid hexadecimal format`);
|
|
12
12
|
return;
|
|
13
13
|
}
|
|
14
|
-
const
|
|
15
|
-
|
|
14
|
+
const n = t.length;
|
|
15
|
+
n < 6 && (t = t.slice(0, 6 - n).repeat(6 / n));
|
|
16
16
|
const e = parseInt(
|
|
17
17
|
t.length === 3 ? t.slice(0, 1).repeat(2) : t.slice(0, 2),
|
|
18
18
|
16
|
|
@@ -23,9 +23,9 @@ function f(t, n = 1) {
|
|
|
23
23
|
t.length === 3 ? t.slice(2, 3).repeat(2) : t.slice(4, 6),
|
|
24
24
|
16
|
|
25
25
|
);
|
|
26
|
-
return [e, o, i,
|
|
26
|
+
return [e, o, i, r * 255];
|
|
27
27
|
}
|
|
28
|
-
function
|
|
28
|
+
function p(t, { withPrefix: r = !0 } = {}) {
|
|
29
29
|
if (!t || !t.length) {
|
|
30
30
|
console.warn("rgbaDeckGLToHex: invalid array or empty values");
|
|
31
31
|
return;
|
|
@@ -37,26 +37,26 @@ function g(t, { withPrefix: n = !0 } = {}) {
|
|
|
37
37
|
return;
|
|
38
38
|
}
|
|
39
39
|
const e = t.map((o) => o.toString(16).padStart(2, "0")).join("");
|
|
40
|
-
return `${
|
|
40
|
+
return `${r ? "#" : ""}${e}`;
|
|
41
41
|
}
|
|
42
|
-
function
|
|
43
|
-
const e = new RegExp(
|
|
44
|
-
return t.normalize(
|
|
42
|
+
function u(t, { format: r = "NFD", replaceUnicode: n = "[̀-ͯ]" } = {}) {
|
|
43
|
+
const e = new RegExp(n, "g");
|
|
44
|
+
return t.normalize(r).replace(e, "");
|
|
45
45
|
}
|
|
46
|
-
function
|
|
46
|
+
function D(t, r, { matchFn: n, normalizeOptions: e } = {}) {
|
|
47
47
|
const o = new RegExp(
|
|
48
|
-
|
|
48
|
+
u(t.toLowerCase(), e),
|
|
49
49
|
"gi"
|
|
50
50
|
);
|
|
51
|
-
return Array.isArray(
|
|
52
|
-
const
|
|
53
|
-
return s
|
|
54
|
-
}) :
|
|
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
55
|
}
|
|
56
|
-
function
|
|
57
|
-
return Intl.DateTimeFormat(
|
|
56
|
+
function y(t, r, n) {
|
|
57
|
+
return Intl.DateTimeFormat(r, n).format(t);
|
|
58
58
|
}
|
|
59
|
-
const
|
|
59
|
+
const a = {
|
|
60
60
|
NUMBER: {
|
|
61
61
|
style: "decimal",
|
|
62
62
|
maximumFractionDigits: 1,
|
|
@@ -78,22 +78,38 @@ const c = {
|
|
|
78
78
|
day: "2-digit"
|
|
79
79
|
}
|
|
80
80
|
};
|
|
81
|
-
function
|
|
82
|
-
return Intl.NumberFormat(
|
|
81
|
+
function f(t, r, n) {
|
|
82
|
+
return Intl.NumberFormat(r, n).format(t);
|
|
83
83
|
}
|
|
84
|
-
function
|
|
85
|
-
return
|
|
84
|
+
function R(t, r, n = {}) {
|
|
85
|
+
return f(t, r, { ...a.NUMBER, ...n });
|
|
86
86
|
}
|
|
87
|
-
function
|
|
88
|
-
return
|
|
87
|
+
function F(t, r, n = {}) {
|
|
88
|
+
return f(t, r, { ...a.CURRENCY, ...n });
|
|
89
|
+
}
|
|
90
|
+
const l = /:+[a-z]+/gi;
|
|
91
|
+
function T(t, r = []) {
|
|
92
|
+
let n = t;
|
|
93
|
+
const e = n.match(l) || [], o = Array.isArray(r);
|
|
94
|
+
return e.forEach((i, s) => {
|
|
95
|
+
let c;
|
|
96
|
+
if (o)
|
|
97
|
+
c = r[s];
|
|
98
|
+
else {
|
|
99
|
+
const g = i.substring(1);
|
|
100
|
+
c = r[g];
|
|
101
|
+
}
|
|
102
|
+
n = n.replace(i, c?.toString());
|
|
103
|
+
}), n;
|
|
89
104
|
}
|
|
90
105
|
export {
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
106
|
+
a as CONFIG,
|
|
107
|
+
F as formatCurrency,
|
|
108
|
+
y as formatDate,
|
|
109
|
+
R as formatNumber,
|
|
110
|
+
m as hexToRgbaDeckGL,
|
|
111
|
+
D as matchText,
|
|
112
|
+
u as normalize,
|
|
113
|
+
T as replaceRoute,
|
|
114
|
+
p as rgbaDeckGLToHex
|
|
99
115
|
};
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* This function is a helper function to copy text to the clipboard.
|
|
3
|
+
*
|
|
4
|
+
* @param {string} text - The text to copy to the clipboard.
|
|
5
|
+
*
|
|
6
|
+
* @returns {void}
|
|
7
|
+
*
|
|
8
|
+
*
|
|
9
|
+
* @example
|
|
10
|
+
* ```ts
|
|
11
|
+
* import { copy } from '@carto/ps-utils'
|
|
12
|
+
*
|
|
13
|
+
* copy('Hello world!')
|
|
14
|
+
* ```
|
|
15
|
+
*/
|
|
16
|
+
export declare function copy(text: string): void;
|
|
@@ -24,7 +24,5 @@ import { RgbaDeckGLToHexOptions } from './types';
|
|
|
24
24
|
* rgbaDeckGLToHex([0, 0, 0], { withPrefix: false }) // => '000000'
|
|
25
25
|
* ```
|
|
26
26
|
*
|
|
27
|
-
*
|
|
28
|
-
* @alpha
|
|
29
27
|
*/
|
|
30
28
|
export declare function rgbaDeckGLToHex(rgba: number[], { withPrefix }?: RgbaDeckGLToHexOptions): string | undefined;
|
package/dist/types/index.d.ts
CHANGED
|
@@ -8,3 +8,5 @@ export * from './strings/normalize/types';
|
|
|
8
8
|
export { formatDate } from './formatters/date/format-date';
|
|
9
9
|
export { formatNumber, formatCurrency } from './formatters/number/format-number';
|
|
10
10
|
export * from './formatters/constants';
|
|
11
|
+
export * from './routes/replace-route';
|
|
12
|
+
export * from './routes/types';
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { Route, Values } from './types';
|
|
2
|
+
/**
|
|
3
|
+
* Replace route with values from array or object.
|
|
4
|
+
* @param {Route} data
|
|
5
|
+
* @param {Values} values
|
|
6
|
+
*
|
|
7
|
+
* @returns {Route}
|
|
8
|
+
*
|
|
9
|
+
* @example
|
|
10
|
+
* ```ts
|
|
11
|
+
* replaceRoute('/user/:id', { id: 1 }) // /user/1
|
|
12
|
+
* replaceRoute('/user/:id/:name', [1, 'John']) // /user/1/John
|
|
13
|
+
* ```
|
|
14
|
+
*
|
|
15
|
+
* @remarks
|
|
16
|
+
* 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`.
|
|
17
|
+
*
|
|
18
|
+
* ```ts
|
|
19
|
+
* replaceRoute('/user/:id/:name', [1]) // /user/1/undefined
|
|
20
|
+
* ```
|
|
21
|
+
*
|
|
22
|
+
**/
|
|
23
|
+
export declare function replaceRoute(data: Route, values?: Values): string;
|
|
@@ -8,6 +8,5 @@ import { MatchTextOptions } from './types';
|
|
|
8
8
|
*
|
|
9
9
|
* @returns {T[] | string | null} - The matched data or null.
|
|
10
10
|
*
|
|
11
|
-
* @alpha
|
|
12
11
|
*/
|
|
13
12
|
export declare function matchText<T>(text: string, data: T[] | string, { matchFn, normalizeOptions }?: MatchTextOptions<T>): T[] | string | null;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@carto/ps-utils",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.3.0",
|
|
4
4
|
"description": "CARTO's Professional Service Utils library",
|
|
5
5
|
"files": [
|
|
6
6
|
"dist"
|
|
@@ -11,21 +11,19 @@
|
|
|
11
11
|
"module": "./dist/index.js",
|
|
12
12
|
"exports": {
|
|
13
13
|
".": {
|
|
14
|
+
"types": "./dist/types/index.d.ts",
|
|
14
15
|
"import": "./dist/index.js",
|
|
15
16
|
"require": "./dist/index.cjs"
|
|
16
17
|
}
|
|
17
18
|
},
|
|
18
19
|
"scripts": {
|
|
19
|
-
"
|
|
20
|
+
"prebuild": "npm exec rimraf dist",
|
|
21
|
+
"build": "tsc && vite build",
|
|
20
22
|
"lint": "eslint src --ext ts,tsx,js,jsx,json --ignore-path ../../.gitignore --fix",
|
|
21
23
|
"format": "prettier --write . --ignore-path ../../.gitignore",
|
|
22
24
|
"test:watch": "vitest",
|
|
23
25
|
"test:related": "vitest --run --passWithNoTests",
|
|
24
26
|
"test:coverage": "vitest run --coverage"
|
|
25
27
|
},
|
|
26
|
-
"typedoc": {
|
|
27
|
-
"entryPoint": "./src/index.ts",
|
|
28
|
-
"readmeFile": "./README.md"
|
|
29
|
-
},
|
|
30
28
|
"dependencies": {}
|
|
31
29
|
}
|