@library/color 0.0.4 → 0.0.5

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,2 +1,36 @@
1
1
 
2
- 
2
+ CLI Building entry: src/index.ts
3
+ CLI Using tsconfig: tsconfig.build.json
4
+ CLI tsup v8.4.0
5
+ CLI Using tsup config: /Users/yeonjuan/Desktop/projects/library/packages/color/tsup.config.ts
6
+ CLI Building entry: src/hexToRgb.ts, src/index.ts, src/rgbToCssString.ts, src/rgbToHex.ts, src/types.ts
7
+ CLI Using tsconfig: tsconfig.build.json
8
+ CLI tsup v8.4.0
9
+ CLI Using tsup config: /Users/yeonjuan/Desktop/projects/library/packages/color/tsup.config.ts
10
+ CLI Target: es2016
11
+ CLI Target: esnext
12
+ CLI Cleaning output folder
13
+ CJS Build start
14
+ CLI Cleaning output folder
15
+ ESM Build start
16
+ CJS dist/cjs/index.cjs 1.15 KB
17
+ CJS ⚡️ Build success in 8ms
18
+ ESM dist/esm/types.js 0 B
19
+ ESM dist/esm/chunk-EGTD3OI6.js 218.00 B
20
+ ESM dist/esm/index.js 177.00 B
21
+ ESM dist/esm/rgbToHex.js 58.00 B
22
+ ESM dist/esm/chunk-VBFFO3TQ.js 306.00 B
23
+ ESM dist/esm/hexToRgb.js 58.00 B
24
+ ESM dist/esm/rgbToCssString.js 64.00 B
25
+ ESM dist/esm/chunk-ICWEDZDJ.js 132.00 B
26
+ ESM ⚡️ Build success in 7ms
27
+ DTS Build start
28
+ DTS Build start
29
+ DTS ⚡️ Build success in 448ms
30
+ DTS dist/cjs/index.d.cts 1.37 KB
31
+ DTS ⚡️ Build success in 722ms
32
+ DTS dist/esm/index.d.ts 177.00 B
33
+ DTS dist/esm/hexToRgb.d.ts 633.00 B
34
+ DTS dist/esm/rgbToCssString.d.ts 438.00 B
35
+ DTS dist/esm/rgbToHex.d.ts 376.00 B
36
+ DTS dist/esm/types.d.ts 109.00 B
@@ -0,0 +1 @@
1
+ "use strict";var p=Object.defineProperty;var l=Object.getOwnPropertyDescriptor;var b=Object.getOwnPropertyNames;var m=Object.prototype.hasOwnProperty;var u=(r,t)=>{for(var n in t)p(r,n,{get:t[n],enumerable:!0})},$=(r,t,n,e)=>{if(t&&typeof t=="object"||typeof t=="function")for(let o of b(t))!m.call(r,o)&&o!==n&&p(r,o,{get:()=>t[o],enumerable:!(e=l(t,o))||e.enumerable});return r};var a=r=>$(p({},"__esModule",{value:!0}),r);var y={};u(y,{hexToRgb:()=>g,rgbToCssString:()=>c,rgbToHex:()=>f});module.exports=a(y);function g(r){r=r[0]==="#"?r.slice(1):r,(r.length===3||r.length===4)&&(r=r[0]+r[0]+r[1]+r[1]+r[2]+r[2]+(r[3]||"")+(r[3]||""));let t=parseInt(r.slice(0,2),16),n=parseInt(r.slice(2,4),16),e=parseInt(r.slice(4,6),16),o=+(parseInt(r.slice(6,8)||"ff",16)/255).toFixed(2);return{r:t,g:n,b:e,a:o}}var s=r=>{let t=r.toString(16);return t.length===1?`0${t}`:t};function f(r){let{r:t,g:n,b:e,a:o}=r,i=`#${s(t)}${s(n)}${s(e)}`;return typeof o=="number"&&o>=0&&o<=1&&(i+=s(parseInt((255*o).toFixed(0)))),i}function c(r){let{r:t,g:n,b:e,a:o}=r;return typeof o!="number"?`rgb(${t}, ${n}, ${e})`:`rgba(${t}, ${n}, ${e}, ${o})`}0&&(module.exports={hexToRgb,rgbToCssString,rgbToHex});
@@ -0,0 +1,47 @@
1
+ type RGBColor = {
2
+ r: number;
3
+ g: number;
4
+ b: number;
5
+ a?: number;
6
+ };
7
+
8
+ /**
9
+ * Convert a hexadecimal color code to its corresponding RGBA representation.
10
+ * @param {string} hex - The hexadecimal color code to be converted.
11
+ * @returns {RGBColor} - An object containing the RGBA values.
12
+ * @example
13
+ * ```
14
+ * import { hexToRgb } from "@library/color";
15
+ *
16
+ * hexToRgb("#f00"); // { r: 255, g: 0, b: 0, a: 1 }
17
+ * hexToRgb("#f000"); // { r: 255, g: 0, b: 0, a: 0 }
18
+ * hexToRgb("#7f11e0"); // { r: 127, g: 17, b: 224, a: 1 }
19
+ * hexToRgb("#11223344"); // { r: 17, g: 34, b: 51, a: 0.27 }
20
+ * ```
21
+ */
22
+ declare function hexToRgb(hex: string): RGBColor;
23
+
24
+ /**
25
+ * @param {RGBColor} rgb An object containing the RGBA values.
26
+ * @returns {string} The hexadecimal color code
27
+ *
28
+ * @example
29
+ * ```ts
30
+ * rgbToHex({ r: 255, g: 99, b: 71 }); // "#ff6347"
31
+ * rgbToHex({ r: 255, g: 99, b: 71, a: 0.5 }); // "#ff634780"
32
+ * ```
33
+ */
34
+ declare function rgbToHex(rgb: RGBColor): string;
35
+
36
+ /**
37
+ * Converts an RGB or RGBA color object into a CSS color string.
38
+ *
39
+ * If the alpha (`a`) value is provided, it returns a `rgba(r, g, b, a)` string.
40
+ * Otherwise, it returns a `rgb(r, g, b)` string.
41
+ *
42
+ * @param {RGBColor} rgb An object containing the RGBA values.
43
+ * @returns {string} A CSS color string.
44
+ */
45
+ declare function rgbToCssString(rgb: RGBColor): string;
46
+
47
+ export { type RGBColor, hexToRgb, rgbToCssString, rgbToHex };
@@ -0,0 +1 @@
1
+ var o=e=>{let r=e.toString(16);return r.length===1?`0${r}`:r};function s(e){let{r,g:i,b:g,a:t}=e,n=`#${o(r)}${o(i)}${o(g)}`;return typeof t=="number"&&t>=0&&t<=1&&(n+=o(parseInt((255*t).toFixed(0)))),n}export{s as a};
@@ -0,0 +1 @@
1
+ function $(e){let{r,g:o,b:t,a:n}=e;return typeof n!="number"?`rgb(${r}, ${o}, ${t})`:`rgba(${r}, ${o}, ${t}, ${n})`}export{$ as a};
@@ -0,0 +1 @@
1
+ function c(t){t=t[0]==="#"?t.slice(1):t,(t.length===3||t.length===4)&&(t=t[0]+t[0]+t[1]+t[1]+t[2]+t[2]+(t[3]||"")+(t[3]||""));let s=parseInt(t.slice(0,2),16),n=parseInt(t.slice(2,4),16),o=parseInt(t.slice(4,6),16),r=+(parseInt(t.slice(6,8)||"ff",16)/255).toFixed(2);return{r:s,g:n,b:o,a:r}}export{c as a};
@@ -1,4 +1,5 @@
1
- import type { RGBColor } from "./types";
1
+ import { RGBColor } from './types.js';
2
+
2
3
  /**
3
4
  * Convert a hexadecimal color code to its corresponding RGBA representation.
4
5
  * @param {string} hex - The hexadecimal color code to be converted.
@@ -13,5 +14,6 @@ import type { RGBColor } from "./types";
13
14
  * hexToRgb("#11223344"); // { r: 17, g: 34, b: 51, a: 0.27 }
14
15
  * ```
15
16
  */
16
- export declare function hexToRgb(hex: string): RGBColor;
17
- //# sourceMappingURL=hexToRgb.d.ts.map
17
+ declare function hexToRgb(hex: string): RGBColor;
18
+
19
+ export { hexToRgb };
@@ -0,0 +1 @@
1
+ import{a}from"./chunk-VBFFO3TQ.js";export{a as hexToRgb};
@@ -0,0 +1,4 @@
1
+ export { hexToRgb } from './hexToRgb.js';
2
+ export { rgbToHex } from './rgbToHex.js';
3
+ export { rgbToCssString } from './rgbToCssString.js';
4
+ export { RGBColor } from './types.js';
@@ -0,0 +1 @@
1
+ import{a as o}from"./chunk-VBFFO3TQ.js";import{a as e}from"./chunk-ICWEDZDJ.js";import{a as r}from"./chunk-EGTD3OI6.js";export{o as hexToRgb,e as rgbToCssString,r as rgbToHex};
@@ -1,4 +1,5 @@
1
- import type { RGBColor } from "./types";
1
+ import { RGBColor } from './types.js';
2
+
2
3
  /**
3
4
  * Converts an RGB or RGBA color object into a CSS color string.
4
5
  *
@@ -8,5 +9,6 @@ import type { RGBColor } from "./types";
8
9
  * @param {RGBColor} rgb An object containing the RGBA values.
9
10
  * @returns {string} A CSS color string.
10
11
  */
11
- export declare function rgbToCssString(rgb: RGBColor): string;
12
- //# sourceMappingURL=rgbToCssString.d.ts.map
12
+ declare function rgbToCssString(rgb: RGBColor): string;
13
+
14
+ export { rgbToCssString };
@@ -0,0 +1 @@
1
+ import{a}from"./chunk-ICWEDZDJ.js";export{a as rgbToCssString};
@@ -1,4 +1,5 @@
1
- import { RGBColor } from "./types";
1
+ import { RGBColor } from './types.js';
2
+
2
3
  /**
3
4
  * @param {RGBColor} rgb An object containing the RGBA values.
4
5
  * @returns {string} The hexadecimal color code
@@ -9,5 +10,6 @@ import { RGBColor } from "./types";
9
10
  * rgbToHex({ r: 255, g: 99, b: 71, a: 0.5 }); // "#ff634780"
10
11
  * ```
11
12
  */
12
- export declare function rgbToHex(rgb: RGBColor): string;
13
- //# sourceMappingURL=rgbToHex.d.ts.map
13
+ declare function rgbToHex(rgb: RGBColor): string;
14
+
15
+ export { rgbToHex };
@@ -0,0 +1 @@
1
+ import{a}from"./chunk-EGTD3OI6.js";export{a as rgbToHex};
@@ -1,7 +1,8 @@
1
- export type RGBColor = {
1
+ type RGBColor = {
2
2
  r: number;
3
3
  g: number;
4
4
  b: number;
5
5
  a?: number;
6
6
  };
7
- //# sourceMappingURL=types.d.ts.map
7
+
8
+ export type { RGBColor };
File without changes
package/package.json CHANGED
@@ -1,16 +1,29 @@
1
1
  {
2
2
  "name": "@library/color",
3
- "version": "0.0.4",
4
- "main": "./dist/index.js",
5
- "exports": "./dist/index.js",
6
- "types": "./dist/index.d.ts",
3
+ "version": "0.0.5",
4
+ "type": "module",
5
+ "main": "./dist/cjs/index.cjs",
6
+ "types": "./dist/cjs/index.d.cts",
7
+ "module": "./dist/esm/index.js",
8
+ "exports": {
9
+ ".": {
10
+ "import": {
11
+ "types": "./dist/esm/index.d.ts",
12
+ "default": "./dist/esm/index.js"
13
+ },
14
+ "require": {
15
+ "types": "./dist/cjs/index.d.cts",
16
+ "default": "./dist/cjs/index.cjs"
17
+ }
18
+ }
19
+ },
7
20
  "license": "MIT",
8
21
  "scripts": {
9
- "build": "rimraf dist && tsc -p tsconfig.build.json ",
22
+ "build": "rimraf dist && tsup --tsconfig tsconfig.build.json",
10
23
  "test": "jest --verbose"
11
24
  },
12
25
  "publishConfig": {
13
26
  "access": "public"
14
27
  },
15
- "gitHead": "95b2a37ecb3e4b963a573a66961aa08e35722232"
28
+ "gitHead": "68a92ce2c568feae3840a87b08cde2a637a01fe5"
16
29
  }
@@ -1,4 +1,4 @@
1
- import type { RGBColor } from "../dist";
1
+ import type { RGBColor } from "./types";
2
2
  import { rgbToHex } from "./rgbToHex";
3
3
 
4
4
  describe("rgbToHex", () => {
package/tsup.config.ts ADDED
@@ -0,0 +1,26 @@
1
+ import { defineConfig } from "tsup";
2
+
3
+ const common = {
4
+ dts: true,
5
+ clean: true,
6
+ sourcemap: false,
7
+ skipNodeModulesBundle: true,
8
+ minify: true,
9
+ } as const;
10
+
11
+ export default defineConfig([
12
+ {
13
+ ...common,
14
+ format: ["cjs"],
15
+ target: ["es2016"],
16
+ outDir: "dist/cjs",
17
+ entry: ["src/index.ts"],
18
+ },
19
+ {
20
+ ...common,
21
+ format: ["esm"],
22
+ target: ["esnext"],
23
+ outDir: "dist/esm",
24
+ entry: ["src/**/*.ts", "!src/**/*.spec.ts"],
25
+ },
26
+ ]);
@@ -1 +0,0 @@
1
- {"version":3,"file":"hexToRgb.d.ts","sourceRoot":"","sources":["../src/hexToRgb.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,SAAS,CAAC;AAExC;;;;;;;;;;;;;GAaG;AACH,wBAAgB,QAAQ,CAAC,GAAG,EAAE,MAAM,GAAG,QAAQ,CAuB9C"}
package/dist/hexToRgb.js DELETED
@@ -1,38 +0,0 @@
1
- /**
2
- * Convert a hexadecimal color code to its corresponding RGBA representation.
3
- * @param {string} hex - The hexadecimal color code to be converted.
4
- * @returns {RGBColor} - An object containing the RGBA values.
5
- * @example
6
- * ```
7
- * import { hexToRgb } from "@library/color";
8
- *
9
- * hexToRgb("#f00"); // { r: 255, g: 0, b: 0, a: 1 }
10
- * hexToRgb("#f000"); // { r: 255, g: 0, b: 0, a: 0 }
11
- * hexToRgb("#7f11e0"); // { r: 127, g: 17, b: 224, a: 1 }
12
- * hexToRgb("#11223344"); // { r: 17, g: 34, b: 51, a: 0.27 }
13
- * ```
14
- */
15
- export function hexToRgb(hex) {
16
- hex = hex[0] === "#" ? hex.slice(1) : hex;
17
- if (hex.length === 3 || hex.length === 4) {
18
- hex =
19
- hex[0] +
20
- hex[0] +
21
- hex[1] +
22
- hex[1] +
23
- hex[2] +
24
- hex[2] +
25
- (hex[3] || "") +
26
- (hex[3] || "");
27
- }
28
- const r = parseInt(hex.slice(0, 2), 16);
29
- const g = parseInt(hex.slice(2, 4), 16);
30
- const b = parseInt(hex.slice(4, 6), 16);
31
- const a = +(parseInt(hex.slice(6, 8) || "ff", 16) / 255).toFixed(2);
32
- return {
33
- r,
34
- g,
35
- b,
36
- a,
37
- };
38
- }
package/dist/index.d.ts DELETED
@@ -1,5 +0,0 @@
1
- export { hexToRgb } from "./hexToRgb.js";
2
- export { rgbToHex } from "./rgbToHex.js";
3
- export { rgbToCssString } from "./rgbToCssString.js";
4
- export type * from "./types";
5
- //# sourceMappingURL=index.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAC;AACzC,OAAO,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAC;AACzC,OAAO,EAAE,cAAc,EAAE,MAAM,qBAAqB,CAAC;AACrD,mBAAmB,SAAS,CAAC"}
package/dist/index.js DELETED
@@ -1,3 +0,0 @@
1
- export { hexToRgb } from "./hexToRgb.js";
2
- export { rgbToHex } from "./rgbToHex.js";
3
- export { rgbToCssString } from "./rgbToCssString.js";
@@ -1 +0,0 @@
1
- {"version":3,"file":"rgbToCssString.d.ts","sourceRoot":"","sources":["../src/rgbToCssString.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,SAAS,CAAC;AAExC;;;;;;;;GAQG;AACH,wBAAgB,cAAc,CAAC,GAAG,EAAE,QAAQ,GAAG,MAAM,CAMpD"}
@@ -1,16 +0,0 @@
1
- /**
2
- * Converts an RGB or RGBA color object into a CSS color string.
3
- *
4
- * If the alpha (`a`) value is provided, it returns a `rgba(r, g, b, a)` string.
5
- * Otherwise, it returns a `rgb(r, g, b)` string.
6
- *
7
- * @param {RGBColor} rgb An object containing the RGBA values.
8
- * @returns {string} A CSS color string.
9
- */
10
- export function rgbToCssString(rgb) {
11
- const { r, g, b, a } = rgb;
12
- if (typeof a !== "number") {
13
- return `rgb(${r}, ${g}, ${b})`;
14
- }
15
- return `rgba(${r}, ${g}, ${b}, ${a})`;
16
- }
@@ -1 +0,0 @@
1
- {"version":3,"file":"rgbToHex.d.ts","sourceRoot":"","sources":["../src/rgbToHex.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,SAAS,CAAC;AAOnC;;;;;;;;;GASG;AACH,wBAAgB,QAAQ,CAAC,GAAG,EAAE,QAAQ,GAAG,MAAM,CAO9C"}
package/dist/rgbToHex.js DELETED
@@ -1,22 +0,0 @@
1
- const hex = (num) => {
2
- const hex = num.toString(16);
3
- return hex.length === 1 ? `0${hex}` : hex;
4
- };
5
- /**
6
- * @param {RGBColor} rgb An object containing the RGBA values.
7
- * @returns {string} The hexadecimal color code
8
- *
9
- * @example
10
- * ```ts
11
- * rgbToHex({ r: 255, g: 99, b: 71 }); // "#ff6347"
12
- * rgbToHex({ r: 255, g: 99, b: 71, a: 0.5 }); // "#ff634780"
13
- * ```
14
- */
15
- export function rgbToHex(rgb) {
16
- const { r, g, b, a } = rgb;
17
- let ret = `#${hex(r)}${hex(g)}${hex(b)}`;
18
- if (typeof a === "number" && a >= 0 && a <= 1) {
19
- ret += hex(parseInt((255 * a).toFixed(0)));
20
- }
21
- return ret;
22
- }
@@ -1 +0,0 @@
1
- {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,QAAQ,GAAG;IACrB,CAAC,EAAE,MAAM,CAAC;IACV,CAAC,EAAE,MAAM,CAAC;IACV,CAAC,EAAE,MAAM,CAAC;IACV,CAAC,CAAC,EAAE,MAAM,CAAC;CACZ,CAAC"}
package/dist/types.js DELETED
@@ -1 +0,0 @@
1
- export {};