@sohanemon/utils 1.0.1 → 1.0.2

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
File without changes
package/dist/index.d.ts CHANGED
@@ -1,6 +1,14 @@
1
1
  import { type ClassValue } from 'clsx';
2
+ interface ColorObject {
3
+ [key: string]: string | {
4
+ DEFAULT: string;
5
+ foreground?: string;
6
+ };
7
+ }
2
8
  export declare function cn(...inputs: ClassValue[]): string;
3
9
  export declare function isNavActive(href: string, path: string): boolean;
4
10
  export declare function kebabCase(camelCase: string): string;
5
11
  export declare function cssColorVariable(colors: Record<string, string>): Record<string, string>;
6
12
  export declare function cleanSrc(src: string): string;
13
+ export declare function tailwindColorObject(input: Record<string, string>): ColorObject;
14
+ export {};
package/dist/index.js CHANGED
@@ -1,19 +1,13 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.cleanSrc = exports.cssColorVariable = exports.kebabCase = exports.isNavActive = exports.cn = void 0;
4
- const clsx_1 = require("clsx");
5
- const tailwind_merge_1 = require("tailwind-merge");
6
- function cn(...inputs) {
7
- return (0, tailwind_merge_1.twMerge)((0, clsx_1.clsx)(inputs));
8
- }
9
- exports.cn = cn;
10
- function isNavActive(href, path) {
11
- return href === '/' ? path === '/' : path === null || path === void 0 ? void 0 : path.includes(href);
12
- }
13
- exports.isNavActive = isNavActive;
1
+ import { clsx } from 'clsx';
2
+ import { twMerge } from 'tailwind-merge';
3
+ export function cn(...inputs) {
4
+ return twMerge(clsx(inputs));
5
+ }
6
+ export function isNavActive(href, path) {
7
+ return href === '/' ? path === '/' : path?.includes(href);
8
+ }
14
9
  function hexToHSLFormatted(hexColor) {
15
- var _a;
16
- const [r, g, b] = (_a = hexColor.match(/\w\w/g)) === null || _a === void 0 ? void 0 : _a.map((c) => parseInt(c, 16) / 255);
10
+ const [r, g, b] = hexColor.match(/\w\w/g)?.map((c) => parseInt(c, 16) / 255);
17
11
  const maxVal = Math.max(r, g, b), minVal = Math.min(r, g, b);
18
12
  const lightness = (maxVal + minVal) / 2;
19
13
  const delta = maxVal - minVal;
@@ -37,21 +31,44 @@ function extractHSLValues(input) {
37
31
  throw new Error(`Invalid HSL format: ${input}`);
38
32
  return `${matches[1]} ${matches[2]}% ${matches[3]}%`;
39
33
  }
40
- function kebabCase(camelCase) {
34
+ export function kebabCase(camelCase) {
41
35
  return camelCase.replace(/[A-Z]+(?![a-z])|[A-Z]/g, ($, ofs) => (ofs ? '-' : '') + $.toLowerCase());
42
36
  }
43
- exports.kebabCase = kebabCase;
44
- function cssColorVariable(colors) {
37
+ export function cssColorVariable(colors) {
45
38
  const temp = {};
46
39
  Object.keys(colors).map((key) => {
47
40
  temp[`--${kebabCase(key)}`] = extractHSLValues(colors[key]);
48
41
  });
49
42
  return temp;
50
43
  }
51
- exports.cssColorVariable = cssColorVariable;
52
- function cleanSrc(src) {
44
+ export function cleanSrc(src) {
53
45
  if (src.includes('/public/'))
54
46
  return src.replace('/public/', '/');
55
47
  return src;
56
48
  }
57
- exports.cleanSrc = cleanSrc;
49
+ export function tailwindColorObject(input) {
50
+ const transformed = {};
51
+ for (const key in input) {
52
+ if (Object.prototype.hasOwnProperty.call(input, key)) {
53
+ if (key.endsWith('Foreground')) {
54
+ const baseKey = key.replace(/Foreground$/, '');
55
+ if (!transformed[baseKey]) {
56
+ // @ts-ignore
57
+ transformed[baseKey] = {};
58
+ }
59
+ // @ts-ignore
60
+ transformed[baseKey].foreground = `hsl(var(--${key}))`;
61
+ }
62
+ else {
63
+ if (!transformed[key]) {
64
+ transformed[key] = { DEFAULT: `hsl(var(--${key}))` };
65
+ }
66
+ else {
67
+ // @ts-ignore
68
+ transformed[key].DEFAULT = `hsl(var(--${key}))`;
69
+ }
70
+ }
71
+ }
72
+ }
73
+ return transformed;
74
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sohanemon/utils",
3
- "version": "1.0.1",
3
+ "version": "1.0.2",
4
4
  "description": "",
5
5
  "source": "./src/index.ts",
6
6
  "main": "./dist/index.js",
@@ -11,8 +11,7 @@
11
11
  ],
12
12
  "scripts": {
13
13
  "build": "tsc",
14
- "build:watch": "tsc --watch",
15
- "test": "echo \"Error: no test specified\" && exit 1"
14
+ "build:watch": "tsc --watch"
16
15
  },
17
16
  "keywords": [],
18
17
  "author": "sohanemon",