simple-merge-class-names 3.0.0 → 3.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 +22 -8
- package/mergeClassNames.js +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -145,20 +145,34 @@ pnpm test:watch
|
|
|
145
145
|
|
|
146
146
|
const isTypeString = (val) => typeof val === "string";
|
|
147
147
|
|
|
148
|
-
const
|
|
148
|
+
const isNonEmptyString = (val) => val !== "";
|
|
149
|
+
|
|
150
|
+
const partition = (array, keepPredicate) => {
|
|
151
|
+
const keep = [];
|
|
152
|
+
const ignore = [];
|
|
153
|
+
for (const element of array) {
|
|
154
|
+
(keepPredicate(element) ? keep : ignore).push(element);
|
|
155
|
+
}
|
|
156
|
+
return [keep, ignore];
|
|
157
|
+
};
|
|
149
158
|
|
|
150
159
|
export const mergeClassNames = (...args) => {
|
|
151
|
-
const space = "\x20"; //
|
|
160
|
+
const space = "\x20"; // ASCII code for a single space character (" "), decimal 32
|
|
161
|
+
|
|
162
|
+
const [strings, nonStrings] = partition(args, isTypeString);
|
|
152
163
|
|
|
153
|
-
const
|
|
164
|
+
const trimmed = strings.map((val) => val.trim());
|
|
154
165
|
|
|
155
|
-
const
|
|
166
|
+
const [nonEmptyStrings, emptyStrings] = partition(
|
|
167
|
+
trimmed,
|
|
168
|
+
isNonEmptyString
|
|
169
|
+
);
|
|
156
170
|
|
|
157
|
-
const
|
|
171
|
+
const className = nonEmptyStrings.join(space);
|
|
158
172
|
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
173
|
+
/* Don't silently ignore invalid input, explicitly disclose them as it may indicate a bigger problem */
|
|
174
|
+
const warn = [];
|
|
175
|
+
/* ... */
|
|
162
176
|
```
|
|
163
177
|
|
|
164
178
|
## Misc.
|
package/mergeClassNames.js
CHANGED
|
@@ -64,7 +64,7 @@ export const mergeClassNames = (...args) => {
|
|
|
64
64
|
|
|
65
65
|
const className = nonEmptyStrings.join(space);
|
|
66
66
|
|
|
67
|
-
/* Don't silently ignore invalid input, explicitly disclose them as it indicate a bigger problem */
|
|
67
|
+
/* Don't silently ignore invalid input, explicitly disclose them as it may indicate a bigger problem */
|
|
68
68
|
const warn = [];
|
|
69
69
|
|
|
70
70
|
/* "Expected all arguments to be strings ..." */
|