Skip to content

Commit

Permalink
Fee-fi-fo-fum!
Browse files Browse the repository at this point in the history
  • Loading branch information
jorgebucaran committed Jan 26, 2018
1 parent 55d4af6 commit 2dc4cf2
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 29 deletions.
14 changes: 2 additions & 12 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -54,17 +54,7 @@ import cc from "classcat"
If you prefer not to use a build system, you can load Classcat from a CDN and it will be globally available through the `window.classcat` object.

```html
<!doctype html>
<html>
<body>
<script src="https://unpkg.com/classcat"></script>
<script>
const cc = classcat
</script>
</body>
</html>
<script src="//unpkg.com/classcat"></script>
```

## Usage
Expand Down Expand Up @@ -100,7 +90,7 @@ cc([

## Credits

Classcat is inspired by [JedWatson/classNames](https://github.com/JedWatson/classnames) with support for nested objects and [better performance](/bench/README.md).
Classcat is an alternative to [JedWatson/classNames](https://github.com/JedWatson/classnames) with support for nested objects and [superior performance](/bench/README.md).
The difference between classcat and classNames is that classNames accepts a [variable number of arguments](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Functions/arguments), whereas classcat only accepts a single argument.

```js
Expand Down
24 changes: 7 additions & 17 deletions src/index.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
export default function cc(classes, prefix) {
var value
var classNames = ""
var next
var type = typeof classes
var result = ""

prefix = prefix || ""

Expand All @@ -15,27 +15,17 @@ export default function cc(classes, prefix) {

if (Array.isArray(classes) && classes.length > 0) {
for (var i = 0, len = classes.length; i < len; i++) {
if ((value = cc(classes[i], prefix))) {
classNames += (classNames && " ") + value
if ((next = cc(classes[i], prefix))) {
result += (result && " ") + next
}
}
} else if (type === "object") {
for (var key in classes) {
if ((value = cc(classes[key], prefix + key))) {
classNames += (classNames && " ") + value
if ((next = cc(classes[key], prefix + key))) {
result += (result && " ") + next
}
}
}

return classNames
return result
}

/*
case "object":
for (var key in classes) {
if (next = cc(classes[key], prefix + (isNaN(key) ? key : ""))) {
classNames += (classNames ? " " : "") + next;
}
}
return classNames;
*/

0 comments on commit 2dc4cf2

Please sign in to comment.