Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

dir-to-object

Package Overview
Dependencies
Maintainers
1
Versions
7
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

dir-to-object - npm Package Compare versions

Comparing version 1.0.0-alpha.3 to 1.0.0-alpha.4

__mocks__/foo/currencies.js

20

__tests__/index.test.js

@@ -5,5 +5,21 @@ const { join } = require('path');

describe('dirToObject', () => {
it('to match snapshot', () => {
expect(dirToObject(join(__dirname, '../__mocks__/foo'))).toMatchSnapshot();
const scenarios = [
{
config: { dirPath: join(__dirname, '../__mocks__/foo') },
description: 'config w/ dirPath only'
},
{
config: {
canAdd: data => data.resolve && data.type,
dirPath: join(__dirname, '../__mocks__/foo')
},
description: 'config w/ canAdd and dirPath'
}
];
scenarios.forEach(({ config, description }) => {
it(description, () => {
expect(dirToObject(config)).toMatchSnapshot();
});
});
});

5

package.json
{
"name": "dir-to-object",
"version": "1.0.0-alpha.3",
"version": "1.0.0-alpha.4",
"description": "Builds an object from the files contained inside a directory.",

@@ -9,3 +9,4 @@ "main": "index.js",

"pretest": "npm run eslint",
"test": "jest"
"test": "jest",
"test:watch": "jest --watch"
},

@@ -12,0 +13,0 @@ "repository": {

@@ -17,7 +17,14 @@ # dir-to-object

const foo = dirToObject(join(__dirname, 'foo'));
const config = {
canAdd: () => true,
dirPath: join(__dirname, 'foo')
};
const foo = dirToObject(config);
console.log(foo);
```
N.B.: `canAdd` is optional while `dirPath` is mandatory
## Contributing

@@ -24,0 +31,0 @@

const fs = require('fs');
const { join } = require('path');
const fields = path =>
fs.readdirSync(path).reduce((accumulator, current) => {
const fields = ({ canAdd, dirPath }) =>
fs.readdirSync(dirPath).reduce((accumulator, fileName) => {
const filePath = join(dirPath, fileName);
// eslint-disable-next-line global-require, import/no-dynamic-require
accumulator[current.replace('.js', '')] = require(`${path}/${current}`);
const content = require(filePath);
if (canAdd && canAdd(content)) {
accumulator[fileName.replace('.js', '')] = content;
}
if (!canAdd) {
accumulator[fileName.replace('.js', '')] = content;
}
return accumulator;

@@ -8,0 +16,0 @@ }, {});

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

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

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc