Skip to content

Commit

Permalink
Merge pull request #229 from JedWatson/cleanup
Browse files Browse the repository at this point in the history
Minor cleanup
  • Loading branch information
JedWatson committed Apr 1, 2021
2 parents c866e9b + 6c684f8 commit 1432ad1
Show file tree
Hide file tree
Showing 7 changed files with 2,889 additions and 509 deletions.
8 changes: 4 additions & 4 deletions bind.js
Expand Up @@ -10,7 +10,7 @@

var hasOwn = {}.hasOwnProperty;

function classNames() {
function classNames () {
var classes = [];

for (var i = 0; i < arguments.length; i++) {
Expand All @@ -24,14 +24,14 @@
} else if (Array.isArray(arg)) {
classes.push(classNames.apply(this, arg));
} else if (argType === 'object') {
if (arg.toString !== Object.prototype.toString) {
classes.push(arg.toString());
} else {
if (arg.toString === Object.prototype.toString) {
for (var key in arg) {
if (hasOwn.call(arg, key) && arg[key]) {
classes.push(this && this[key] || key);
}
}
} else {
classes.push(arg.toString());
}
}
}
Expand Down
8 changes: 4 additions & 4 deletions dedupe.js
Expand Up @@ -28,17 +28,17 @@
resultSet[num] = true;
}

function _parseObject(resultSet, object) {
if(object.toString !== Object.prototype.toString) {
resultSet[object.toString()] = true;
} else {
function _parseObject (resultSet, object) {
if (object.toString === Object.prototype.toString) {
for (var k in object) {
if (hasOwn.call(object, k)) {
// set value to false instead of deleting it to avoid changing object structure
// https://www.smashingmagazine.com/2012/11/writing-fast-memory-efficient-javascript/#de-referencing-misconceptions
resultSet[k] = !!object[k];
}
}
} else {
resultSet[object.toString()] = true;
}
}

Expand Down
13 changes: 4 additions & 9 deletions index.d.ts
Expand Up @@ -8,15 +8,10 @@
// Michal Adamczyk <https://github.com/mradamczyk>
// Marvin Hagemeister <https://github.com/marvinhagemeister>

export type ClassValue = string | number | ClassDictionary | ClassArray | undefined | null | boolean;
export type Value = string | number | boolean | undefined | null;
export type Mapping = { [key: string]: Value };
export type Argument = Value | Mapping | Argument[];

export interface ClassDictionary
{
[id: string]: boolean | undefined | null;
}

export interface ClassArray extends Array<ClassValue> {}

export function classNames(...args: ClassArray): string;
export function classNames(...args: Argument[]): string;

export default classNames;
8 changes: 4 additions & 4 deletions index.js
Expand Up @@ -22,21 +22,21 @@
if (argType === 'string' || argType === 'number') {
classes.push(arg);
} else if (Array.isArray(arg)) {
if(arg.length) {
if (arg.length) {
var inner = classNames.apply(null, arg);
if (inner) {
classes.push(inner);
}
}
} else if (argType === 'object') {
if (arg.toString !== Object.prototype.toString) {
classes.push(arg.toString());
} else {
if (arg.toString === Object.prototype.toString) {
for (var key in arg) {
if (hasOwn.call(arg, key) && arg[key]) {
classes.push(key);
}
}
} else {
classes.push(arg.toString());
}
}
}
Expand Down

0 comments on commit 1432ad1

Please sign in to comment.