@carto/ps-utils 0.1.0-alpha.3 → 0.1.0-alpha.6
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/ps-utils.es.js +33 -42
- package/dist/ps-utils.umd.js +1 -1
- package/package.json +4 -3
package/dist/ps-utils.es.js
CHANGED
|
@@ -1,56 +1,47 @@
|
|
|
1
|
-
function
|
|
2
|
-
if (!
|
|
3
|
-
console.warn(`hexToRgbaDeckGL: ${
|
|
1
|
+
function f(n, r = 1) {
|
|
2
|
+
if (!n) {
|
|
3
|
+
console.warn(`hexToRgbaDeckGL: ${n} 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
|
-
if (
|
|
11
|
-
|
|
12
|
-
}
|
|
13
|
-
if (!/[0-9A-Fa-f]{6}/g.test(hexadecimal) && !/[0-9A-Fa-f]{3}/g.test(hexadecimal) && !/[0-9A-Fa-f]{2}/g.test(hexadecimal)) {
|
|
14
|
-
console.warn(`hexToRgbaDeckGL: ${hexadecimal} invalid hexadecimal format`);
|
|
10
|
+
if (n != null && n.includes("#") && (n = n.slice(1)), !/[0-9A-Fa-f]{6}/g.test(n) && !/[0-9A-Fa-f]{3}/g.test(n) && !/[0-9A-Fa-f]{2}/g.test(n)) {
|
|
11
|
+
console.warn(`hexToRgbaDeckGL: ${n} invalid hexadecimal format`);
|
|
15
12
|
return;
|
|
16
13
|
}
|
|
17
|
-
const
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
const r = parseInt(hexadecimal.length === 3 ? hexadecimal.slice(0, 1).repeat(2) : hexadecimal.slice(0, 2), 16);
|
|
22
|
-
const g = parseInt(hexadecimal.length === 3 ? hexadecimal.slice(1, 2).repeat(2) : hexadecimal.slice(2, 4), 16);
|
|
23
|
-
const b = parseInt(hexadecimal.length === 3 ? hexadecimal.slice(2, 3).repeat(2) : hexadecimal.slice(4, 6), 16);
|
|
24
|
-
return [r, g, b, alpha * 255];
|
|
14
|
+
const t = n.length;
|
|
15
|
+
t < 6 && (n = n.slice(0, 6 - t).repeat(6 / t));
|
|
16
|
+
const e = parseInt(n.length === 3 ? n.slice(0, 1).repeat(2) : n.slice(0, 2), 16), o = parseInt(n.length === 3 ? n.slice(1, 2).repeat(2) : n.slice(2, 4), 16), s = parseInt(n.length === 3 ? n.slice(2, 3).repeat(2) : n.slice(4, 6), 16);
|
|
17
|
+
return [e, o, s, r * 255];
|
|
25
18
|
}
|
|
26
|
-
function
|
|
27
|
-
if (!
|
|
28
|
-
console.warn(
|
|
19
|
+
function g(n, { withPrefix: r = !0 } = {}) {
|
|
20
|
+
if (!n || !n.length) {
|
|
21
|
+
console.warn("rgbaDeckGLToHex: invalid array or empty values");
|
|
29
22
|
return;
|
|
30
23
|
}
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
console.warn(`rgbaDeckGLToHex: [${rgba.toString()}] invalid array value format`);
|
|
24
|
+
if (n.some((o) => o < 0 || o > 255)) {
|
|
25
|
+
console.warn(`rgbaDeckGLToHex: [${n.toString()}] invalid array value format`);
|
|
34
26
|
return;
|
|
35
27
|
}
|
|
36
|
-
const
|
|
37
|
-
|
|
38
|
-
return hex.padStart(2, "0");
|
|
39
|
-
}).join("");
|
|
40
|
-
return `${withPrefix ? "#" : ""}${hexadecimal}`;
|
|
28
|
+
const e = n.map((o) => o.toString(16).padStart(2, "0")).join("");
|
|
29
|
+
return `${r ? "#" : ""}${e}`;
|
|
41
30
|
}
|
|
42
|
-
function
|
|
43
|
-
const
|
|
44
|
-
return
|
|
31
|
+
function u(n, { format: r = "NFD", replaceUnicode: t = "[\u0300-\u036F]" } = {}) {
|
|
32
|
+
const e = new RegExp(t, "g");
|
|
33
|
+
return n.normalize(r).replace(e, "");
|
|
45
34
|
}
|
|
46
|
-
function
|
|
47
|
-
const
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
const newData = matchFn ? matchFn(match) : match;
|
|
53
|
-
return normalize(newData).match(regex);
|
|
54
|
-
});
|
|
35
|
+
function c(n, r, { matchFn: t, normalizeOptions: e } = {}) {
|
|
36
|
+
const o = new RegExp(u(n.toLowerCase(), e), "gi");
|
|
37
|
+
return Array.isArray(r) ? r.filter((s) => {
|
|
38
|
+
const i = t ? t(s) : s;
|
|
39
|
+
return u(i).match(o);
|
|
40
|
+
}) : u(r).match(o) ? r : null;
|
|
55
41
|
}
|
|
56
|
-
export {
|
|
42
|
+
export {
|
|
43
|
+
f as hexToRgbaDeckGL,
|
|
44
|
+
c as matchText,
|
|
45
|
+
u as normalize,
|
|
46
|
+
g as rgbaDeckGLToHex
|
|
47
|
+
};
|
package/dist/ps-utils.umd.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
(function(t,i){typeof exports=="object"&&typeof module
|
|
1
|
+
(function(t,i){typeof exports=="object"&&typeof module<"u"?i(exports):typeof define=="function"&&define.amd?define(["exports"],i):(t=typeof globalThis<"u"?globalThis:t||self,i(t.PsUtils={}))})(this,function(t){"use strict";function i(n,e=1){if(!n){console.warn(`hexToRgbaDeckGL: ${n} invalid hexadecimal format`);return}if(e<0||e>1){console.warn(`hexToRgbaDeckGL: ${e} invalid alpha format`);return}if(n!=null&&n.includes("#")&&(n=n.slice(1)),!/[0-9A-Fa-f]{6}/g.test(n)&&!/[0-9A-Fa-f]{3}/g.test(n)&&!/[0-9A-Fa-f]{2}/g.test(n)){console.warn(`hexToRgbaDeckGL: ${n} invalid hexadecimal format`);return}const r=n.length;r<6&&(n=n.slice(0,6-r).repeat(6/r));const s=parseInt(n.length===3?n.slice(0,1).repeat(2):n.slice(0,2),16),o=parseInt(n.length===3?n.slice(1,2).repeat(2):n.slice(2,4),16),u=parseInt(n.length===3?n.slice(2,3).repeat(2):n.slice(4,6),16);return[s,o,u,e*255]}function c(n,{withPrefix:e=!0}={}){if(!n||!n.length){console.warn("rgbaDeckGLToHex: invalid array or empty values");return}if(n.some(o=>o<0||o>255)){console.warn(`rgbaDeckGLToHex: [${n.toString()}] invalid array value format`);return}const s=n.map(o=>o.toString(16).padStart(2,"0")).join("");return`${e?"#":""}${s}`}function f(n,{format:e="NFD",replaceUnicode:r="[\u0300-\u036F]"}={}){const s=new RegExp(r,"g");return n.normalize(e).replace(s,"")}function g(n,e,{matchFn:r,normalizeOptions:s}={}){const o=new RegExp(f(n.toLowerCase(),s),"gi");return Array.isArray(e)?e.filter(u=>{const l=r?r(u):u;return f(l).match(o)}):f(e).match(o)?e:null}t.hexToRgbaDeckGL=i,t.matchText=g,t.normalize=f,t.rgbaDeckGLToHex=c,Object.defineProperties(t,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}})});
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@carto/ps-utils",
|
|
3
|
-
"version": "0.1.0-alpha.
|
|
3
|
+
"version": "0.1.0-alpha.6",
|
|
4
4
|
"description": "CARTO's Professional Service Utils library",
|
|
5
5
|
"files": [
|
|
6
6
|
"dist"
|
|
@@ -16,12 +16,13 @@
|
|
|
16
16
|
}
|
|
17
17
|
},
|
|
18
18
|
"scripts": {
|
|
19
|
-
"build": "vite build
|
|
19
|
+
"build": "vite build",
|
|
20
20
|
"lint": "eslint './**/*.{ts,tsx}' --ignore-path ../../.gitignore",
|
|
21
21
|
"format": "prettier --write . --ignore-path ../../.gitignore",
|
|
22
22
|
"docs:generate": "typedoc --options ../../typedoc.json src/index.ts",
|
|
23
23
|
"test:watch": "vitest",
|
|
24
|
-
"test:
|
|
24
|
+
"test:related": "vitest --run --passWithNoTests",
|
|
25
|
+
"test:coverage": "vitest run --coverage"
|
|
25
26
|
},
|
|
26
27
|
"dependencies": {}
|
|
27
28
|
}
|