Skip to content

Commit

Permalink
Remove support for numbers (#370)
Browse files Browse the repository at this point in the history
Closes #239
  • Loading branch information
jonkoops committed Jan 24, 2024
1 parent 6e91360 commit 1d01e88
Show file tree
Hide file tree
Showing 12 changed files with 32 additions and 38 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ classNames({ foo: true, bar: true }); // => 'foo bar'
classNames('foo', { bar: true, duck: false }, 'baz', { quux: true }); // => 'foo bar baz quux'

// other falsy values are just ignored
classNames(null, false, 'bar', undefined, 0, 1, { baz: null }, ''); // => 'bar 1'
classNames(null, false, 'bar', undefined, 0, { baz: null }, ''); // => 'bar'
```

Arrays will be recursively flattened as per the rules above:
Expand Down
2 changes: 1 addition & 1 deletion benchmarks/benchmarks.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ const benchmarks = [
},
{
description: 'mix',
args: ['one', {two: true, three: false}, {four: 'four', five: true}, 6, {}]
args: ['one', {two: true, three: false}, {four: 'four', five: true}, {}]
},
{
description: 'arrays',
Expand Down
2 changes: 1 addition & 1 deletion bind.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ export default function classNames () {
}

function parseValue (arg) {
if (typeof arg === 'string' || typeof arg === 'number') {
if (typeof arg === 'string') {
return this && this[arg] || arg;
}

Expand Down
6 changes: 0 additions & 6 deletions dedupe.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,6 @@ function appendValue (classSet, arg) {
appendArray(classSet, arg);
} else if (argType === 'object') {
appendObject(classSet, arg);
} else if (argType === 'number') {
appendNumber(classSet, arg);
}
}

Expand All @@ -51,10 +49,6 @@ function appendArray (classSet, array) {
}
}

function appendNumber (classSet, num) {
classSet[num] = true;
}

const hasOwn = {}.hasOwnProperty;

function appendObject (classSet, object) {
Expand Down
2 changes: 1 addition & 1 deletion index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
// Sean Kelley <https://github.com/seansfkelley>
// Michal Adamczyk <https://github.com/mradamczyk>
// Marvin Hagemeister <https://github.com/marvinhagemeister>
export type Value = string | number | boolean | undefined | null;
export type Value = string | boolean | undefined | null;
export type Mapping = Record<string, any>;
export interface ArgumentArray extends Array<Argument> {}
export interface ReadonlyArgumentArray extends ReadonlyArray<Argument> {}
Expand Down
2 changes: 1 addition & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ export default function classNames () {
}

function parseValue (arg) {
if (typeof arg === 'string' || typeof arg === 'number') {
if (typeof arg === 'string') {
return arg;
}

Expand Down
4 changes: 2 additions & 2 deletions tests/bind.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ describe('bind', () => {
});

it('joins arrays of class names and ignore falsy values', () => {
assert.equal(classNames('a', 0, null, undefined, true, 1, 'b'), 'a 1 b');
assert.equal(classNames('a', 0, null, undefined, false, 'b'), 'a b');
});

it('supports heterogenous arguments', () => {
Expand Down Expand Up @@ -105,7 +105,7 @@ describe('bind', () => {
});

it('joins arrays of class names and ignore falsy values', () => {
assert.equal(classNamesBound('a', 0, null, undefined, true, 1, 'b'), '#a 1 #b');
assert.equal(classNamesBound('a', 0, null, undefined, false, 1, 'b'), '#a #b');
});

it('supports heterogenous arguments', () => {
Expand Down
12 changes: 6 additions & 6 deletions tests/bind.test-d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,17 +22,17 @@ bound(null);
bound(undefined);
bound(true);
bound(false);
bound(42);
bound({ conditional: true });
bound({ conditional: {} });
bound({ conditional: Symbol() });
bound([]);
bound([['bar', null, undefined, true, false, 1234]]);
bound(['bar', null, undefined, true, false, 1234]);
bound('bar', null, undefined, true, false, 1234);
bound([['bar', null, undefined, true, false]]);
bound(['bar', null, undefined, true, false]);
bound('bar', null, undefined, true, false);
bound('bar', ['abc', { foo: true }]);
bound('bar', ['abc', { foo: true }], { def: false, ijk: 1234 });
bound('abc', 1234, true, false, undefined, null, { foo: true }, ['abc', 1234, true, false, undefined, null, { foo: true }]);
bound('bar', ['abc', { foo: true }], { def: false });
bound('abc', true, false, undefined, null, { foo: true }, ['abc', true, false, undefined, null, { foo: true }]);
bound(foo);
bound(ifoo);
expectError(bound(Symbol()));
expectError(bound(42));
4 changes: 2 additions & 2 deletions tests/dedupe.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,14 @@ describe('dedupe', () => {
});

it('should make sure object with falsy value wipe out previous classes', () => {
assert.equal(dedupe('foo foo', 0, null, undefined, true, 1, 'b', { 'foo': false }), '1 b');
assert.equal(dedupe('foo foo', 0, null, undefined, false, 'b', { 'foo': false }), 'b');
assert.equal(dedupe('foo', 'foobar', 'bar', { foo: false }), 'foobar bar');
assert.equal(dedupe('foo', 'foo-bar', 'bar', { foo: false }), 'foo-bar bar');
assert.equal(dedupe('foo', '-moz-foo-bar', 'bar', { foo: false }), '-moz-foo-bar bar');
});

it('joins arrays of class names and ignore falsy values', () => {
assert.equal(dedupe('a', 0, null, undefined, true, 1, 'b'), '1 a b');
assert.equal(dedupe('a', 0, null, undefined, false, 'b'), 'a b');
});

it('supports heterogenous arguments', () => {
Expand Down
12 changes: 6 additions & 6 deletions tests/dedupe.test-d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,17 +19,17 @@ dedupe(null);
dedupe(undefined);
dedupe(true);
dedupe(false);
dedupe(42);
dedupe({ conditional: true });
dedupe({ conditional: {} });
dedupe({ conditional: Symbol() });
dedupe([]);
dedupe([['bar', null, undefined, true, false, 1234]]);
dedupe(['bar', null, undefined, true, false, 1234]);
dedupe('bar', null, undefined, true, false, 1234);
dedupe([['bar', null, undefined, true, false]]);
dedupe(['bar', null, undefined, true, false]);
dedupe('bar', null, undefined, true, false);
dedupe('bar', ['abc', { foo: true }]);
dedupe('bar', ['abc', { foo: true }], { def: false, ijk: 1234 });
dedupe('abc', 1234, true, false, undefined, null, { foo: true }, ['abc', 1234, true, false, undefined, null, { foo: true }]);
dedupe('bar', ['abc', { foo: true }], { def: false });
dedupe('abc', true, false, undefined, null, { foo: true }, ['abc', true, false, undefined, null, { foo: true }]);
dedupe(foo);
dedupe(ifoo);
expectError(dedupe(Symbol()));
expectError(dedupe(42));
2 changes: 1 addition & 1 deletion tests/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ describe('classNames', () => {
});

it('joins arrays of class names and ignore falsy values', () => {
assert.equal(classNames('a', 0, null, undefined, true, 1, 'b'), 'a 1 b');
assert.equal(classNames('a', 0, null, undefined, false, 'b'), 'a b');
});

it('supports heterogenous arguments', () => {
Expand Down
20 changes: 10 additions & 10 deletions tests/index.test-d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,25 +19,25 @@ classNames(null);
classNames(undefined);
classNames(true);
classNames(false);
classNames(42);
classNames({ conditional: true });
classNames({ conditional: {} });
classNames({ conditional: Symbol() });
classNames([]);
classNames([['bar', null, undefined, true, false, 1234]]);
classNames(['bar', null, undefined, true, false, 1234]);
classNames('bar', null, undefined, true, false, 1234);
classNames([['bar', null, undefined, true, false]]);
classNames(['bar', null, undefined, true, false]);
classNames('bar', null, undefined, true, false);
classNames('bar', ['abc', { foo: true }]);
classNames('bar', ['abc', { foo: true }], { def: false, ijk: 1234 });
classNames('abc', 1234, true, false, undefined, null, { foo: true }, ['abc', 1234, true, false, undefined, null, { foo: true }]);
classNames('abc', 1234, true, false, undefined, null, { foo: true }, ['abc', 1234, true, false, undefined, null, { foo: true }], ['abc', 1234, true, false, undefined, null, { foo: true }] as const);
classNames('bar', ['abc', { foo: true }], { def: false });
classNames('abc', true, false, undefined, null, { foo: true }, ['abc', true, false, undefined, null, { foo: true }]);
classNames('abc', true, false, undefined, null, { foo: true }, ['abc', true, false, undefined, null, { foo: true }], ['abc', 1234, true, false, undefined, null, { foo: true }] as const);
classNames(foo);
classNames(ifoo);
expectError(classNames(Symbol()));
expectError(classNames(42));
// should match tests/index.js
classNames('c', ['a', 'b']);
classNames('', 'b', {}, '');
classNames('a', 0, null, undefined, true, 1, 'b');
classNames('a', null, undefined, true, 'b');
classNames('a', [[]]);
classNames('a', []);
classNames('c', ['a', 'b']);
Expand All @@ -48,5 +48,5 @@ classNames(['a', 0, null, undefined, false, true, 'b']);
classNames(['a', ['b', 'c']]);
classNames(['a', ['b', ['c', {d: true}]]]);
classNames(['a', {b: true, c: false}]);
classNames({a: true}, 'b', 0);
classNames({}, Infinity, [{}, []]);
classNames({a: true}, 'b');
classNames({}, [{}, []]);

0 comments on commit 1d01e88

Please sign in to comment.