Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Provide named export for clsx #44

Merged
merged 4 commits into from Jul 2, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion clsx.d.ts
Expand Up @@ -6,6 +6,6 @@ export interface ClassDictionary {

export interface ClassArray extends Array<ClassValue> { }

declare const clsx: (...classes: ClassValue[]) => string;
export const clsx: (...classes: ClassValue[]) => string;

export default clsx;
6 changes: 6 additions & 0 deletions readme.md
Expand Up @@ -46,6 +46,12 @@ clsx('foo', [1 && 'bar', { baz:false, bat:null }, ['hello', ['world']]], 'cya');
//=> 'foo bar hello world cya'
```

Named imports are also available to comply with ES6 module especifications:
lukeed marked this conversation as resolved.
Show resolved Hide resolved

```js
import { clsx } from 'clsx';
```


## API

Expand Down
4 changes: 3 additions & 1 deletion src/index.js
Expand Up @@ -26,7 +26,7 @@ function toVal(mix) {
return str;
}

export default function () {
export function clsx() {
var i=0, tmp, x, str='';
while (i < arguments.length) {
if (tmp = arguments[i++]) {
Expand All @@ -38,3 +38,5 @@ export default function () {
}
return str;
}

export default clsx;
4 changes: 4 additions & 0 deletions test/index.js
@@ -1,9 +1,13 @@
import test from 'tape';
import fn from '../src';
import { clsx } from '../src';

test('clsx', t => {
t.is(typeof fn, 'function', 'exports a function');
t.is(typeof fn(), 'string', '~> returns string output');
t.is(fn, clsx, "named import available");
t.is(typeof clsx, "function", "exports a named function");
t.is(typeof clsx(), "string", "~> returns string output");
t.end();
});

Expand Down