Skip to content

Commit

Permalink
fix: use Array.isArray check;
Browse files Browse the repository at this point in the history
- Closes #17
  • Loading branch information
lukeed committed Feb 3, 2020
1 parent af19571 commit 0d6023a
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 5 deletions.
6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "clsx",
"version": "1.0.4",
"repository": "lukeed/clsx",
"description": "A tiny (223B) utility for constructing className strings conditionally.",
"description": "A tiny (229B) utility for constructing className strings conditionally.",
"module": "dist/clsx.m.js",
"unpkg": "dist/clsx.min.js",
"main": "dist/clsx.js",
Expand All @@ -11,7 +11,7 @@
"author": {
"name": "Luke Edwards",
"email": "luke.edwards05@gmail.com",
"url": "lukeed.com"
"url": "https://lukeed.com"
},
"engines": {
"node": ">=6"
Expand All @@ -31,7 +31,7 @@
"classnames"
],
"devDependencies": {
"bundt": "^0.1.1",
"bundt": "^0.4.0",
"tap-spec": "^5.0.0",
"tape": "^4.9.1"
}
Expand Down
10 changes: 9 additions & 1 deletion readme.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# clsx [![Build Status](https://travis-ci.org/lukeed/clsx.svg?branch=master)](https://travis-ci.org/lukeed/clsx)

> A tiny (223B) utility for constructing `className` strings conditionally.<Br>Also serves as a [faster](/bench) & smaller drop-in replacement for the `classnames` module.
> A tiny (229B) utility for constructing `className` strings conditionally.<Br>Also serves as a [faster](/bench) & smaller drop-in replacement for the `classnames` module.
This module is available in three formats:

Expand Down Expand Up @@ -68,6 +68,14 @@ clsx(true, false, '', null, undefined, 0, NaN);

For snapshots of cross-browser results, check out the [`bench`](/bench) directory~!

## Support

All versions of Node.js are supported.

All browsers that support [`Array.isArray`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/isArray#Browser_compatibility) are supported (IE9+).

>**Note:** For IE8 support and older, please install `clsx@1.0.x` and beware of [#17](https://github.com/lukeed/clsx/issues/17).

## Related

Expand Down
2 changes: 1 addition & 1 deletion src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ function toVal(mix) {
var k, y, str='';
if (mix) {
if (typeof mix === 'object') {
if (!!mix.push) {
if (Array.isArray(mix)) {
for (k=0; k < mix.length; k++) {
if (mix[k] && (y = toVal(mix[k]))) {
str && (str += ' ');
Expand Down
8 changes: 8 additions & 0 deletions test/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,14 @@ test('arrays (variadic)', t => {
t.end();
});

test('arrays (no `push` escape)', t => {
t.is(fn({ push:1 }), 'push');
t.is(fn({ pop:true }), 'pop');
t.is(fn({ push:true }), 'push');
t.is(fn('hello', { world:1, push:true }), 'hello world push');
t.end();
});

test('functions', t => {
const foo = () => {};
t.is(fn(foo, 'hello'), 'hello');
Expand Down

0 comments on commit 0d6023a

Please sign in to comment.