@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.
@@ -1,56 +1,47 @@
1
- function hexToRgbaDeckGL(hexadecimal, alpha = 1) {
2
- if (!hexadecimal) {
3
- console.warn(`hexToRgbaDeckGL: ${hexadecimal} invalid hexadecimal format`);
1
+ function f(n, r = 1) {
2
+ if (!n) {
3
+ console.warn(`hexToRgbaDeckGL: ${n} invalid hexadecimal format`);
4
4
  return;
5
5
  }
6
- if (alpha < 0 || alpha > 1) {
7
- console.warn(`hexToRgbaDeckGL: ${alpha} invalid alpha format`);
6
+ if (r < 0 || r > 1) {
7
+ console.warn(`hexToRgbaDeckGL: ${r} invalid alpha format`);
8
8
  return;
9
9
  }
10
- if (hexadecimal == null ? void 0 : hexadecimal.includes("#")) {
11
- hexadecimal = hexadecimal.slice(1);
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 length = hexadecimal.length;
18
- if (length < 6) {
19
- hexadecimal = hexadecimal.slice(0, 6 - length).repeat(6 / length);
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 rgbaDeckGLToHex(rgba, { withPrefix = true } = {}) {
27
- if (!rgba || !rgba.length) {
28
- console.warn(`rgbaDeckGLToHex: invalid array or empty values`);
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
- const hasInvalidValue = rgba.some((value) => value < 0 || value > 255);
32
- if (hasInvalidValue) {
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 hexadecimal = rgba.map((value) => {
37
- const hex = value.toString(16);
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 normalize(data, { format = "NFD", replaceUnicode = "[\u0300-\u036F]" } = {}) {
43
- const unicode = new RegExp(replaceUnicode, "g");
44
- return data.normalize(format).replace(unicode, "");
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 matchText(text, data, { matchFn, normalizeOptions } = {}) {
47
- const regex = new RegExp(normalize(text.toLowerCase(), normalizeOptions), "gi");
48
- if (!Array.isArray(data)) {
49
- return normalize(data).match(regex) ? data : null;
50
- }
51
- return data.filter((match) => {
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 { hexToRgbaDeckGL, matchText, normalize, rgbaDeckGLToHex };
42
+ export {
43
+ f as hexToRgbaDeckGL,
44
+ c as matchText,
45
+ u as normalize,
46
+ g as rgbaDeckGLToHex
47
+ };
@@ -1 +1 @@
1
- (function(t,i){typeof exports=="object"&&typeof module!="undefined"?i(exports):typeof define=="function"&&define.amd?define(["exports"],i):(t=typeof globalThis!="undefined"?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"}})});
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",
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 && mv dist/src dist/types",
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:coverage": "vitest --coverage"
24
+ "test:related": "vitest --run --passWithNoTests",
25
+ "test:coverage": "vitest run --coverage"
25
26
  },
26
27
  "dependencies": {}
27
28
  }