Socket
Socket
Sign inDemoInstall

require-folder-tree

Package Overview
Dependencies
1
Maintainers
1
Versions
21
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 1.2.1 to 1.3.0

8

changelog.md

@@ -63,1 +63,9 @@ # Changelog

* Travis runs tests on node 0.10 and 0.12
## 1.3.0
* fileNameAttribute/folderNameAttribute options
* fileParentAttribute/folderParentAttribute options
* Tests clear require cache before each test
* Run jshint on test code
* Restructure tests

18

lib/index.js

@@ -22,2 +22,6 @@ // --------------------

folderNameTransform: (options || {}).fileNameTransform,
//fileNameAttribute: undefined,
folderNameAttribute: (options || {}).fileNameAttribute,
//fileParentAttribute: undefined,
folderParentAttribute: (options || {}).fileParentAttribute,
flatten: false,

@@ -33,2 +37,7 @@ flattenPrefix: false,

if (options.fileNameAttribute === true) options.fileNameAttribute = 'name';
if (options.folderNameAttribute === true) options.folderNameAttribute = 'name';
if (options.fileParentAttribute === true) options.fileParentAttribute = 'parent';
if (options.folderParentAttribute === true) options.folderParentAttribute = 'parent';
// create flatten function

@@ -98,2 +107,4 @@ if (options.flatten && !options.flattenCustom) {

resultFiles[file] = require(filePath);
if (options.fileNameAttribute) resultFiles[file][options.fileNameAttribute] = file;
if (options.fileParentAttribute) resultFiles[file][options.fileParentAttribute] = result;
});

@@ -120,5 +131,10 @@

for (var thisFile in resultFolder) {
resultFolders[options.flattenCustom(file, thisFile)] = resultFolder[thisFile];
var thisFileName = options.flattenCustom(file, thisFile);
if (options.fileNameAttribute) resultFolder[thisFile][options.fileNameAttribute] = thisFileName;
if (options.fileParentAttribute) resultFolder[thisFile][options.fileParentAttribute] = result;
resultFolders[thisFileName] = resultFolder[thisFile];
}
} else {
if (options.folderNameAttribute) resultFolder[options.folderNameAttribute] = file;
if (options.folderParentAttribute) resultFolder[options.folderParentAttribute] = result;
resultFolders[file] = resultFolder;

@@ -125,0 +141,0 @@ }

2

package.json
{
"name": "require-folder-tree",
"version": "1.2.1",
"version": "1.3.0",
"description": "Utility to require multiple files in a folder tree with flexible options",

@@ -5,0 +5,0 @@ "main": "./lib/",

@@ -95,2 +95,34 @@ # require-folder-tree.js

### fileNameAttribute
When set, saves the file name (after `fileNameTransform` has been applied) as an attribute of each `require`-d file.
If `true`, uses value `'name'`. Defaults to `undefined`.
```js
requireFolderTree('/path/to/folder', { fileNameAttribute: true, recurse: false });
// returns { a: { name: 'a', ... }, b: { name: 'b', ... } }
```
### folderNameAttribute
Like `fileNameAttribute`, but for folder names.
By default, inherits value of `options.fileNameAttribute`. If you want to save file names only, set `options.folderNameAttribute = null`.
### fileParentAttribute
When set, saves the parent folder as an attribute of each `require`-d file.
If `true`, uses value `'parent'`. Defaults to `undefined`.
```js
requireFolderTree('/path/to/folder', { fileParentAttribute: true, recurse: false });
// returns { a: { parent: <reference to root object>, ... }, b: { parent: <reference to root object>, ... } }
```
### folderParentAttribute
Like `fileParentAttribute`, but for folders.
By default, inherits value of `options.fileParentAttribute`. If you want to save file parents only, set `options.folderParentAttribute = null`.
### flatten

@@ -97,0 +129,0 @@

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc