Skip to content

Commit f3fbf00

Browse files
author
root
committed
🚀 Delivered the most copied piece of code from our projects
0 parents  commit f3fbf00

File tree

12 files changed

+5733
-0
lines changed

12 files changed

+5733
-0
lines changed

.eslintrc.json

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
{
2+
"extends": ["plugin:@typescript-eslint/base"],
3+
"ignorePatterns": ["coverage/**", "dist/**", "node_modules/**", "*.json", "*.lock", "*.yaml", "*.md", "*.svg"],
4+
"rules": {
5+
"@typescript-eslint/no-unused-expressions": [
6+
"error",
7+
{
8+
"allowShortCircuit": true,
9+
"allowTaggedTemplates": true,
10+
"allowTernary": true
11+
}
12+
],
13+
"no-restricted-properties": [
14+
"error",
15+
{
16+
"message": "Please use import() instead. More info: https://facebook.github.io/create-react-app/docs/code-splitting",
17+
"object": "require",
18+
"property": "ensure"
19+
},
20+
{
21+
"message": "Please use import() instead. More info: https://facebook.github.io/create-react-app/docs/code-splitting",
22+
"object": "System",
23+
"property": "import"
24+
}
25+
]
26+
},
27+
"overrides": [
28+
{
29+
"files": ["tests/**/*.ts"],
30+
"extends": ["plugin:jest/recommended", "plugin:jest/style"]
31+
},
32+
{
33+
"files": ["scripts/**/*.?(m|c)js"],
34+
"rules": {
35+
"no-console": "off"
36+
}
37+
}
38+
]
39+
}

.gitignore

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
/.vscode/
2+
/dist/
3+
coverage
4+
node_modules/
5+
.DS_Store
6+
*.local
7+
.idea

.prettierrc.json

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
{
2+
"tabWidth": 2,
3+
"semi": true,
4+
"singleQuote": false,
5+
"printWidth": 120,
6+
"trailingComma": "all"
7+
}

LICENSE

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
CC0 1.0 Universal (CC0 1.0) Public Domain Dedication
2+
3+
The person who associated a work with this deed has dedicated the work to the public domain by waiving all of his or her rights to the work worldwide under copyright law, including all related and neighboring rights, to the extent allowed by law.
4+
5+
You can copy, modify, distribute and perform the work, even for commercial purposes, all without asking permission.
6+
7+
Copy of the legal code:
8+
https://creativecommons.org/publicdomain/zero/1.0/legalcode

README.md

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
# cn-func
2+
3+
A simple helper function to merge class names using `clsx` and `tailwind-merge`.
4+
5+
## Why This Library?
6+
7+
In many projects, developers often need to combine class names conditionally and ensure that Tailwind CSS classes are merged correctly. Instead of copying the same utility function from project to project, this library was published to provide a reusable, easy-to-install solution. It simplifies the process of merging class names, making your code cleaner and more maintainable.
8+
9+
## Installation
10+
11+
Install the package via npm:
12+
13+
```sh
14+
npm install cn-func
15+
```
16+
17+
## Usage
18+
19+
```js
20+
import { cn } from "cn-func";
21+
22+
const className = cn("text-sm", "block", condition && "rounded");
23+
24+
// Output classes:
25+
// text-sm block rounded (if condition is true)
26+
```
27+
28+
## Documentation
29+
30+
This package uses the following libraries under the hood:
31+
32+
[clsx](https://github.com/lukeed/clsx): A tiny utility for constructing className strings conditionally.
33+
[tailwind-merge](https://github.com/dcastil/tailwind-merge): A utility for merging Tailwind CSS classes in a predictable manner.
34+
35+
## License
36+
37+
This project is licensed under the MIT License - see the LICENSE file for details.

configs/jest.config.mjs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
export default {
2+
rootDir: "..",
3+
preset: "ts-jest",
4+
testMatch: ["<rootDir>/@(src|tests)/**/?(*.)test.ts"],
5+
};

configs/rollup.config.mjs

Lines changed: 107 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,107 @@
1+
// @ts-check
2+
3+
import { getBabelOutputPlugin } from "@rollup/plugin-babel";
4+
import { nodeResolve } from "@rollup/plugin-node-resolve";
5+
import typescript from "@rollup/plugin-typescript";
6+
import { defineConfig } from "rollup";
7+
import del from "rollup-plugin-delete";
8+
import { dts } from "rollup-plugin-dts";
9+
10+
import pkg from "../package.json" assert { type: "json" };
11+
12+
export default defineConfig([
13+
{
14+
input: pkg.source,
15+
output: [
16+
getOutputConfig({
17+
file: pkg.exports["."].import,
18+
format: "esm",
19+
targets: "> 0.5%, last 2 versions, Firefox ESR, not dead, maintained node versions",
20+
}),
21+
getOutputConfig({
22+
file: pkg.exports["."].require,
23+
format: "cjs",
24+
targets: "> 0.5%, last 2 versions, Firefox ESR, not dead, maintained node versions",
25+
}),
26+
],
27+
external: /node_modules/,
28+
plugins: [
29+
del({ targets: "dist/*" }),
30+
nodeResolve(),
31+
typescript({
32+
compilerOptions: {
33+
noEmitOnError: true,
34+
},
35+
}),
36+
],
37+
},
38+
{
39+
input: pkg.source,
40+
output: [
41+
getOutputConfig({
42+
file: pkg.exports["./es5"].import,
43+
format: "esm",
44+
targets: "supports es5",
45+
}),
46+
getOutputConfig({
47+
file: pkg.exports["./es5"].require,
48+
format: "cjs",
49+
targets: "supports es5",
50+
}),
51+
],
52+
external: /node_modules/,
53+
plugins: [
54+
nodeResolve(),
55+
typescript({
56+
compilerOptions: {
57+
noEmitOnError: true,
58+
declaration: false,
59+
declarationMap: false,
60+
},
61+
}),
62+
],
63+
},
64+
{
65+
input: "dist/types/index.d.ts",
66+
output: {
67+
file: pkg.exports["."].types,
68+
format: "esm",
69+
},
70+
plugins: [
71+
dts(),
72+
del({
73+
targets: "dist/types",
74+
hook: "buildEnd",
75+
runOnce: true,
76+
}),
77+
],
78+
},
79+
]);
80+
81+
function getOutputConfig({ file, format, targets }) {
82+
/** @type {import('rollup').OutputOptions} */
83+
const config = {
84+
file,
85+
format,
86+
sourcemap: true,
87+
freeze: false,
88+
generatedCode: "es2015",
89+
plugins: [
90+
getBabelOutputPlugin({
91+
presets: [
92+
[
93+
"@babel/preset-env",
94+
{
95+
loose: true,
96+
bugfixes: true,
97+
modules: false,
98+
targets,
99+
},
100+
],
101+
],
102+
}),
103+
],
104+
};
105+
106+
return config;
107+
}

package.json

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
{
2+
"name": "cn-func",
3+
"version": "1.0.0",
4+
"description": "A simple helper function to merge class names using clsx and tailwind-merge.",
5+
"scripts": {
6+
"build": "rollup --config configs/rollup.config.mjs",
7+
"test": "jest test --config configs/jest.config.mjs --coverage",
8+
"lint": "eslint '**'",
9+
"prepublishOnly": "npm run build"
10+
},
11+
"repository": {
12+
"type": "git",
13+
"url": "https://github.com/ccxdev/cn-func.git"
14+
},
15+
"exports": {
16+
".": {
17+
"types": "./dist/types.d.ts",
18+
"require": "./dist/bundle-cjs.js",
19+
"import": "./dist/bundle-mjs.mjs",
20+
"default": "./dist/bundle-mjs.mjs"
21+
},
22+
"./es5": {
23+
"types": "./dist/types.d.ts",
24+
"require": "./dist/es5/bundle-cjs.js",
25+
"import": "./dist/es5/bundle-mjs.mjs",
26+
"default": "./dist/es5/bundle-mjs.mjs"
27+
}
28+
},
29+
"keywords": [
30+
"tailwindcss",
31+
"tailwind",
32+
"css",
33+
"classes",
34+
"className",
35+
"classList",
36+
"merge",
37+
"cn",
38+
"classnames",
39+
"cn-function"
40+
],
41+
"main": "./dist/index.js",
42+
"types": "./dist/index.d.ts",
43+
"source": "src/index.ts",
44+
"author": "Mykyta Okovit",
45+
"license": "CC0-1.0",
46+
"sideEffects": false,
47+
"dependencies": {
48+
"clsx": "^2.1.1",
49+
"tailwind-merge": "^2.3.0"
50+
},
51+
"devDependencies": {
52+
"@babel/preset-env": "^7.24.6",
53+
"@rollup/plugin-babel": "^6.0.4",
54+
"@rollup/plugin-node-resolve": "^15.2.3",
55+
"@rollup/plugin-typescript": "^11.1.6",
56+
"@types/jest": "^29.5.12",
57+
"@typescript-eslint/eslint-plugin": "^7.10.0",
58+
"@typescript-eslint/parser": "^7.10.0",
59+
"eslint": "^8.57.0",
60+
"eslint-plugin-jest": "^28.5.0",
61+
"jest": "^29.7.0",
62+
"prettier": "^3.2.5",
63+
"rollup": "^4.18.0",
64+
"rollup-plugin-delete": "^2.0.0",
65+
"rollup-plugin-dts": "^6.1.1",
66+
"ts-jest": "^29.1.3",
67+
"tslib": "^2.6.2",
68+
"typescript": "^5.4.5"
69+
}
70+
}

0 commit comments

Comments
 (0)