https://github.com/jongacnik/sanitize-elements
sanitize-elements
https://github.com/jongacnik/sanitize-elements
Last synced: 8 months ago
JSON representation
sanitize-elements
- Host: GitHub
- URL: https://github.com/jongacnik/sanitize-elements
- Owner: jongacnik
- Created: 2015-03-23T01:26:40.000Z (about 11 years ago)
- Default Branch: master
- Last Pushed: 2015-03-23T01:27:21.000Z (about 11 years ago)
- Last Synced: 2025-03-06T18:19:31.226Z (over 1 year ago)
- Language: JavaScript
- Size: 97.7 KB
- Stars: 3
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# sanitize-elements
Makes sure you've got dom elements, if dom elements are what you want
Accepts a dom node, a node list, a jQuery object, an array of dom nodes, etc. Will return dom elements as a plain array. Single dom elements can be wrapped in an array if optional wrap param is passed as true. If dom element(s) aren't passed in, returns false.
## Install
npm install sanitize-elements
## Usage
sanitize-elements is meant to be consumed in a [CommonJS](http://www.commonjs.org/), [Browserify](http://browserify.org/) environment (though you can also use a pre-bundled version, more below):
var sanitizeElements = require('sanitize-elements');
sanitizeElements(elements, wrap)
// elements: elements to sanitize
// wrap: wrap single dom elements in array, default false
Some simple (abstracted) examples:
sanitizeElements(document.querySelector('.element'))
// returns $element
sanitizeElements(document.querySelector('.element'), true)
// returns [$element]
sanitizeElements(document.querySelectorAll('.elements'))
// returns [$element, $element, ...]
sanitizeElements($('.elements'))
// returns [$element, $element, ...]
sanitizeElements(window)
// returns false
sanitizeElements('iWannaBeAnElement')
// returns false
In the context of a function:
var something = function($elements) {
if ($elements = sanitizeElements($elements)) {
// do something
} else {
console.warn('Pass in some elements please!')
return
}
}
## Bundled Version
If you don't want to mess with a build process you can also include the pre-bundled version found in `dist/sanitize-elements.bundled.js` in your project which exposes `sanitizeElements()` globally.
## Todo
- Tests