cls-prefix
A simple JavaScript utility for conditionally joining classNames together (like 'classnames') and customize a prefix.
Why?
When some dom or component need same prefix class name, this lib suitable for this.
Install
npm:
npm install cls-prefix -S
yarn:
yarn add cls-prefix
Usage
Commonjs:
const clsPrefix = ;
ESModule:
;
With <script>
tag:
Alternatively, you can copy node_modules/cls-prefix/umd/index.js
in your project, on your page with a standalone <script>
tag and it will export a global clsPrefix
method.
Now on your project:
Basic usage:
const clsPrefixInstance = "prefix";const clsPrefixSplice = clsPrefixInstancesplice; ; // => 'prefix'; // => 'prefix-foo prefix-bar'; // => 'prefix-foo prefix-bar'; // => 'prefix-foo-bar'; // => ''; // => 'prefix-foo prefix-bar'; // => 'prefix-foo prefix-bar'; // => 'prefix-foo prefix-bar prefix-baz'
Of course, you can use no prefix:
const clsPrefixInstance = ;const clsPrefixSplice = clsPrefixInstancesplice; ; // => 'foo bar'; // => 'foo bar'