Comparing version 1.0.2 to 1.0.3
29
index.js
@@ -1,27 +0,7 @@ | ||
var fs = require('fs') | ||
, Walk = require('./lib/walk') | ||
var Walk = require('./lib/walk') | ||
, Serialize = require('./lib/serialize'); | ||
/** | ||
* Load and parse file contents. | ||
* Serialize a commonmark AST to line-delimited JSON. | ||
* | ||
* The options are passed to the Walk and Serialize streams.. | ||
* | ||
* @function load | ||
* @param {String} file path. | ||
* @param {Object} [opts] processing options. | ||
* | ||
* @returns the parser stream. | ||
*/ | ||
function load(path, opts) { | ||
opts.buffer = true; | ||
var source = fs.createReadStream(path) | ||
, ast = new Walk(opts) | ||
, serialize = new Serialize(opts); | ||
return source.pipe(ast).pipe(serialize); | ||
} | ||
/** | ||
* Parse a commonmark string. | ||
* | ||
* When a callback function is given it is added as a listener for | ||
@@ -31,3 +11,3 @@ * the error and finish events on the parser stream. | ||
* @function serialize | ||
* @param {String|Buffer} buffer input data. | ||
* @param {Object} buffer input AST. | ||
* @param {Object} [opts] processing options. | ||
@@ -44,2 +24,4 @@ * @param {Function} [cb] callback function. | ||
opts = opts || {}; | ||
var ast = new Walk(opts) | ||
@@ -65,4 +47,3 @@ , serialize = new Serialize(opts); | ||
module.exports = { | ||
load: load, | ||
serialize: serialize | ||
} |
@@ -7,8 +7,10 @@ var through = require('through3') | ||
return function (key, val) { | ||
var invalid = Boolean(~seen.indexOf(val)) | ||
|| key === '_parent' || key === '_prev' || key === '_lastChild'; | ||
if(invalid) { | ||
return; | ||
} | ||
if(!val || typeof (val) !== 'object') { | ||
return val; | ||
} | ||
if(~seen.indexOf(val)) { | ||
return; | ||
} | ||
seen.push(val); | ||
@@ -20,12 +22,2 @@ return val; | ||
/** | ||
* Converts AST nodes to newline delimited JSON. | ||
* | ||
* @module {constructor} AstSerialize | ||
* @param {Object} [opts] stream options. | ||
*/ | ||
function AstSerialize(opts) { | ||
opts = opts || {}; | ||
} | ||
/** | ||
* Stream transform. | ||
@@ -44,2 +36,2 @@ * | ||
module.exports = through.transform(transform, {ctor: AstSerialize}) | ||
module.exports = through.transform(transform); |
@@ -12,13 +12,2 @@ var through = require('through3'); | ||
/** | ||
* Iterates an AST document and emits on every node. | ||
* | ||
* @module {constructor} AstWalk | ||
* @param {Object} [opts] stream options. | ||
*/ | ||
function AstWalk(opts) { | ||
opts = opts || {}; | ||
} | ||
/** | ||
* Stream transform. | ||
@@ -57,2 +46,2 @@ * | ||
module.exports = through.transform(transform, {ctor: AstWalk}) | ||
module.exports = through.transform(transform); |
{ | ||
"name": "mkast", | ||
"version": "1.0.2", | ||
"version": "1.0.3", | ||
"description": "Commonmark AST transformer", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
@@ -6,2 +6,3 @@ var expect = require('chai').expect | ||
, ast = require('../../index') | ||
, Walk = require('../../lib/walk') | ||
, Deserialize = require('../../lib/deserialize'); | ||
@@ -11,4 +12,11 @@ | ||
it('should parse string input w/ callback', function(done) { | ||
it('should serialize ast w/ callback', function(done) { | ||
var parser = new Parser() | ||
, buffer = parser.parse('# Title\n<? @include file.md ?>'); | ||
ast.serialize(buffer, done); | ||
}); | ||
it('should serialize and deserialize ast', function(done) { | ||
var parser = new Parser() | ||
@@ -22,3 +30,2 @@ , buffer = parser.parse('# Title\n<? @include file.md ?>') | ||
expect(doc).to.be.an('object'); | ||
console.dir(doc) | ||
expect((new Renderer()).render(doc)).to.eql(expected); | ||
@@ -32,2 +39,20 @@ done(); | ||
it('should skip non-document on walk', function(done) { | ||
var walker = new Walk(); | ||
walker.once('finish', done); | ||
walker.end({_type: 'foo'}); | ||
}); | ||
it('should error on bad json', function(done) { | ||
var deserializer = new Deserialize(); | ||
deserializer.once('error', function(err) { | ||
function fn() { | ||
throw err; | ||
} | ||
expect(fn).throws(Error); | ||
done(); | ||
}); | ||
deserializer.end(new Buffer('{')); | ||
}); | ||
}); |
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
Filesystem access
Supply chain riskAccesses the file system, and could potentially read sensitive data.
Found 1 instance in 1 package
0
15884
222