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 CHANGED
@@ -145,20 +145,34 @@ pnpm test:watch
145
145
 
146
146
  const isTypeString = (val) => typeof val === "string";
147
147
 
148
- const isNotEmptyString = (val) => val !== "";
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"; // " "; ASCII code for single space character;
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 stringsOnly = args.filter((val) => isTypeString(val));
164
+ const trimmed = strings.map((val) => val.trim());
154
165
 
155
- const trimmed = stringsOnly.map((val) => val.trim());
166
+ const [nonEmptyStrings, emptyStrings] = partition(
167
+ trimmed,
168
+ isNonEmptyString
169
+ );
156
170
 
157
- const nonEmpty = trimmed.filter((val) => isNotEmptyString(val));
171
+ const className = nonEmptyStrings.join(space);
158
172
 
159
- const className = nonEmpty.join(space);
160
- return className;
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.
@@ -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 ..." */
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "simple-merge-class-names",
3
- "version": "3.0.0",
3
+ "version": "3.0.2",
4
4
  "description": "A straightforward utility for merging CSS class names in React + Tailwind and JavaScript projects.",
5
5
  "exports": {
6
6
  ".": {