Skip to content

Commit

Permalink
feat: add named clsx export alias (#44)
Browse files Browse the repository at this point in the history
* Provide named export for clsx

* update readme

* update types

* update test file

Co-authored-by: Luke Edwards <[email protected]>
  • Loading branch information
danikaze and lukeed authored Jul 2, 2022
1 parent 74cefa6 commit 56ab81f
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 13 deletions.
11 changes: 3 additions & 8 deletions clsx.d.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,6 @@
export type ClassValue = ClassArray | ClassDictionary | string | number | null | boolean | undefined;
export type ClassDictionary = Record<string, any>;
export type ClassArray = ClassValue[];

export interface ClassDictionary {
[id: string]: any;
}

export interface ClassArray extends Array<ClassValue> { }

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

export declare function clsx(...inputs: ClassValue[]): string;
export default clsx;
2 changes: 2 additions & 0 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ $ npm install --save clsx

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

// Strings (variadic)
clsx('foo', true && 'bar', 'baz');
Expand Down
4 changes: 3 additions & 1 deletion src/index.js
Original file line number Diff line number Diff line change
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;
15 changes: 11 additions & 4 deletions test/index.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,16 @@
import test from 'tape';
import fn from '../src';
import * as mod from '../src';

test('clsx', t => {
t.is(typeof fn, 'function', 'exports a function');
t.is(typeof fn(), 'string', '~> returns string output');
const fn = mod.default;

test('exports', t => {
t.is(typeof mod.default, 'function', 'exports default function');
t.is(typeof mod.clsx, 'function', 'exports named function');
t.ok(mod.default === mod.clsx, 'exports are equal');

t.is(typeof mod.default(), 'string', '~> returns string output');
t.is(typeof mod.clsx(), 'string', '~> returns string output');

t.end();
});

Expand Down

0 comments on commit 56ab81f

Please sign in to comment.