Comparing version 0.0.0 to 1.0.0
27
index.js
'use strict'; | ||
module.exports = function (str, opts) { | ||
var objType = require('obj-type'); | ||
function add(el, str) { | ||
if (el.classList) { | ||
el.classList.add(str); | ||
} else { | ||
el.className += ' ' + str; | ||
} | ||
} | ||
module.exports = function (el, str) { | ||
if (objType(el).indexOf('element') === -1 && objType(el) !== 'nodelist') { | ||
throw new TypeError('Expected HTML DOM element(s) as first argument'); | ||
} | ||
if (typeof str !== 'string') { | ||
throw new TypeError('Expected a string'); | ||
throw new TypeError('Expected a string as second argument'); | ||
} | ||
opts = opts || {}; | ||
if (objType(el).indexOf('element') !== -1) { | ||
add(el, str); | ||
return; | ||
} | ||
return str + ' & ' + (opts.postfix || 'rainbows'); | ||
for (var i = 0; i < el.length; i++) { | ||
add(el[i], str); | ||
} | ||
}; |
{ | ||
"name": "add-class", | ||
"version": "0.0.0", | ||
"description": "My stellar module", | ||
"version": "1.0.0", | ||
"description": "Add a given class to elements.", | ||
"license": "MIT", | ||
"repository": "gillstrom/add-class", | ||
"author": { | ||
"name": "gillstrom", | ||
"email": "andreasgillstrom@gmail.com", | ||
"name": "Andreas Gillström", | ||
"url": "github.com/gillstrom" | ||
@@ -15,5 +15,2 @@ }, | ||
}, | ||
"scripts": { | ||
"test": "mocha" | ||
}, | ||
"files": [ | ||
@@ -23,8 +20,13 @@ "index.js" | ||
"keywords": [ | ||
"" | ||
"add", | ||
"browser", | ||
"class", | ||
"className", | ||
"class name", | ||
"DOM", | ||
"element" | ||
], | ||
"dependencies": {}, | ||
"devDependencies": { | ||
"mocha": "*" | ||
"dependencies": { | ||
"obj-type": "^1.0.0" | ||
} | ||
} |
@@ -1,6 +0,8 @@ | ||
# add-class [![Build Status](https://travis-ci.org/gillstrom/add-class.svg?branch=master)](https://travis-ci.org/gillstrom/add-class) | ||
# add-class | ||
> My stellar module | ||
> Add a given class to elements. | ||
*Supported in IE8+* | ||
## Install | ||
@@ -17,31 +19,36 @@ | ||
var addClass = require('add-class'); | ||
var el = document.querySelector('div'); | ||
var els = document.querySelectorAll('span'); | ||
addClass('unicorns'); | ||
//=> unicorns & rainbows | ||
addClass(el, 'foo'); | ||
addClass(els, 'bar'); | ||
``` | ||
## API | ||
## Browser API | ||
### addClass(input, [options]) | ||
### addClass(element, className) | ||
#### input | ||
#### element | ||
*Required* | ||
Type: HTML DOM element | ||
Element(s) to add class to. | ||
#### className | ||
*Required* | ||
Type: `string` | ||
Lorem ipsum. | ||
Class name to be added. | ||
#### options | ||
##### foo | ||
## Related | ||
Type: `boolean` | ||
Default: `false` | ||
* [has-class](https://github.com/gillstrom/has-class) - Check if an element has a given class. | ||
Lorem ipsum. | ||
## License | ||
MIT © [gillstrom](http://github.com/gillstrom) | ||
MIT © [Andreas Gillström](http://github.com/gillstrom) |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Trivial Package
Supply chain riskPackages less than 10 lines of code are easily copied into your own project and may not warrant the additional supply chain risk of an external dependency.
Found 1 instance in 1 package
No v1
QualityPackage is not semver >=1. This means it is not stable and does not support ^ ranges.
Found 1 instance in 1 package
2950
0
24
1
54
0
1
+ Addedobj-type@^1.0.0
+ Addedobj-type@1.0.1(transitive)