@carto/ps-utils 0.0.2-alpha.18

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/README.md ADDED
@@ -0,0 +1,11 @@
1
+ # CARTO PS Library - Utils
2
+
3
+ This repository contains the packages with utils helpers.
4
+
5
+ The see what helpers are available, the functions and examples, see [docs](https://github.com/CartoDB/carto-ps-lib/blob/main/packages/utils/docs/README.md) section.
6
+
7
+ ## Contributing
8
+
9
+ 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.
10
+
11
+ 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.
@@ -0,0 +1,26 @@
1
+ function hexToRgbaDeckGL(hexadecimal, alpha = 1) {
2
+ if (!hexadecimal) {
3
+ console.warn(`hexToRgbaDeckGL: ${hexadecimal} invalid hexadecimal format`);
4
+ return;
5
+ }
6
+ if (alpha < 0 || alpha > 1) {
7
+ console.warn(`hexToRgbaDeckGL: ${alpha} invalid alpha format`);
8
+ return;
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`);
15
+ return;
16
+ }
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];
25
+ }
26
+ export { hexToRgbaDeckGL };
@@ -0,0 +1 @@
1
+ (function(n,s){typeof exports=="object"&&typeof module!="undefined"?s(exports):typeof define=="function"&&define.amd?define(["exports"],s):(n=typeof globalThis!="undefined"?globalThis:n||self,s(n.PsUtils={}))})(this,function(n){"use strict";function s(t,o=1){if(!t){console.warn(`hexToRgbaDeckGL: ${t} invalid hexadecimal format`);return}if(o<0||o>1){console.warn(`hexToRgbaDeckGL: ${o} invalid alpha format`);return}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)){console.warn(`hexToRgbaDeckGL: ${t} invalid hexadecimal format`);return}const e=t.length;e<6&&(t=t.slice(0,6-e).repeat(6/e));const r=parseInt(t.length===3?t.slice(0,1).repeat(2):t.slice(0,2),16),f=parseInt(t.length===3?t.slice(1,2).repeat(2):t.slice(2,4),16),u=parseInt(t.length===3?t.slice(2,3).repeat(2):t.slice(4,6),16);return[r,f,u,o*255]}n.hexToRgbaDeckGL=s,Object.defineProperties(n,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}})});
@@ -0,0 +1,24 @@
1
+ /**
2
+ * Function to parse hexadecimal string to deck.gl colors format.
3
+ *
4
+ * @param {string} hexadecimal - hexadecimal string, including # or not
5
+ * @param {number} alpha - opacity of final color, value must be between 0-1
6
+ *
7
+ * @example
8
+ *
9
+ * 6 digits hexadecimal:
10
+ * ```ts
11
+ * hexToRgbaDeckGL('#d1d1d1', 1)
12
+ * ```
13
+ * 3 digits hexadecimal:
14
+ * ```ts
15
+ * hexToRgbaDeckGL('#d1d', 1)
16
+ * ```
17
+ * 2 digits hexadecimal:
18
+ * ```ts
19
+ * hexToRgbaDeckGL('#d1', 1)
20
+ * ```
21
+ *
22
+ * @alpha
23
+ */
24
+ export declare function hexToRgbaDeckGL(hexadecimal: string, alpha?: number): number[] | undefined;
@@ -0,0 +1 @@
1
+ export { hexToRgbaDeckGL } from './colors/hexToRgbaDeckGL';
package/package.json ADDED
@@ -0,0 +1,27 @@
1
+ {
2
+ "name": "@carto/ps-utils",
3
+ "version": "0.0.2-alpha.18",
4
+ "description": "CARTO's Professional Service Utils library",
5
+ "files": [
6
+ "dist"
7
+ ],
8
+ "type": "module",
9
+ "types": "./dist/types/index.d.ts",
10
+ "main": "./dist/ps-utils.umd.js",
11
+ "module": "./dist/ps-utils.es.js",
12
+ "exports": {
13
+ ".": {
14
+ "import": "./dist/ps-utils.es.js",
15
+ "require": "./dist/ps-utils.umd.js"
16
+ }
17
+ },
18
+ "scripts": {
19
+ "build": "vite build && mv dist/src dist/types",
20
+ "lint": "eslint './**/*.{ts,tsx}' --ignore-path ../../.gitignore",
21
+ "format": "prettier --write . --ignore-path ../../.gitignore",
22
+ "docs:generate": "typedoc --options ../../typedoc.json src/index.ts",
23
+ "test:watch": "vitest",
24
+ "test:coverage": "vitest --coverage"
25
+ },
26
+ "dependencies": {}
27
+ }