https://github.com/json2d/css-extractor
:gem: extracts class names and ids from CSS
https://github.com/json2d/css-extractor
Last synced: about 1 year ago
JSON representation
:gem: extracts class names and ids from CSS
- Host: GitHub
- URL: https://github.com/json2d/css-extractor
- Owner: json2d
- License: mit
- Created: 2017-03-23T15:44:45.000Z (over 9 years ago)
- Default Branch: master
- Last Pushed: 2017-03-23T20:29:46.000Z (over 9 years ago)
- Last Synced: 2025-03-23T22:07:00.086Z (over 1 year ago)
- Language: JavaScript
- Homepage:
- Size: 4.88 KB
- Stars: 1
- Watchers: 1
- Forks: 0
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# css-extractor
:gem: extracts class names and ids from CSS
### Installing
```
$ npm install css-extractor
```
### Basic Usage
```javascript
var extractor = require('css-extractor');
var css = "#id, .class { color:#000 }";
extractor.extract(css);
// => ['#id','.class']
```
`extract` will return an array of all unique class names and ids
### Approach
This module was designed to be lightweight, with no dependencies, using `RegExp` patterns to trim the input CSS content and capture the class names and ids.
### Testing
Tests are performed using the `tap` testing framework. To run:
```
$ npm install
$ npm test
```
The main focus of the test cases is to ensure compatibility with common and uncommon syntactic features and liberties available in CSS, including:
* `@media` queries
* attribute selectors: `#id[href='#id-like']`
* arbitrary and non-mandatory spacing
* comment blocks
For more on such cases, check out the `.css` files in `test\fixtures`