directory-tree-md
Advanced tools
Comparing version 2.0.6 to 2.0.7
@@ -5,2 +5,3 @@ 'use strict'; | ||
const PATH = require('path'); | ||
const YAML = require('yamljs'); | ||
const constants = { | ||
@@ -24,14 +25,2 @@ DIRECTORY: 'directory', | ||
function strToObj(str) { | ||
const arr = str.split('\n').filter((item) => !!item); | ||
const json = {}; | ||
for (let i = 0; i < arr.length; i += 1) { | ||
const item = arr[i].split(":"); | ||
const key = item[0] ? String.prototype.trim.call(item[0]) : item[0] | ||
const value = item[1] ? String.prototype.trim.call(item[1]) : item[1] | ||
json[key] = value; | ||
} | ||
return json; | ||
} | ||
function directoryTree(path, options, onEachFile) { | ||
@@ -62,3 +51,3 @@ const name = PATH.basename(path); | ||
item.relative = item.path.replace(process.cwd(), ''); | ||
item.mdconf = contentMatch ? strToObj(contentMatch[1]) : {}; | ||
item.mdconf = contentMatch ? YAML.parse(contentMatch[1]) : {}; | ||
item.isEmpty = contentMatch ? !String.prototype.trim.call(contentStr.replace(contentMatch[0], '')) : true; | ||
@@ -65,0 +54,0 @@ } |
{ | ||
"name": "directory-tree-md", | ||
"version": "2.0.6", | ||
"version": "2.0.7", | ||
"description": "Convert a directory tree to a JS object.", | ||
@@ -20,3 +20,5 @@ "repository": { | ||
"homepage": "https://github.com/react-doc/node-directory-tree-md", | ||
"dependencies": {}, | ||
"dependencies": { | ||
"yamljs": "^0.3.0" | ||
}, | ||
"devDependencies": { | ||
@@ -32,2 +34,2 @@ "chai": "^2.3.0", | ||
} | ||
} | ||
} |
@@ -26,3 +26,3 @@ # node-directory-tree-md | ||
Markdown configuration set by comments. | ||
Markdown configuration set by comments, support [yaml](http://www.yaml.org/). | ||
@@ -34,2 +34,4 @@ ```markdown | ||
des: A detailed description | ||
header: | ||
url: http://google.com | ||
--> | ||
@@ -54,3 +56,6 @@ | ||
"heder": "😆😆😆😆", | ||
"des": "A detailed description" | ||
"des": "A detailed description", | ||
"header": { | ||
"url": "http://google.com" | ||
} | ||
}, | ||
@@ -57,0 +62,0 @@ "isEmpty": true, |
209
7617
1
64
+ Addedyamljs@^0.3.0
+ Addedargparse@1.0.10(transitive)
+ Addedbalanced-match@1.0.2(transitive)
+ Addedbrace-expansion@1.1.11(transitive)
+ Addedconcat-map@0.0.1(transitive)
+ Addedfs.realpath@1.0.0(transitive)
+ Addedglob@7.2.3(transitive)
+ Addedinflight@1.0.6(transitive)
+ Addedinherits@2.0.4(transitive)
+ Addedminimatch@3.1.2(transitive)
+ Addedonce@1.4.0(transitive)
+ Addedpath-is-absolute@1.0.1(transitive)
+ Addedsprintf-js@1.0.3(transitive)
+ Addedwrappy@1.0.2(transitive)
+ Addedyamljs@0.3.0(transitive)