-
Notifications
You must be signed in to change notification settings - Fork 564
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Co-authored-by: Daniel Cousens <[email protected]>
- Loading branch information
Showing
14 changed files
with
156 additions
and
258 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
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 |
---|---|---|
@@ -1,17 +1,3 @@ | ||
import { ArgumentArray } from './index.js'; | ||
|
||
declare namespace classNames { | ||
type Binding = Record<string, string>; | ||
} | ||
|
||
interface ClassNames { | ||
(this: classNames.Binding | undefined, ...args: ArgumentArray): string; | ||
|
||
default: ClassNames; | ||
} | ||
|
||
declare const classNames: ClassNames; | ||
|
||
export as namespace classNames; | ||
|
||
export = classNames; | ||
export type Binding = Record<string, string>; | ||
export default function classNames(this: Binding | undefined, ...args: ArgumentArray): string; |
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 |
---|---|---|
@@ -1,77 +1,54 @@ | ||
/*! | ||
Copyright (c) 2018 Jed Watson. | ||
Licensed under the MIT License (MIT), see | ||
http://jedwatson.github.io/classnames | ||
*/ | ||
/* global define */ | ||
const hasOwn = {}.hasOwnProperty; | ||
|
||
(function () { | ||
'use strict'; | ||
export default function classNames () { | ||
let classes = ''; | ||
|
||
var hasOwn = {}.hasOwnProperty; | ||
for (let i = 0; i < arguments.length; i++) { | ||
const arg = arguments[i]; | ||
if (arg) { | ||
classes = appendClass(classes, parseValue.call(this, arg)); | ||
} | ||
} | ||
|
||
function classNames () { | ||
var classes = ''; | ||
return classes; | ||
} | ||
|
||
for (var i = 0; i < arguments.length; i++) { | ||
var arg = arguments[i]; | ||
if (arg) { | ||
classes = appendClass(classes, parseValue.call(this, arg)); | ||
} | ||
} | ||
function parseValue (arg) { | ||
if (typeof arg === 'string' || typeof arg === 'number') { | ||
return this && this[arg] || arg; | ||
} | ||
|
||
return classes; | ||
if (typeof arg !== 'object') { | ||
return ''; | ||
} | ||
|
||
function parseValue (arg) { | ||
if (typeof arg === 'string' || typeof arg === 'number') { | ||
return this && this[arg] || arg; | ||
} | ||
if (Array.isArray(arg)) { | ||
return classNames.apply(this, arg); | ||
} | ||
|
||
if (typeof arg !== 'object') { | ||
return ''; | ||
} | ||
if (arg.toString !== Object.prototype.toString && !arg.toString.toString().includes('[native code]')) { | ||
return arg.toString(); | ||
} | ||
|
||
if (Array.isArray(arg)) { | ||
return classNames.apply(this, arg); | ||
} | ||
let classes = ''; | ||
|
||
if (arg.toString !== Object.prototype.toString && !arg.toString.toString().includes('[native code]')) { | ||
return arg.toString(); | ||
for (const key in arg) { | ||
if (hasOwn.call(arg, key) && arg[key]) { | ||
classes = appendClass(classes, this && this[key] || key); | ||
} | ||
} | ||
|
||
var classes = ''; | ||
|
||
for (var key in arg) { | ||
if (hasOwn.call(arg, key) && arg[key]) { | ||
classes = appendClass(classes, this && this[key] || key); | ||
} | ||
} | ||
return classes; | ||
} | ||
|
||
return classes; | ||
function appendClass (value, newClass) { | ||
if (!newClass) { | ||
return value; | ||
} | ||
|
||
function appendClass (value, newClass) { | ||
if (!newClass) { | ||
return value; | ||
} | ||
|
||
if (value) { | ||
return value + ' ' + newClass; | ||
} | ||
|
||
return value + newClass; | ||
if (value) { | ||
return value + ' ' + newClass; | ||
} | ||
|
||
if (typeof module !== 'undefined' && module.exports) { | ||
classNames.default = classNames; | ||
module.exports = classNames; | ||
} else if (typeof define === 'function' && typeof define.amd === 'object' && define.amd) { | ||
// register as 'classnames', consistent with npm package name | ||
define('classnames', [], function () { | ||
return classNames; | ||
}); | ||
} else { | ||
window.classNames = classNames; | ||
} | ||
}()); | ||
return value + newClass; | ||
} |
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 |
---|---|---|
@@ -1,5 +1,2 @@ | ||
import classNames = require('./index.js'); | ||
|
||
export as namespace classNames; | ||
|
||
export = classNames; | ||
import classNames from './index.js'; | ||
export default classNames; |
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 |
---|---|---|
@@ -1,115 +1,94 @@ | ||
/*! | ||
Copyright (c) 2018 Jed Watson. | ||
Licensed under the MIT License (MIT), see | ||
http://jedwatson.github.io/classnames | ||
*/ | ||
/* global define */ | ||
|
||
(function () { | ||
'use strict'; | ||
|
||
var classNames = (function () { | ||
// don't inherit from Object so we can skip hasOwnProperty check later | ||
// http://stackoverflow.com/questions/15518328/creating-js-object-with-object-createnull#answer-21079232 | ||
function StorageObject() {} | ||
StorageObject.prototype = Object.create(null); | ||
|
||
function _parseArray (resultSet, array) { | ||
var length = array.length; | ||
|
||
for (var i = 0; i < length; ++i) { | ||
_parse(resultSet, array[i]); | ||
} | ||
} | ||
const classNames = (function () { | ||
// don't inherit from Object so we can skip hasOwnProperty check later | ||
// http://stackoverflow.com/questions/15518328/creating-js-object-with-object-createnull#answer-21079232 | ||
function StorageObject() {} | ||
StorageObject.prototype = Object.create(null); | ||
|
||
var hasOwn = {}.hasOwnProperty; | ||
function _parseArray (resultSet, array) { | ||
const length = array.length; | ||
|
||
function _parseNumber (resultSet, num) { | ||
resultSet[num] = true; | ||
for (let i = 0; i < length; ++i) { | ||
_parse(resultSet, array[i]); | ||
} | ||
} | ||
|
||
function _parseObject (resultSet, object) { | ||
if (object.toString !== Object.prototype.toString && !object.toString.toString().includes('[native code]')) { | ||
resultSet[object.toString()] = true; | ||
return; | ||
} | ||
const hasOwn = {}.hasOwnProperty; | ||
|
||
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]; | ||
} | ||
function _parseNumber (resultSet, num) { | ||
resultSet[num] = true; | ||
} | ||
|
||
function _parseObject (resultSet, object) { | ||
if (object.toString !== Object.prototype.toString && !object.toString.toString().includes('[native code]')) { | ||
resultSet[object.toString()] = true; | ||
return; | ||
} | ||
|
||
for (const 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]; | ||
} | ||
} | ||
} | ||
|
||
var SPACE = /\s+/; | ||
function _parseString (resultSet, str) { | ||
var array = str.split(SPACE); | ||
var length = array.length; | ||
const SPACE = /\s+/; | ||
function _parseString (resultSet, str) { | ||
const array = str.split(SPACE); | ||
const length = array.length; | ||
|
||
for (var i = 0; i < length; ++i) { | ||
resultSet[array[i]] = true; | ||
} | ||
for (let i = 0; i < length; ++i) { | ||
resultSet[array[i]] = true; | ||
} | ||
} | ||
|
||
function _parse (resultSet, arg) { | ||
if (!arg) return; | ||
var argType = typeof arg; | ||
function _parse (resultSet, arg) { | ||
if (!arg) return; | ||
const argType = typeof arg; | ||
|
||
// 'foo bar' | ||
if (argType === 'string') { | ||
_parseString(resultSet, arg); | ||
// 'foo bar' | ||
if (argType === 'string') { | ||
_parseString(resultSet, arg); | ||
|
||
// ['foo', 'bar', ...] | ||
} else if (Array.isArray(arg)) { | ||
_parseArray(resultSet, arg); | ||
// ['foo', 'bar', ...] | ||
} else if (Array.isArray(arg)) { | ||
_parseArray(resultSet, arg); | ||
|
||
// { 'foo': true, ... } | ||
} else if (argType === 'object') { | ||
_parseObject(resultSet, arg); | ||
// { 'foo': true, ... } | ||
} else if (argType === 'object') { | ||
_parseObject(resultSet, arg); | ||
|
||
// '130' | ||
} else if (argType === 'number') { | ||
_parseNumber(resultSet, arg); | ||
} | ||
// '130' | ||
} else if (argType === 'number') { | ||
_parseNumber(resultSet, arg); | ||
} | ||
} | ||
|
||
function _classNames () { | ||
// don't leak arguments | ||
// https://github.com/petkaantonov/bluebird/wiki/Optimization-killers#32-leaking-arguments | ||
var len = arguments.length; | ||
var args = Array(len); | ||
for (var i = 0; i < len; i++) { | ||
args[i] = arguments[i]; | ||
} | ||
function _classNames () { | ||
// don't leak arguments | ||
// https://github.com/petkaantonov/bluebird/wiki/Optimization-killers#32-leaking-arguments | ||
const length = arguments.length; | ||
const args = Array(length); | ||
for (let i = 0; i < length; i++) { | ||
args[i] = arguments[i]; | ||
} | ||
|
||
var classSet = new StorageObject(); | ||
_parseArray(classSet, args); | ||
const classSet = new StorageObject(); | ||
_parseArray(classSet, args); | ||
|
||
var list = []; | ||
const list = []; | ||
|
||
for (var k in classSet) { | ||
if (classSet[k]) { | ||
list.push(k) | ||
} | ||
for (const k in classSet) { | ||
if (classSet[k]) { | ||
list.push(k) | ||
} | ||
|
||
return list.join(' '); | ||
} | ||
|
||
return _classNames; | ||
})(); | ||
|
||
if (typeof module !== 'undefined' && module.exports) { | ||
classNames.default = classNames; | ||
module.exports = classNames; | ||
} else if (typeof define === 'function' && typeof define.amd === 'object' && define.amd) { | ||
// register as 'classnames', consistent with npm package name | ||
define('classnames', [], function () { | ||
return classNames; | ||
}); | ||
} else { | ||
window.classNames = classNames; | ||
return list.join(' '); | ||
} | ||
}()); | ||
|
||
return _classNames; | ||
})(); | ||
|
||
export default classNames; |
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
Oops, something went wrong.