1.2.1 • Published 10 years ago
webshortener v1.2.1
webShortener
Utility for shortening ids and classnames.
Installation
npm install -g webshortener
Usage
CLI
webshortener [-h path] [--html path] [-c path] [--css path] [-j path] [--js path] [-o path] [--output path] path ...
More at man webshortener
As a library
API
- A container for information common to all streams
new Shortener();
- Shortener streams for different file types
new Shortener().htmlShortener
new Shortener().cssShortener
new Shortener().jsShortener
Example
var Shortener = require('webShortener');
var shrtnr = new Shortener();
fs.createReadStream('./index.html').pipe(shrtnr.htmlShortener())
.on('error', function(err)
{
console.err(err);
process.exit(1);
})
.pipe(fs.createWriteStream('./index.html.parsed'));
.on('finish', function()
{
console.log('Finished parsing index.html');
})
What gets replaced
- In HTML files id and class attributes get replaced
- In CSS files selectors, containing ids and classes get shortened
- In JS files special comments get replaced
/* webname .class */
,/* webname #id */
Replacement generation
Replacement for ids and classnames is generated separately.
E.X. id='a' class='a'
, not id='a' class='b'
A replacement is guaranteed to be the shortest one available, while it being unique.