JSPM

  • Created
  • Published
  • Downloads 21238
  • Score
    100M100P100Q149956F
  • License MIT

Extract class (or id) name from a string

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

ESLint on airbnb-base with caveats

Extract class (or id) name from a string

Minimum Node version required Link to npm page Build Status Coverage bitHound Overall Score bitHound Dependencies View dependencies as 2D chart bitHound Dev Dependencies Known Vulnerabilities Downloads/Month Test in browser MIT License

Install

npm i string-extract-class-names

Here's what you'll get:

Type Key in package.json Path Size
Main export - CommonJS version, transpiled, contains require and module.exports main dist/string-extract-class-names.cjs.js 2 KB
ES module build that Webpack/Rollup understands. Untranspiled ES6 code with import/export. module dist/string-extract-class-names.esm.js 2 KB
UMD build for browsers, transpiled, minified, containing iife's and has all dependencies baked-in browser dist/string-extract-class-names.umd.js 8 KB

⬆  back to top

Table of Contents

Purpose

This library extracts the class and id names from the string and returns them all put into an array.

I use string-extract-class-names to identify all the CSS class names from the parsed HTML/CSS in the library email-remove-unused-css which detects and deletes the unused CSS styles.

Since deleting of people's code is a risky task, a huge responsibility falls onto parts which identify what should be deleted, and more importantly, parts which identify class names and id's. 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 and nothing else.

⬆  back to top

Examples

var extract = require('string-extract-class-names')

// two classes and one id extracted:
extract('div.first.second#third a[target=_blank]')
// => ['.first', '.second', '#third']

// six id's extracted (works even despite the nonsensical question mark characters):
extract('?#id1#id2? #id3#id4> p > #id5#id6')
// => ['#id1', '#id2', '#id3', '#id4', '#id5', '#id6']

⬆  back to top

API

extract(
  string               // String. Input.
)
// => Extracted classes/id's in an array

Contributing

Hi! 99% of people in the society are passive - consumers. They wait for others to take action, they prefer to blend in. The remaining 1% are proactive citizens who will do something rather than wait. If you are one of that 1%, you're in luck because I am the same and together we can make something happen.

  • If you want a new feature in this package or you would like to change some of its functionality, raise an issue on this repo. Also, you can email me. Just let it out.

  • If you tried to use this library but it misbehaves, or you need an advice setting it up, and its readme doesn't make sense, just document it and raise an issue on this repo. Alternatively, you can email me.

  • If you don't like the code in here and would like to give an advice about how something could be done better, please do. Same drill - GitHub issues or email, your choice.

  • If you would like to add or change some features, just fork it, hack away, and file a pull request. I'll do my best to merge it quickly. Code style is airbnb, only without semicolons. If you use a good code editor, it will pick up the established ESLint setup.

⬆  back to top

Licence

MIT License (MIT)

Copyright © 2017 Codsen Ltd, Roy Revelt