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 all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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