Package Exports
- string-extract-class-names
This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (string-extract-class-names) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.
Readme
string-extract-class-names
Extract classes (or id's) from a string into an array
Install
$ npm install --save string-extract-class-namesPurpose
This library extracts the classes and id's from the string and returns them all put into an array.
I use string-extract-class-names to identify and delete unused CSS selectors in the library email-remove-unused-css.
Since deleting of people's code is a risky task, a huge responsibility falls onto parts which identify what should be deleted. That's why I extracted the string-extract-class-names from the email-remove-unused-css and set up a proper test suite.
Currently there 196 checks in test.js running on AVA. I'm checking all the possible (and impossible) strings in and around the class and id names to be 100% sure only correct class and id names are put into the results array.
Examples
var extract = require('string-extract-class-names')
// chop off tag, then the rest after the space character:
extract('div.first.second#third a[target=_blank]')
// => ['.first', '.second', '#third']
extract('?#id1#id2? #id3#id4> p > #id5#id6')
// => ['#id1', '#id2', '#id3', '#id4', '#id5', '#id6']API
extract(
string // String. Input.
)
// => Extracted classes/id's in an arrayContributing & testing
All contributions welcome. This library uses Standard JavaScript notation. See test.js. It's very minimalistic testing setup using AVA.
npm testIf you see anything incorrect whatsoever, raise an issue. PR's are welcome — fork, hack and PR.
Licence
MIT © Roy Reveltas