Skip to content

Commit 56ab81f

Browse files
danikazelukeed
andauthoredJul 2, 2022
feat: add named clsx export alias (#44)
* Provide named export for clsx * update readme * update types * update test file Co-authored-by: Luke Edwards <luke.edwards05@gmail.com>
1 parent 74cefa6 commit 56ab81f

File tree

4 files changed

+19
-13
lines changed

4 files changed

+19
-13
lines changed
 

‎clsx.d.ts

+3-8
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,6 @@
11
export type ClassValue = ClassArray | ClassDictionary | string | number | null | boolean | undefined;
2+
export type ClassDictionary = Record<string, any>;
3+
export type ClassArray = ClassValue[];
24

3-
export interface ClassDictionary {
4-
[id: string]: any;
5-
}
6-
7-
export interface ClassArray extends Array<ClassValue> { }
8-
9-
declare const clsx: (...classes: ClassValue[]) => string;
10-
5+
export declare function clsx(...inputs: ClassValue[]): string;
116
export default clsx;

‎readme.md

+2
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@ $ npm install --save clsx
2020

2121
```js
2222
import clsx from 'clsx';
23+
// or
24+
import { clsx } from 'clsx';
2325

2426
// Strings (variadic)
2527
clsx('foo', true && 'bar', 'baz');

‎src/index.js

+3-1
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ function toVal(mix) {
2626
return str;
2727
}
2828

29-
export default function () {
29+
export function clsx() {
3030
var i=0, tmp, x, str='';
3131
while (i < arguments.length) {
3232
if (tmp = arguments[i++]) {
@@ -38,3 +38,5 @@ export default function () {
3838
}
3939
return str;
4040
}
41+
42+
export default clsx;

‎test/index.js

+11-4
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,16 @@
11
import test from 'tape';
2-
import fn from '../src';
2+
import * as mod from '../src';
33

4-
test('clsx', t => {
5-
t.is(typeof fn, 'function', 'exports a function');
6-
t.is(typeof fn(), 'string', '~> returns string output');
4+
const fn = mod.default;
5+
6+
test('exports', t => {
7+
t.is(typeof mod.default, 'function', 'exports default function');
8+
t.is(typeof mod.clsx, 'function', 'exports named function');
9+
t.ok(mod.default === mod.clsx, 'exports are equal');
10+
11+
t.is(typeof mod.default(), 'string', '~> returns string output');
12+
t.is(typeof mod.clsx(), 'string', '~> returns string output');
13+
714
t.end();
815
});
916

0 commit comments

Comments
 (0)
Please sign in to comment.