cleanify

strip single/multiline comments

npm install cleanify
16 downloads in the last month

Cleanify

Nodejs module for stripping single/multiline comments from string/s.

Install:

npm install cleanify

To run tests enter module dir and run:

node test.js

Usage:

var fs = require('fs');
var Cleanify = require('cleanify');

/*
 * Choose literal string skip type:
 *   SINGLE: skip only single quoted strings -> 'b//la'
 *   DOUBLE: skip only double quoted strings -> "b//a"
 *   MULTI: skip both string types -> "b//la" 'b//a'
 */
var cleanify = new Cleanify(Cleanify.SINGLE);
var cleanify = new Cleanify(Cleanify.DOUBLE);
var cleanify = new Cleanify(Cleanify.MULTI);

// Multi is default
var cleanify = new Cleanify();

var lol = fs.readFileSync('./test/lol.js', 'utf8');

// One argument -> return stripped string
var string = cleanify.strip(lol);

// require() can load .json but comments are not allowed
var wtf = fs.readFileSync('./test/wtf.json', 'utf8');
var oh = fs.readFileSync('./test/oh.txt', 'utf8');

// More then one arguments -> return array of stripped strings
var array = cleanify.strip(lol, oh, wtf);

console.log('string: ' + string);
console.log('array: ' + JSON.stringify(array));
npm loves you