fix: use `Array.isArray` check;
Before adoption: this commit came in with the history the project adopted, so no landing records it.
- Closes #17
authored by Luke Edwards · committed by Luke Edwards · parent af19571 · Browse files · 4 files·+21 added−5 removed
This commit
State
Before adoption: this commit came in with the history the project adopted, so no landing records it.
Diff stats
4 files+21 added−5 removed
- tests:+8 added−0 removed
- other:+13 added−5 removed
Provenance
- Commit
0d6023a- Tree
8791a91- Author
Luke Edwards <luke.edwards05@gmail.com>- Committer
Luke Edwards <luke.edwards05@gmail.com>- Parent
af19571
4 files changed+21 added−5 removed
modified:src/index.js+1 added-1 removed
123455678928 unmodified linesfunction 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 += ' '); str += y;28 unmodified linesmodified:test/index.js+8 added
62 unmodified lines636465666768697071727374757677783 unmodified lines62 unmodified lines t.is(fn(['foo'], null, ['baz', ''], true, '', []), 'foo baz'); 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'); t.is(fn(foo, 'hello', fn), 'hello');3 unmodified linesmodified:package.json+3 added-3 removed
12345567891011121314141516171811 unmodified lines30313233343435363738{ "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", "types": "clsx.d.ts", "license": "MIT", "author": { "name": "Luke Edwards", "email": "luke.edwards05@gmail.com", "url": "lukeed.com" "url": "https://lukeed.com" }, "engines": { "node": ">=6" },11 unmodified lines "classname", "classnames" ], "devDependencies": { "bundt": "^0.1.1", "bundt": "^0.4.0", "tap-spec": "^5.0.0", "tape": "^4.9.1" }}modified:readme.md+9 added-1 removed
1 # clsx [](https://travis-ci.org/lukeed/clsx)2 3-> A tiny (223B) utility for constructing `className` strings conditionally.<Br>Also serves as a [faster](/bench) & smaller drop-in replacement for the `classnames` module.3+> A tiny (229B) utility for constructing `className` strings conditionally.<Br>Also serves as a [faster](/bench) & smaller drop-in replacement for the `classnames` module.4 5 This module is available in three formats:6 7 * **ES Module**: `dist/clsx.m.js`59 unmodified lines67 ## Benchmarks68 69 For snapshots of cross-browser results, check out the [`bench`](/bench) directory~!70 71+## Support72 73+All versions of Node.js are supported.74+75+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+).76+77+>**Note:** For IE8 support and older, please install `clsx@1.0.x` and beware of [#17](https://github.com/lukeed/clsx/issues/17).78+79+80 ## Related81 82 - [obj-str](https://github.com/lukeed/obj-str) - Similar utility that is faster and smaller (96B) but only works with Objects.83 3 unmodified lines