simple-merge-class-names 1.0.9 → 2.0.0
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 +34 -7
- package/mergeClassNames.js +10 -6
- package/package.json +14 -3
package/README.md
CHANGED
|
@@ -12,6 +12,8 @@ A straightforward utility for merging CSS class names in `React + Tailwind` and
|
|
|
12
12
|
- [Where This Package Excels](#where-this-package-excels)
|
|
13
13
|
- [Source Code](#source-code)
|
|
14
14
|
- [Argument Handling](#argument-handling)
|
|
15
|
+
- [Changes From Version 1.X.X](#changes-from-version-1xx)
|
|
16
|
+
- [Testing](#testing)
|
|
15
17
|
- [Production Considerations](#production-considerations)
|
|
16
18
|
- [License](#license)
|
|
17
19
|
|
|
@@ -105,23 +107,48 @@ While similar packages exist (`clsx`) with better features and potentially impro
|
|
|
105
107
|
* mergeClassNames - A straightforward utility for merging CSS class names in React + Tailwind, and other JavaScript projects.
|
|
106
108
|
...
|
|
107
109
|
*/
|
|
108
|
-
|
|
110
|
+
|
|
111
|
+
const isTypeString = (val) => typeof val === "string";
|
|
109
112
|
|
|
110
113
|
const isNotEmptyString = (val) => val !== "";
|
|
111
114
|
|
|
112
115
|
export const mergeClassNames = (...args) => {
|
|
113
|
-
const space = " ";
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
const
|
|
116
|
+
const space = "\x20"; // " "; ASCII code for single space character;
|
|
117
|
+
|
|
118
|
+
const stringsOnly = args.filter((val) => isTypeString(val));
|
|
119
|
+
|
|
120
|
+
const trimmed = stringsOnly.map((val) => val.trim());
|
|
121
|
+
|
|
122
|
+
const nonEmpty = trimmed.filter((val) => isNotEmptyString(val));
|
|
123
|
+
|
|
124
|
+
const className = nonEmpty.join(space);
|
|
118
125
|
return className;
|
|
119
126
|
};
|
|
120
127
|
```
|
|
121
128
|
|
|
122
129
|
### Argument Handling
|
|
123
130
|
|
|
124
|
-
`mergeClassNames` accepts
|
|
131
|
+
`mergeClassNames` only accepts **_non-empty string values_**, everything else like empty strings (`""`), `null`, `undefined`, numbers, objects and arrays is _ignored_. This ensures stricter and predictable output.
|
|
132
|
+
|
|
133
|
+
#### Breaking Changes From Version 1.X.X
|
|
134
|
+
|
|
135
|
+
In pervious versions, arguments that were not strings were implicitly converted to strings by the JavaScript engine.
|
|
136
|
+
|
|
137
|
+
### Testing
|
|
138
|
+
|
|
139
|
+
This project uses `Vitest` as the test runner for fast, modern testing.
|
|
140
|
+
|
|
141
|
+
#### Run All Testing Once
|
|
142
|
+
|
|
143
|
+
```bash
|
|
144
|
+
pnpm test
|
|
145
|
+
```
|
|
146
|
+
|
|
147
|
+
#### Run Tests In Watch Mode
|
|
148
|
+
|
|
149
|
+
```bash
|
|
150
|
+
pnpm test:watch
|
|
151
|
+
```
|
|
125
152
|
|
|
126
153
|
## Production Considerations
|
|
127
154
|
|
package/mergeClassNames.js
CHANGED
|
@@ -37,15 +37,19 @@
|
|
|
37
37
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
|
38
38
|
*/
|
|
39
39
|
|
|
40
|
-
const
|
|
40
|
+
const isTypeString = (val) => typeof val === "string";
|
|
41
41
|
|
|
42
42
|
const isNotEmptyString = (val) => val !== "";
|
|
43
43
|
|
|
44
44
|
export const mergeClassNames = (...args) => {
|
|
45
|
-
const space = " ";
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
const
|
|
45
|
+
const space = "\x20"; // " "; ASCII code for single space character;
|
|
46
|
+
|
|
47
|
+
const stringsOnly = args.filter((val) => isTypeString(val));
|
|
48
|
+
|
|
49
|
+
const trimmed = stringsOnly.map((val) => val.trim());
|
|
50
|
+
|
|
51
|
+
const nonEmpty = trimmed.filter((val) => isNotEmptyString(val));
|
|
52
|
+
|
|
53
|
+
const className = nonEmpty.join(space);
|
|
50
54
|
return className;
|
|
51
55
|
};
|
package/package.json
CHANGED
|
@@ -1,11 +1,19 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "simple-merge-class-names",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "2.0.0",
|
|
4
4
|
"description": "Example usage: <div className = {mergeClassNames('flex', 'flex-col')}/>",
|
|
5
5
|
"main": "mergeClassNames.js",
|
|
6
6
|
"exports": "./mergeClassNames.js",
|
|
7
|
+
"files": [
|
|
8
|
+
"package.json",
|
|
9
|
+
"mergeClassNames.js",
|
|
10
|
+
"LICENSE.txt",
|
|
11
|
+
"README.md"
|
|
12
|
+
],
|
|
7
13
|
"scripts": {
|
|
8
|
-
"test": "
|
|
14
|
+
"test": "vitest",
|
|
15
|
+
"test:watch": "vitest --watch",
|
|
16
|
+
"test:ui": "vitest --ui"
|
|
9
17
|
},
|
|
10
18
|
"keywords": [
|
|
11
19
|
"merge",
|
|
@@ -23,5 +31,8 @@
|
|
|
23
31
|
"bugs": {
|
|
24
32
|
"url": "https://github.com/new-AF/simple-merge-class-names/issues"
|
|
25
33
|
},
|
|
26
|
-
"homepage": "https://github.com/new-AF/simple-merge-class-names"
|
|
34
|
+
"homepage": "https://github.com/new-AF/simple-merge-class-names",
|
|
35
|
+
"devDependencies": {
|
|
36
|
+
"vitest": "^3.2.3"
|
|
37
|
+
}
|
|
27
38
|
}
|