simple-merge-class-names 1.0.10 → 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 +17 -7
- package/mergeClassNames.js +10 -6
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -12,6 +12,7 @@ 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)
|
|
15
16
|
- [Testing](#testing)
|
|
16
17
|
- [Production Considerations](#production-considerations)
|
|
17
18
|
- [License](#license)
|
|
@@ -106,23 +107,32 @@ While similar packages exist (`clsx`) with better features and potentially impro
|
|
|
106
107
|
* mergeClassNames - A straightforward utility for merging CSS class names in React + Tailwind, and other JavaScript projects.
|
|
107
108
|
...
|
|
108
109
|
*/
|
|
109
|
-
|
|
110
|
+
|
|
111
|
+
const isTypeString = (val) => typeof val === "string";
|
|
110
112
|
|
|
111
113
|
const isNotEmptyString = (val) => val !== "";
|
|
112
114
|
|
|
113
115
|
export const mergeClassNames = (...args) => {
|
|
114
|
-
const space = " ";
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
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);
|
|
119
125
|
return className;
|
|
120
126
|
};
|
|
121
127
|
```
|
|
122
128
|
|
|
123
129
|
### Argument Handling
|
|
124
130
|
|
|
125
|
-
`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.
|
|
126
136
|
|
|
127
137
|
### Testing
|
|
128
138
|
|
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