json-to-fs-structure
Advanced tools
Comparing version 1.2.0 to 1.2.1
30
index.js
@@ -9,3 +9,3 @@ const fs = require("fs"); | ||
const levelPropertiesToDirectories = (obj, filePath, stopWord, spaceReplace, executorObject = {}) => { | ||
const levelPropertiesToDirectories = (obj, filePath, stopWord, ignoredWords, spaceReplace, executorObject = {}) => { | ||
if (obj && (typeof obj === 'string' || obj instanceof String)) { | ||
@@ -27,3 +27,3 @@ return; | ||
promiseArray = promiseArray.concat( | ||
levelPropertiesToDirectories(arrayObject, filePath, stopWord, spaceReplace, { | ||
levelPropertiesToDirectories(arrayObject, filePath, stopWord, ignoredWords, spaceReplace, { | ||
leafProcedure, | ||
@@ -40,3 +40,3 @@ nonLeafProcedure, | ||
fields.forEach(property => { | ||
if (property !== stopWord) { | ||
if (property !== stopWord && ignoredWords.indexOf(property) === -1) { | ||
const newPath = spaceReplace ? `${filePath}${sep}${property.replace(/ /g, spaceReplace)}` : `${filePath}${sep}${property}`; | ||
@@ -54,3 +54,3 @@ try { | ||
promiseArray = promiseArray.concat( | ||
levelPropertiesToDirectories(obj[`${property}`], newPath, stopWord, spaceReplace, { | ||
levelPropertiesToDirectories(obj[`${property}`], newPath, stopWord, ignoredWords, spaceReplace, { | ||
leafProcedure, | ||
@@ -70,3 +70,3 @@ nonLeafProcedure, | ||
} | ||
} else { | ||
} else if(ignoredWords.indexOf(property) === -1) { | ||
if (leafProcedure) { | ||
@@ -85,5 +85,6 @@ accumulator = leafProcedure(`${filePath}${sep}`, accumulator, obj[`${property}`]); | ||
stopWord, | ||
spaceReplace | ||
spaceReplace, | ||
ignoredWords = [] | ||
}) { | ||
return Promise.all(levelPropertiesToDirectories(jsonObject, filePath, stopWord, spaceReplace)).then( | ||
return Promise.all(levelPropertiesToDirectories(jsonObject, filePath, stopWord, ignoredWords, spaceReplace)).then( | ||
callback | ||
@@ -100,6 +101,7 @@ ); | ||
stopWord, | ||
spaceReplace | ||
spaceReplace, | ||
ignoredWords = [] | ||
}) { | ||
return Promise.all( | ||
levelPropertiesToDirectories(jsonObject, filePath, stopWord, spaceReplace, { | ||
levelPropertiesToDirectories(jsonObject, filePath, stopWord, ignoredWords, spaceReplace, { | ||
leafProcedure, | ||
@@ -118,6 +120,7 @@ accumulator: context | ||
stopWord, | ||
spaceReplace | ||
spaceReplace, | ||
ignoredWords = [] | ||
}) { | ||
return Promise.all( | ||
levelPropertiesToDirectories(jsonObject, filePath, stopWord, spaceReplace, { | ||
levelPropertiesToDirectories(jsonObject, filePath, stopWord, ignoredWords, spaceReplace, { | ||
nonLeafProcedure, | ||
@@ -136,6 +139,7 @@ accumulator: context | ||
stopWord, | ||
spaceReplace | ||
spaceReplace, | ||
ignoredWords = [] | ||
}) { | ||
return Promise.all( | ||
levelPropertiesToDirectories(jsonObject, filePath, stopWord, spaceReplace, { | ||
levelPropertiesToDirectories(jsonObject, filePath, stopWord, ignoredWords, spaceReplace, { | ||
procedure, | ||
@@ -142,0 +146,0 @@ accumulator: context |
{ | ||
"name": "json-to-fs-structure", | ||
"version": "1.2.0", | ||
"version": "1.2.1", | ||
"description": "A simple module that takes a simple JSON file and produces the properties as a file structure in the same directory or given directory.", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
@@ -460,3 +460,42 @@ const assert = require("assert"); | ||
}); | ||
it("should not do anything with ignored words like meta", done => { | ||
const endpoints = []; | ||
const options = { | ||
jsonObject: { | ||
testArrayField5: [ | ||
{ somedir: {meta: {}, apple: {}} }, | ||
{ anotherdir: {} }, | ||
{ | ||
meta: {somethingweird: {}}, | ||
andanotherdir: { | ||
interiorone: { | ||
interiortwo: { | ||
apple: {dontdonothing: {}}, | ||
interiorthree: [{ interiorfour: {} }, { interiorfive: {} }] | ||
} | ||
} | ||
} | ||
} | ||
] | ||
}, | ||
procedure: (filePath, acc) => { | ||
endpoints.push(filePath); | ||
}, | ||
filePath: ".", | ||
context: {}, | ||
callback: () => { | ||
assert.equal(fs.statSync("testArrayField5/somedir").size, 4096); | ||
assert.equal(fs.statSync("testArrayField5/anotherdir").size, 4096); | ||
fs.rmdirSync("testArrayField5/somedir"); | ||
fs.rmdirSync("testArrayField5/anotherdir"); | ||
fs.rmdirSync("testArrayField5"); | ||
done(); | ||
}, | ||
ignoredWords: ['meta', 'apple'], | ||
stopWord: 'andanotherdir' | ||
}; | ||
jsonToFsWithFunction(options); | ||
expect(endpoints).toMatchSnapshot(); | ||
}); | ||
}); | ||
}); |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
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
190427
645