-
-
Notifications
You must be signed in to change notification settings - Fork 144
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
194 additions
and
25 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,18 +6,30 @@ | |
"module": "dist/clsx.mjs", | ||
"unpkg": "dist/clsx.min.js", | ||
"main": "dist/clsx.js", | ||
"types": "clsx.d.ts", | ||
"license": "MIT", | ||
"exports": { | ||
"import": { | ||
"types": "./clsx.d.mts", | ||
"default": "./dist/clsx.mjs" | ||
".": { | ||
"import": { | ||
"types": "./clsx.d.mts", | ||
"default": "./dist/clsx.mjs" | ||
}, | ||
"default": { | ||
"types": "./clsx.d.ts", | ||
"default": "./dist/clsx.js" | ||
} | ||
}, | ||
"default": { | ||
"types": "./clsx.d.ts", | ||
"default": "./dist/clsx.js" | ||
"./lite": { | ||
"import": { | ||
"types": "./clsx.d.mts", | ||
"default": "./dist/lite.mjs" | ||
}, | ||
"default": { | ||
"types": "./clsx.d.ts", | ||
"default": "./dist/lite.js" | ||
} | ||
} | ||
}, | ||
"types": "clsx.d.ts", | ||
"license": "MIT", | ||
"author": { | ||
"name": "Luke Edwards", | ||
"email": "[email protected]", | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
export function clsx() { | ||
var i=0, tmp, str='', len=arguments.length; | ||
for (; i < len; i++) { | ||
if (tmp = arguments[i]) { | ||
if (typeof tmp === 'string') { | ||
str += (str && ' ') + tmp; | ||
} | ||
} | ||
} | ||
return str; | ||
} | ||
|
||
export default clsx; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
// @ts-check | ||
import { test } from 'uvu'; | ||
import * as assert from 'uvu/assert'; | ||
import * as mod from '../src/lite'; | ||
|
||
const fn = mod.default; | ||
|
||
test('exports', () => { | ||
assert.type(mod.default, 'function', 'exports default function'); | ||
assert.type(mod.clsx, 'function', 'exports named function'); | ||
assert.is(mod.default, mod.clsx, 'exports are equal'); | ||
|
||
assert.type(mod.default(), 'string', '~> returns string output'); | ||
assert.type(mod.clsx(), 'string', '~> returns string output'); | ||
}); | ||
|
||
test('strings', () => { | ||
assert.is(fn(''), ''); | ||
assert.is(fn('foo'), 'foo'); | ||
assert.is(fn(true && 'foo'), 'foo'); | ||
assert.is(fn(false && 'foo'), ''); | ||
}); | ||
|
||
test('strings (variadic)', () => { | ||
assert.is(fn(''), ''); | ||
assert.is(fn('foo', 'bar'), 'foo bar'); | ||
assert.is(fn(true && 'foo', false && 'bar', 'baz'), 'foo baz'); | ||
assert.is(fn(false && 'foo', 'bar', 'baz', ''), 'bar baz'); | ||
}); | ||
|
||
test('emptys', () => { | ||
assert.is(fn(''), ''); | ||
assert.is(fn(undefined), ''); | ||
assert.is(fn(null), ''); | ||
assert.is(fn(0), ''); | ||
}); | ||
|
||
// lite ignores all non-strings | ||
test('non-strings', () => { | ||
// number | ||
assert.is(fn(1), ''); | ||
assert.is(fn(1, 2), ''); | ||
assert.is(fn(Infinity), ''); | ||
assert.is(fn(NaN), ''); | ||
assert.is(fn(0), ''); | ||
|
||
// objects | ||
assert.is(fn({}), ''); | ||
assert.is(fn(null), ''); | ||
assert.is(fn({ a:1 }), ''); | ||
assert.is(fn({ a:1 }, { b:2 }), ''); | ||
|
||
// arrays | ||
assert.is(fn([]), ''); | ||
assert.is(fn(['foo']), ''); | ||
assert.is(fn(['foo', 'bar']), ''); | ||
|
||
// functions | ||
assert.is(fn(fn), ''); | ||
assert.is(fn(fn, fn), ''); | ||
}); | ||
|
||
test.run(); |