pax_global_header00006660000000000000000000000064142611510240014506gustar00rootroot0000000000000052 comment=6da37d67472ea9eb177a4ea9a9fa2f3f4a3c445e clsx-1.2.1/000077500000000000000000000000001426115102400124605ustar00rootroot00000000000000clsx-1.2.1/.editorconfig000066400000000000000000000003231426115102400151330ustar00rootroot00000000000000# http://editorconfig.org root = true [*] indent_size = 2 indent_style = tab end_of_line = lf charset = utf-8 trim_trailing_whitespace = true insert_final_newline = true [*.{json,yml,md}] indent_style = space clsx-1.2.1/.github/000077500000000000000000000000001426115102400140205ustar00rootroot00000000000000clsx-1.2.1/.github/FUNDING.yml000066400000000000000000000000171426115102400156330ustar00rootroot00000000000000github: lukeed clsx-1.2.1/.github/workflows/000077500000000000000000000000001426115102400160555ustar00rootroot00000000000000clsx-1.2.1/.github/workflows/ci.yml000066400000000000000000000020511426115102400171710ustar00rootroot00000000000000name: CI on: [push, pull_request] jobs: test: name: Node.js v${{ matrix.nodejs }} runs-on: ubuntu-latest strategy: matrix: nodejs: [8, 10, 12, 14, 16] steps: - uses: actions/checkout@v2 - uses: actions/setup-node@v2 with: node-version: ${{ matrix.nodejs }} - name: (cache) restore uses: actions/cache@master with: path: node_modules key: ${{ runner.os }}-${{ hashFiles('**/package.json') }} - name: Install run: npm install - name: (coverage) Install if: matrix.nodejs >= 16 run: npm install -g nyc - name: Build run: npm run build - name: Test run: npm test if: matrix.nodejs < 16 - name: (coverage) Test run: nyc --include=src npm test if: matrix.nodejs >= 16 - name: (coverage) Report if: matrix.nodejs >= 16 run: | nyc report --reporter=text-lcov > coverage.lcov bash <(curl -s https://codecov.io/bash) env: CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }} clsx-1.2.1/.gitignore000066400000000000000000000000621426115102400144460ustar00rootroot00000000000000node_modules .DS_Store *-lock.* *.lock *.log dist clsx-1.2.1/bench/000077500000000000000000000000001426115102400135375ustar00rootroot00000000000000clsx-1.2.1/bench/chrome.png000077500000000000000000000157741426115102400155430ustar00rootroot00000000000000PNG  IHDR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~uOe`=@uBck{A '~8ō++ ُ1 wUѫ!o3D^ˋ=}?W\}MUF1K*T`MO,5[w# v,yŧ{."X|=9݁ e}W,๷1Xo1Xn ~&>{^0Y^ˋmj }P_^1kPF?@VB[ ) oCVVp?VpW{~go9ٯp(.~{GeI͉zzu^H|7Qrְ5CqY8_f*E xnC\/w8X%Qy(nB 3w-**@ \pCqq\j4"]9獰&aVoU/-U+ng_\Æ=3*qp?!M,3:5lz(_n~Pi乫gujXۗPܤ;q9g<6aE&0,u]ߠ{9/ÒP1Ò˰d5T̰d2,z 3,k K^C K/ÒP1Ò˰d5T̰d2,z 3,k K^C KįOЂ^cńB!B~ڭc S<1&H%F> I"Bܓ)fdf`W5E,oYónډط]7dz(V/ִ}}[woNa(2KR#XtۺxsZn'"7Z yS#=,1onI)#1^OEóTļ7'Rgó0onIg٥<,ooN;V6|]obXm~Rzx֑Xu7lA,'b#ԥ#=,nnR~N"d.f2lIENDB`clsx-1.2.1/bench/index.js000066400000000000000000000023271426115102400152100ustar00rootroot00000000000000const { Suite } = require('benchmark'); const classnames = require('classnames'); const classcat = require('classcat'); const clsx = require('../dist/clsx'); const old = require('clsx'); function bench(name, ...args) { console.log(`\n# ${name}`); new Suite() .add('classcat* ', () => classcat.apply(classcat, [args])) .add('classnames ', () => classnames.apply(classnames, args)) .add('clsx (prev) ', () => old.apply(old, args)) .add('clsx ', () => clsx.apply(clsx, args)) .on('cycle', e => console.log(' ' + e.target)) .run(); } bench( 'Strings', 'foo', '', 'bar', 'baz', 'bax', 'bux' ); bench( 'Objects', { foo:true, bar:true, bax:true, bux:false }, { baz:true, bax:false, bux:true } ); bench( 'Arrays', ['foo', 'bar'], ['baz', 'bax', 'bux'] ); bench( 'Nested Arrays', ['foo', ['bar']], ['baz', ['bax', ['bux']]] ); bench( 'Nested Arrays w/ Objects', ['foo', { bar:true, bax:true, bux:false }], ['bax', { bax:false, bux:true }] ); bench( 'Mixed', 'foo', 'bar', { bax:true, bux:false }, ['baz', { bax:false, bux:true }] ); bench( 'Mixed (Bad Data)', 'foo', 'bar', undefined, null, NaN, () => {}, { bax:true, bux:false, 123:true }, ['baz', { bax:false, bux:true, abc:null }, {}] ); clsx-1.2.1/bench/package.json000066400000000000000000000002271426115102400160260ustar00rootroot00000000000000{ "private": true, "devDependencies": { "benchmark": "^2.1.4", "classcat": "^3.2.5", "classnames": "^2.2.6", "clsx": "1.1.0" } } clsx-1.2.1/bench/readme.md000066400000000000000000000043731426115102400153250ustar00rootroot00000000000000## Benchmarks > Below you will find benchmark results for [Node.js](#Node) and [multiple browser](#Browsers) engines. ## Node These are the results while running this directory's benchmark suite in Node v10.13.0. > **Note:** The `≠` denotes that the candidate has a different API and is not compatible with `classnames` usage. ``` # Strings classcat ≠ x 8,719,816 ops/sec ±0.69% (91 runs sampled) classnames x 3,992,284 ops/sec ±1.64% (94 runs sampled) clsx x 12,784,134 ops/sec ±0.42% (97 runs sampled) # Objects classcat ≠ x 8,680,509 ops/sec ±0.36% (97 runs sampled) classnames x 3,772,978 ops/sec ±0.46% (96 runs sampled) clsx x 9,412,010 ops/sec ±0.42% (95 runs sampled) # Arrays classcat ≠ x 7,589,602 ops/sec ±0.62% (95 runs sampled) classnames x 1,665,275 ops/sec ±1.83% (93 runs sampled) clsx x 9,141,916 ops/sec ±0.42% (95 runs sampled) # Nested Arrays classcat ≠ x 6,411,409 ops/sec ±0.84% (93 runs sampled) classnames x 1,164,706 ops/sec ±1.60% (95 runs sampled) clsx x 7,165,151 ops/sec ±0.47% (91 runs sampled) # Nested Arrays w/ Objects classcat ≠ x 6,447,346 ops/sec ±0.68% (92 runs sampled) classnames x 1,597,180 ops/sec ±1.49% (93 runs sampled) clsx x 7,651,411 ops/sec ±0.56% (95 runs sampled) # Mixed classcat ≠ x 6,595,879 ops/sec ±0.42% (96 runs sampled) classnames x 2,129,199 ops/sec ±1.46% (94 runs sampled) clsx x 8,119,210 ops/sec ±0.42% (93 runs sampled) # Mixed (Bad Data) classcat ≠ x 1,771,920 ops/sec ±0.41% (96 runs sampled) classnames x 1,166,577 ops/sec ±0.84% (94 runs sampled) clsx x 2,238,939 ops/sec ±0.34% (95 runs sampled) ``` ## Browsers Results are taken from the [benchmark suite](https://github.com/JedWatson/classnames/tree/master/benchmarks) within the `classnames` repository. These were run in a clean environment and on 4GHz i7 with 32GB of RAM. As you can see, results _will_ vary from browser to browser – multiple results were included for quick viewing. ---

chrome firefox safari

clsx-1.2.1/bench/safari.png000077500000000000000000000145051426115102400155220ustar00rootroot00000000000000PNG  IHDRXs;PLTED7Buuu333}}}zzzi_dˆ֞f[ٓyJٿ厎UґϨ]RNAǦʷSGXYNlnc㍍\P鍅𭨊󽹫hy{r|`󡡡ꑉcXr񵰐xntjJ>Ъ䲲왒錄F9잗Œ\IDATx݋Q_43A_ MU/A'N!īٽM.=:e;Ao893 E/ """""""""""""""""""""""""2 ܀(^PQ j% 'WMl5iL,|wDkv)EC5DVYg9bX̗ ؾ,Q֑Rf?and# +Rdca =rˠVUO"aTkk\XXE9(,ieza'aYά5ń~7l)/ ,p0ϫ~N: ,/Y]?V#j t 2 HH?L|kHH2I| +Yb| +Yb| +Yb| +Yb| +Yb| +Yb| +Yb| +Yb| +Yb| +Yb| +Yb| +Yb| +Yb| +Yb|-fy1yKu1b +{gT䀄m@diYТ5)ji9nf:OwJ.;ν.scot#hG_rB7 Oe8T9cn Tj?R7@•Pw"Е݉0r4,nCP , O[`}PǣhMàscol&#J;;]L}U`eKr4+ݝtCE"  ap4{aT9cn V GAj-?>㰟XOSu匹0xRt*&xoPC3xbFDi ,*,,>Ρxg'iVϨbJV%O 1V?F"_OKmSZIr2#NX-ɻ` KhYU.9E`jWo]OXr݅m=։5%*OLy`EnEt-Deզ~EKzb>@ڦk- Wpij<6Xj[_ӧQDVekԣmUѺ߆?jvͰwL XݟW_'`1,^}1Ɵū/xOc Xb?W_'`1,^}1Ɵū/xOc[Kr,X0Kr.X.0e XBfz^tuSdtX*Nj9[/:K׹I^/ޠJ e{Ѣt5F {r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ߐSEVzq8?!WªVEB8y} jt-rP&bqoNɩX: Ý7!SEtnȝ}~fnŧTQ,br7_pC.>%bZ!شQ7_Llw(^GM>lQ,dbi%|Kk/XZ{&K6(^GM>lQ,dbi%|Kk/XZ{&K6 84qcӦO? Ж)u6ύ!hF)SpqEF1U3f蛍zdEFACϠQNi{"#/g(]s|[o!Rx`6:0qU,s#X!lF!E~\NHs3XSe3*Nzî)MHH<7‹͈٣Գ]ȈWԳ] kIENDB`clsx-1.2.1/bin/000077500000000000000000000000001426115102400132305ustar00rootroot00000000000000clsx-1.2.1/bin/index.js000066400000000000000000000022651426115102400147020ustar00rootroot00000000000000// @ts-check const fs = require('fs'); const zlib = require('zlib'); const { minify } = require('terser'); const pkg = require('../package.json'); if (!fs.existsSync('dist')) fs.mkdirSync('dist'); /** * @param {string} file * @param {string} source */ function write(file, source) { let isModule = !source.startsWith('!function'); let result = minify(source, { module: isModule, compress: true, }); fs.writeFileSync(file, result.code); console.log('~> "%s" (%d b)', file, zlib.gzipSync(result.code).byteLength); } let input = fs.readFileSync('src/index.js', 'utf8'); // copy for ESM write(pkg.module, input); // transform ESM -> CJS exports write(pkg.main, input.replace('export function', 'function').replace( 'export default clsx;', 'module.exports = clsx;\n' + 'module.exports.clsx = clsx;' )); // transform ESM -> UMD exports input = input.replace('export function', 'function').replace('export default clsx;', 'return clsx.clsx=clsx, clsx;'); write(pkg.unpkg, '!function(global,factory){"object"==typeof exports&&"undefined"!=typeof module?module.exports=factory():"function"==typeof define&&define.amd?define(factory):global.clsx=factory()}(this,function(){' + input + '});'); clsx-1.2.1/clsx.d.ts000066400000000000000000000004251426115102400142240ustar00rootroot00000000000000export type ClassValue = ClassArray | ClassDictionary | string | number | null | boolean | undefined; export type ClassDictionary = Record; export type ClassArray = ClassValue[]; export declare function clsx(...inputs: ClassValue[]): string; export default clsx; clsx-1.2.1/license000066400000000000000000000021201426115102400140200ustar00rootroot00000000000000MIT License Copyright (c) Luke Edwards (lukeed.com) Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. clsx-1.2.1/package.json000066400000000000000000000013361426115102400147510ustar00rootroot00000000000000{ "name": "clsx", "version": "1.2.1", "repository": "lukeed/clsx", "description": "A tiny (228B) 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": "https://lukeed.com" }, "engines": { "node": ">=6" }, "scripts": { "build": "node bin", "test": "uvu -r esm test" }, "files": [ "*.d.ts", "dist" ], "keywords": [ "classes", "classname", "classnames" ], "devDependencies": { "esm": "3.2.25", "terser": "4.8.0", "uvu": "0.5.4" } } clsx-1.2.1/readme.md000066400000000000000000000043361426115102400142450ustar00rootroot00000000000000# clsx [![CI](https://github.com/lukeed/clsx/workflows/CI/badge.svg)](https://github.com/lukeed/clsx/actions?query=workflow%3ACI) [![codecov](https://badgen.net/codecov/c/github/lukeed/clsx)](https://codecov.io/gh/lukeed/clsx) > A tiny (228B) utility for constructing `className` strings conditionally.
Also serves as a [faster](/bench) & smaller drop-in replacement for the `classnames` module. This module is available in three formats: * **ES Module**: `dist/clsx.m.js` * **CommonJS**: `dist/clsx.js` * **UMD**: `dist/clsx.min.js` ## Install ``` $ npm install --save clsx ``` ## Usage ```js import clsx from 'clsx'; // or import { clsx } from 'clsx'; // Strings (variadic) clsx('foo', true && 'bar', 'baz'); //=> 'foo bar baz' // Objects clsx({ foo:true, bar:false, baz:isTrue() }); //=> 'foo baz' // Objects (variadic) clsx({ foo:true }, { bar:false }, null, { '--foobar':'hello' }); //=> 'foo --foobar' // Arrays clsx(['foo', 0, false, 'bar']); //=> 'foo bar' // Arrays (variadic) clsx(['foo'], ['', 0, false, 'bar'], [['baz', [['hello'], 'there']]]); //=> 'foo bar baz hello there' // Kitchen sink (with nesting) clsx('foo', [1 && 'bar', { baz:false, bat:null }, ['hello', ['world']]], 'cya'); //=> 'foo bar hello world cya' ``` ## API ### clsx(...input) Returns: `String` #### input Type: `Mixed` The `clsx` function can take ***any*** number of arguments, each of which can be an Object, Array, Boolean, or String. > **Important:** _Any_ falsey values are discarded!
Standalone Boolean values are discarded as well. ```js clsx(true, false, '', null, undefined, 0, NaN); //=> '' ``` ## Benchmarks 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 - [obj-str](https://github.com/lukeed/obj-str) - A smaller (96B) and similiar utility that only works with Objects. ## License MIT © [Luke Edwards](https://lukeed.com) clsx-1.2.1/src/000077500000000000000000000000001426115102400132475ustar00rootroot00000000000000clsx-1.2.1/src/index.js000066400000000000000000000012451426115102400147160ustar00rootroot00000000000000function toVal(mix) { var k, y, str=''; if (typeof mix === 'string' || typeof mix === 'number') { str += mix; } else if (typeof mix === 'object') { if (Array.isArray(mix)) { for (k=0; k < mix.length; k++) { if (mix[k]) { if (y = toVal(mix[k])) { str && (str += ' '); str += y; } } } } else { for (k in mix) { if (mix[k]) { str && (str += ' '); str += k; } } } } return str; } export function clsx() { var i=0, tmp, x, str=''; while (i < arguments.length) { if (tmp = arguments[i++]) { if (x = toVal(tmp)) { str && (str += ' '); str += x } } } return str; } export default clsx; clsx-1.2.1/test/000077500000000000000000000000001426115102400134375ustar00rootroot00000000000000clsx-1.2.1/test/classnames.js000066400000000000000000000047001426115102400161270ustar00rootroot00000000000000/** * Ported from `classnames` for compatibility checks. */ import { test } from 'uvu'; import * as assert from 'uvu/assert'; import clsx from '../src'; test('(compat) keeps object keys with truthy values', () => { const out = clsx({ a:true, b:false, c:0, d:null, e:undefined, f:1 }); assert.is(out, 'a f'); }); test('(compat) joins arrays of class names and ignore falsy values', () => { const out = clsx('a', 0, null, undefined, true, 1, 'b'); assert.is(out, 'a 1 b'); }); test('(compat) supports heterogenous arguments', () => { assert.is(clsx({ a:true }, 'b', 0), 'a b'); }); test('(compat) should be trimmed', () => { assert.is(clsx('', 'b', {}, ''), 'b'); }); test('(compat) returns an empty string for an empty configuration', () => { assert.is(clsx({}), ''); }); test('(compat) supports an array of class names', () => { assert.is(clsx(['a', 'b']), 'a b'); }); test('(compat) joins array arguments with string arguments', () => { assert.is(clsx(['a', 'b'], 'c'), 'a b c'); assert.is(clsx('c', ['a', 'b']), 'c a b'); }); test('(compat) handles multiple array arguments', () => { assert.is(clsx(['a', 'b'], ['c', 'd']), 'a b c d'); }); test('(compat) handles arrays that include falsy and true values', () => { assert.is(clsx(['a', 0, null, undefined, false, true, 'b']), 'a b'); }); test('(compat) handles arrays that include arrays', () => { assert.is(clsx(['a', ['b', 'c']]), 'a b c'); }); test('(compat) handles arrays that include objects', () => { assert.is(clsx(['a', { b:true, c:false }]), 'a b'); }); test('(compat) handles deep array recursion', () => { assert.is(clsx(['a', ['b', ['c', { d:true }]]]), 'a b c d'); }); test('(compat) handles arrays that are empty', () => { assert.is(clsx('a', []), 'a'); }); test('(compat) handles nested arrays that have empty nested arrays', () => { assert.is(clsx('a', [[]]), 'a'); }); test('(compat) handles all types of truthy and falsy property values as expected', () => { const out = clsx({ // falsy: null: null, emptyString: '', noNumber: NaN, zero: 0, negativeZero: -0, false: false, undefined: undefined, // truthy (literally anything else): nonEmptyString: 'foobar', whitespace: ' ', function: Object.prototype.toString, emptyObject: {}, nonEmptyObject: {a: 1, b: 2}, emptyList: [], nonEmptyList: [1, 2, 3], greaterZero: 1 }); assert.is(out, 'nonEmptyString whitespace function emptyObject nonEmptyObject emptyList nonEmptyList greaterZero'); }); test.run(); clsx-1.2.1/test/index.js000066400000000000000000000046231426115102400151110ustar00rootroot00000000000000// @ts-check import { test } from 'uvu'; import * as assert from 'uvu/assert'; import * as mod from '../src'; const fn = mod.default; test('exports', () => { assert.type(mod.default, 'function', 'exports default function'); assert.type(mod.clsx, 'function', 'exports named function'); assert.is(mod.default, mod.clsx, 'exports are equal'); assert.type(mod.default(), 'string', '~> returns string output'); assert.type(mod.clsx(), 'string', '~> returns string output'); }); test('strings', () => { assert.is(fn(''), ''); assert.is(fn('foo'), 'foo'); assert.is(fn(true && 'foo'), 'foo'); assert.is(fn(false && 'foo'), ''); }); test('strings (variadic)', () => { assert.is(fn(''), ''); assert.is(fn('foo', 'bar'), 'foo bar'); assert.is(fn(true && 'foo', false && 'bar', 'baz'), 'foo baz'); assert.is(fn(false && 'foo', 'bar', 'baz', ''), 'bar baz'); }); test('objects', () => { assert.is(fn({}), ''); assert.is(fn({ foo:true }), 'foo'); assert.is(fn({ foo:true, bar:false }), 'foo'); assert.is(fn({ foo:'hiya', bar:1 }), 'foo bar'); assert.is(fn({ foo:1, bar:0, baz:1 }), 'foo baz'); assert.is(fn({ '-foo':1, '--bar':1 }), '-foo --bar'); }); test('objects (variadic)', () => { assert.is(fn({}, {}), ''); assert.is(fn({ foo:1 }, { bar:2 }), 'foo bar'); assert.is(fn({ foo:1 }, null, { baz:1, bat:0 }), 'foo baz'); assert.is(fn({ foo:1 }, {}, {}, { bar:'a' }, { baz:null, bat:Infinity }), 'foo bar bat'); }); test('arrays', () => { assert.is(fn([]), ''); assert.is(fn(['foo']), 'foo'); assert.is(fn(['foo', 'bar']), 'foo bar'); assert.is(fn(['foo', 0 && 'bar', 1 && 'baz']), 'foo baz'); }); test('arrays (nested)', () => { assert.is(fn([[[]]]), ''); assert.is(fn([[['foo']]]), 'foo'); assert.is(fn([true, [['foo']]]), 'foo');; assert.is(fn(['foo', ['bar', ['', [['baz']]]]]), 'foo bar baz'); }); test('arrays (variadic)', () => { assert.is(fn([], []), ''); assert.is(fn(['foo'], ['bar']), 'foo bar'); assert.is(fn(['foo'], null, ['baz', ''], true, '', []), 'foo baz'); }); test('arrays (no `push` escape)', () => { assert.is(fn({ push:1 }), 'push'); assert.is(fn({ pop:true }), 'pop'); assert.is(fn({ push:true }), 'push'); assert.is(fn('hello', { world:1, push:true }), 'hello world push'); }); test('functions', () => { const foo = () => {}; assert.is(fn(foo, 'hello'), 'hello'); assert.is(fn(foo, 'hello', fn), 'hello'); assert.is(fn(foo, 'hello', [[fn], 'world']), 'hello world'); }); test.run();