simple-merge-class-names 3.0.4 → 4.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/mergeClassNames.d.ts +1 -1
- package/mergeClassNames.js +14 -4
- package/package.json +1 -1
package/mergeClassNames.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export declare const mergeClassNames: (...args: string[]) => string;
|
|
1
|
+
export declare const mergeClassNames: (...args: (string | boolean)[]) => string;
|
package/mergeClassNames.js
CHANGED
|
@@ -37,6 +37,8 @@
|
|
|
37
37
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
|
38
38
|
*/
|
|
39
39
|
|
|
40
|
+
const isValueFalse = (val) => val === false;
|
|
41
|
+
|
|
40
42
|
const isTypeString = (val) => typeof val === "string";
|
|
41
43
|
|
|
42
44
|
const isNonEmptyString = (val) => val !== "";
|
|
@@ -53,7 +55,9 @@ const partition = (array, keepPredicate) => {
|
|
|
53
55
|
export const mergeClassNames = (...args) => {
|
|
54
56
|
const space = "\x20"; // ASCII code for a single space character (" "), decimal 32
|
|
55
57
|
|
|
56
|
-
const [
|
|
58
|
+
const [_, nonFalseValues] = partition(args, isValueFalse); // ignore all false values used for conditional class inclusion
|
|
59
|
+
|
|
60
|
+
const [strings, nonStrings] = partition(nonFalseValues, isTypeString);
|
|
57
61
|
|
|
58
62
|
const trimmed = strings.map((val) => val.trim());
|
|
59
63
|
|
|
@@ -67,16 +71,22 @@ export const mergeClassNames = (...args) => {
|
|
|
67
71
|
/* Don't silently ignore invalid input, explicitly disclose them as it may indicate a bigger problem */
|
|
68
72
|
const warn = [];
|
|
69
73
|
|
|
70
|
-
/* "Expected all arguments to be
|
|
74
|
+
/* "Expected all arguments to be either ..." */
|
|
71
75
|
if (nonStrings.length > 0) {
|
|
72
76
|
const join = ", ";
|
|
73
77
|
const count = nonStrings.length;
|
|
78
|
+
const maxPrint = 10;
|
|
74
79
|
const formatGotArray = (element, index) =>
|
|
75
80
|
`(${index + 1}/${count}): (${element}) of type "${typeof element}"`;
|
|
76
|
-
const message =
|
|
81
|
+
const message = (
|
|
82
|
+
count > maxPrint ? nonStrings.slice(0, maxPrint) : nonStrings
|
|
83
|
+
)
|
|
84
|
+
.map(formatGotArray)
|
|
85
|
+
.join(join);
|
|
86
|
+
const suffix = count > maxPrint ? ", ... ]" : "]";
|
|
77
87
|
|
|
78
88
|
warn.push(
|
|
79
|
-
`Expected all arguments to be strings, but got ${count}
|
|
89
|
+
`Expected all arguments to be either strings or value "false", but got ${count} invalid values: [${message}${suffix}.`
|
|
80
90
|
);
|
|
81
91
|
}
|
|
82
92
|
|