No puede seleccionar más de 25 temas Los temas deben comenzar con una letra o número, pueden incluir guiones ('-') y pueden tener hasta 35 caracteres de largo.

hace 3 años
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. # clsx [![Build Status](https://travis-ci.org/lukeed/clsx.svg?branch=master)](https://travis-ci.org/lukeed/clsx)
  2. > A tiny (229B) utility for constructing `className` strings conditionally.<Br>Also serves as a [faster](/bench) & smaller drop-in replacement for the `classnames` module.
  3. This module is available in three formats:
  4. * **ES Module**: `dist/clsx.m.js`
  5. * **CommonJS**: `dist/clsx.js`
  6. * **UMD**: `dist/clsx.min.js`
  7. ## Install
  8. ```
  9. $ npm install --save clsx
  10. ```
  11. ## Usage
  12. ```js
  13. import clsx from 'clsx';
  14. // Strings (variadic)
  15. clsx('foo', true && 'bar', 'baz');
  16. //=> 'foo bar baz'
  17. // Objects
  18. clsx({ foo:true, bar:false, baz:isTrue() });
  19. //=> 'foo baz'
  20. // Objects (variadic)
  21. clsx({ foo:true }, { bar:false }, null, { '--foobar':'hello' });
  22. //=> 'foo --foobar'
  23. // Arrays
  24. clsx(['foo', 0, false, 'bar']);
  25. //=> 'foo bar'
  26. // Arrays (variadic)
  27. clsx(['foo'], ['', 0, false, 'bar'], [['baz', [['hello'], 'there']]]);
  28. //=> 'foo bar baz hello there'
  29. // Kitchen sink (with nesting)
  30. clsx('foo', [1 && 'bar', { baz:false, bat:null }, ['hello', ['world']]], 'cya');
  31. //=> 'foo bar hello world cya'
  32. ```
  33. ## API
  34. ### clsx(...input)
  35. Returns: `String`
  36. #### input
  37. Type: `Mixed`
  38. The `clsx` function can take ***any*** number of arguments, each of which can be an Object, Array, Boolean, or String.
  39. > **Important:** _Any_ falsey values are discarded!<br>Standalone Boolean values are discarded as well.
  40. ```js
  41. clsx(true, false, '', null, undefined, 0, NaN);
  42. //=> ''
  43. ```
  44. ## Benchmarks
  45. For snapshots of cross-browser results, check out the [`bench`](/bench) directory~!
  46. ## Support
  47. All versions of Node.js are supported.
  48. 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+).
  49. >**Note:** For IE8 support and older, please install `clsx@1.0.x` and beware of [#17](https://github.com/lukeed/clsx/issues/17).
  50. ## Related
  51. - [obj-str](https://github.com/lukeed/obj-str) - Similar utility that is faster and smaller (96B) but only works with Objects.
  52. ## License
  53. MIT © [Luke Edwards](https://lukeed.com)