From 56ab81f4255d86d323fa04e5ab462aeb9c43f56d Mon Sep 17 00:00:00 2001 From: danikaze Date: Sun, 3 Jul 2022 02:46:48 +0900 Subject: [PATCH] feat: add named `clsx` export alias (#44) * Provide named export for clsx * update readme * update types * update test file Co-authored-by: Luke Edwards --- clsx.d.ts | 11 +++-------- readme.md | 2 ++ src/index.js | 4 +++- test/index.js | 15 +++++++++++---- 4 files changed, 19 insertions(+), 13 deletions(-) diff --git a/clsx.d.ts b/clsx.d.ts index c3e5769..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 { } - -declare const clsx: (...classes: ClassValue[]) => string; - +export declare function clsx(...inputs: ClassValue[]): string; export default clsx; diff --git a/readme.md b/readme.md index 6c465d0..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'); 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..b1ee1b8 100644 --- a/test/index.js +++ b/test/index.js @@ -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(); });