From 5de89f6001fa4dae822c892927520ac27c3887de Mon Sep 17 00:00:00 2001 From: danikaze Date: Tue, 22 Mar 2022 15:10:58 +0900 Subject: [PATCH 1/4] Provide named export for clsx --- clsx.d.ts | 2 +- readme.md | 6 ++++++ src/index.js | 4 +++- test/index.js | 4 ++++ 4 files changed, 14 insertions(+), 2 deletions(-) diff --git a/clsx.d.ts b/clsx.d.ts index c3e5769..e0edfd0 100644 --- a/clsx.d.ts +++ b/clsx.d.ts @@ -6,6 +6,6 @@ export interface ClassDictionary { export interface ClassArray extends Array { } -declare const clsx: (...classes: ClassValue[]) => string; +export const clsx: (...classes: ClassValue[]) => string; export default clsx; diff --git a/readme.md b/readme.md index 6c465d0..43899f6 100644 --- a/readme.md +++ b/readme.md @@ -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: + +```js +import { clsx } from 'clsx'; +``` + ## API diff --git a/src/index.js b/src/index.js index abce2aa..adc2673 100644 --- a/src/index.js +++ b/src/index.js @@ -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++]) { @@ -38,3 +38,5 @@ export default function () { } return str; } + +export default clsx; diff --git a/test/index.js b/test/index.js index 8be66cc..e34ca04 100644 --- a/test/index.js +++ b/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(); }); From 513e0c99daea83c9e33646a2663347b59c0e676b Mon Sep 17 00:00:00 2001 From: Luke Edwards Date: Sat, 2 Jul 2022 10:35:20 -0700 Subject: [PATCH 2/4] update readme --- readme.md | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/readme.md b/readme.md index 43899f6..cba8d87 100644 --- a/readme.md +++ b/readme.md @@ -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'); @@ -46,12 +48,6 @@ 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: - -```js -import { clsx } from 'clsx'; -``` - ## API From f4f161d8ed67a433960208e8f47f7efcad732984 Mon Sep 17 00:00:00 2001 From: Luke Edwards Date: Sat, 2 Jul 2022 10:36:27 -0700 Subject: [PATCH 3/4] update types --- clsx.d.ts | 11 +++-------- 1 file changed, 3 insertions(+), 8 deletions(-) diff --git a/clsx.d.ts b/clsx.d.ts index e0edfd0..f557360 100644 --- a/clsx.d.ts +++ b/clsx.d.ts @@ -1,11 +1,6 @@ export type ClassValue = ClassArray | ClassDictionary | string | number | null | boolean | undefined; +export type ClassDictionary = Record; +export type ClassArray = ClassValue[]; -export interface ClassDictionary { - [id: string]: any; -} - -export interface ClassArray extends Array { } - -export const clsx: (...classes: ClassValue[]) => string; - +export declare function clsx(...inputs: ClassValue[]): string; export default clsx; From 7fccd4989386e9d3f5e9d5a7845733b57bcbfeb6 Mon Sep 17 00:00:00 2001 From: Luke Edwards Date: Sat, 2 Jul 2022 10:41:27 -0700 Subject: [PATCH 4/4] update test file --- test/index.js | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/test/index.js b/test/index.js index e34ca04..b1ee1b8 100644 --- a/test/index.js +++ b/test/index.js @@ -1,13 +1,16 @@ import test from 'tape'; -import fn from '../src'; -import { clsx } 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'); - t.is(fn, clsx, "named import available"); - t.is(typeof clsx, "function", "exports a named function"); - t.is(typeof clsx(), "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(); });