diff --git a/.gitignore b/.gitignore index a22e55e..2b9d76a 100644 --- a/.gitignore +++ b/.gitignore @@ -5,3 +5,4 @@ components/ coverage/ node_modules/ build.js +.idea diff --git a/index.js b/index.js index f3912ee..8936d41 100644 --- a/index.js +++ b/index.js @@ -15,13 +15,16 @@ * * @param {NLCSTNode|Array.} node - Node to to * stringify. + * @param {string} separator - a specified separator * @return {string} - Stringified `node`. */ -function nlcstToString(node) { +function nlcstToString(node, separator) { var values; var length; var children; + separator = separator || ''; + if (typeof node.value === 'string') { return node.value; } @@ -40,10 +43,10 @@ function nlcstToString(node) { values = []; while (length--) { - values[length] = nlcstToString(children[length]); + values[length] = nlcstToString(children[length], separator); } - return values.join(''); + return values.join(separator); } /* diff --git a/nlcst-to-string.js b/nlcst-to-string.js index 94ea398..7d21825 100644 --- a/nlcst-to-string.js +++ b/nlcst-to-string.js @@ -16,13 +16,16 @@ * * @param {NLCSTNode|Array.} node - Node to to * stringify. + * @param {string} separator - a specified separator * @return {string} - Stringified `node`. */ -function nlcstToString(node) { +function nlcstToString(node, separator) { var values; var length; var children; + separator = separator || ''; + if (typeof node.value === 'string') { return node.value; } @@ -41,10 +44,10 @@ function nlcstToString(node) { values = []; while (length--) { - values[length] = nlcstToString(children[length]); + values[length] = nlcstToString(children[length], separator); } - return values.join(''); + return values.join(separator); } /* diff --git a/nlcst-to-string.min.js b/nlcst-to-string.min.js index d51ead6..71ed205 100644 --- a/nlcst-to-string.min.js +++ b/nlcst-to-string.min.js @@ -1 +1 @@ -!function(b,a){typeof exports==='object'&&typeof module!=='undefined'?module.exports=b():typeof define==='function'&&define.amd?define([],b):(typeof window!=='undefined'?a=window:typeof global!=='undefined'?a=global:typeof self!=='undefined'?a=self:a=this,a.nlcstToString=b())}(function(){return function a(b,c,e){function f(d,k){if(!c[d]){if(!b[d]){var i=typeof require=='function'&&require;if(!k&&i)return i(d,!0);if(g)return g(d,!0);var j=new Error("Cannot find module '"+d+"'");throw j.code='MODULE_NOT_FOUND',j}var h=c[d]={exports:{}};b[d][0].call(h.exports,function(c){var a=b[d][1][c];return f(a?a:c)},h,h.exports,a,b,c,e)}return c[d].exports}var g=typeof require=='function'&&require;for(var d=0;d