Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

add-class

Package Overview
Dependencies
Maintainers
1
Versions
5
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

add-class - npm Package Compare versions

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);
}
};

22

package.json
{
"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

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc