Comparing version 3.1.0 to 3.2.0
{ | ||
"name": "stringify", | ||
"description": "Browserify middleware to be able to require() text files (including templates) inside of your client-side JavaScript files.", | ||
"version": "3.1.0", | ||
"version": "3.2.0", | ||
"main": "./index.js", | ||
@@ -12,3 +12,4 @@ "author": "John Postlethwait <john.postlethwait@gmail.com>", | ||
"Sébastien David <sebastien.david.1983@gmail.com>", | ||
"Kenneth Skovhus <kenneth.skovhus@gmail.com>" | ||
"Kenneth Skovhus <kenneth.skovhus@gmail.com>", | ||
"Michaelangelo Jong <mike96angelo@gmail.com>" | ||
], | ||
@@ -31,8 +32,3 @@ "website": "http://johnpostlethwait.github.com/stringify/", | ||
}, | ||
"licenses": [ | ||
{ | ||
"name": "MIT", | ||
"url": "http://opensource.org/licenses/mit-license.php" | ||
} | ||
], | ||
"license": "MIT", | ||
"dependencies": { | ||
@@ -39,0 +35,0 @@ "html-minifier": "^0.6.9", |
@@ -13,5 +13,26 @@ # Stringify # | ||
### Register With Node Require ### | ||
```javascript | ||
var stringify = require('stringify'); | ||
stringify.registerWithRequire({ | ||
extensions: ['.txt', '.html'], | ||
minify: true, | ||
minifier: { | ||
extensions: ['.html'], | ||
options: { | ||
// html-minifier options | ||
} | ||
} | ||
}); | ||
var myTextFile = require('./path/to/my/text/file.txt'); | ||
console.log(myTextFile); // prints the contents of file. | ||
``` | ||
### Browserify Command Line ### | ||
`browserity -t stringify myfile.js` | ||
`browserify -t stringify myfile.js` | ||
@@ -18,0 +39,0 @@ ### Browserify Middleware ### |
'use strict'; | ||
var htmlMinifier = require('html-minifier'), | ||
fs = require('fs'), | ||
path = require('path'), | ||
@@ -44,2 +45,4 @@ through = require('through'); | ||
var NODE_REQUIRE_OPTIONS = {}; | ||
/** | ||
@@ -129,4 +132,37 @@ * Stringifies the content | ||
/** | ||
* Reads in a file and stringifies and minifies the contents. | ||
* @param {String} module | ||
* @param {String} filename | ||
* @return {String} | ||
*/ | ||
function requireStringify (module, filename) { | ||
var contents; | ||
try { | ||
contents = fs.readFileSync(path.resolve(filename), 'utf8'); | ||
} catch (error) { | ||
throw new Error('Cannot find module \'' + filename + '\''); | ||
} | ||
module.exports = minify(filename, contents, NODE_REQUIRE_OPTIONS); | ||
} | ||
/** | ||
* Registers the given extensions with node require. | ||
* @param {Object|Array} options | ||
* @param {Object.Array} options.extensions | ||
* @return {void} | ||
*/ | ||
function registerWithRequire (options) { | ||
NODE_REQUIRE_OPTIONS = options || {}; | ||
var exts = getExtensions(NODE_REQUIRE_OPTIONS); | ||
for (var i = 0; i < exts.length; i++) { | ||
require.extensions[ exts[i] ] = requireStringify; | ||
} | ||
} | ||
/** | ||
* Exposes the Browserify transform function. | ||
@@ -184,4 +220,9 @@ * | ||
// exports registerWithRequire so stringify can be registered with node require. | ||
module.exports.registerWithRequire = registerWithRequire; | ||
// Test-environment specific exports... | ||
if (process.env.NODE_ENV) { | ||
module.exports.NODE_REQUIRE_OPTIONS = NODE_REQUIRE_OPTIONS; | ||
module.exports.requireStringify = requireStringify; | ||
module.exports.stringify = stringify; | ||
@@ -188,0 +229,0 @@ module.exports.getExtensions = getExtensions; |
@@ -39,2 +39,6 @@ /* jshint expr: true */ | ||
}); | ||
it('should have a method "registerWithRequire"', function () { | ||
stringify.registerWithRequire.should.be.a.Function; | ||
}); | ||
}); | ||
@@ -41,0 +45,0 @@ |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Misc. License Issues
License(Experimental) A package's licensing information has fine-grained problems.
Found 1 instance in 1 package
No License Found
License(Experimental) License information could not be found.
Found 1 instance in 1 package
27395
19
0
0
566
196
4