New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

quaff

Package Overview
Dependencies
Maintainers
1
Versions
11
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

quaff - npm Package Compare versions

Comparing version 2.0.0 to 3.0.0

LICENSE

68

index.js

@@ -1,31 +0,20 @@

'use strict';
// internal
const fs = require('fs');
const glob = require('glob');
const path = require('path');
// packages
const dset = require('dset');
const dsv = require('d3-dsv');
const glob = require('fast-glob');
const parseJson = require('parse-json');
const yaml = require('js-yaml');
const dsv = require('d3-dsv');
module.exports = function quaff(rawPath) {
const cwd = path.normalize(rawPath);
const files = glob.sync(path.join(cwd, '**/*.{json,yaml,yml,csv,tsv}'));
function normalizePath (dir) {
const cleanDir = path.normalize(dir);
if (cleanDir.slice(-path.sep.length) !== path.sep) {
return cleanDir + path.sep;
}
return cleanDir;
}
module.exports = function (rawDataDir) {
const dataDir = normalizePath(rawDataDir);
const depth = dataDir.split(path.sep).length - 1;
const files = glob.sync(dataDir + '**/*.{json,yaml,yml,csv,tsv}');
const payload = {};
files.forEach(function (file) {
const extension = path.extname(file);
const basename = path.basename(file, extension);
const dir = path.normalize(path.dirname(file));
files.forEach(function(file) {
const { name, dir, ext } = path.parse(file);
const fileContents = fs.readFileSync(file, 'utf8');

@@ -35,27 +24,22 @@

if (extension === '.json') {
data = JSON.parse(fileContents);
} else if (extension === '.yaml' || extension === '.yml') {
if (ext === '.json') {
data = parseJson(fileContents, file);
} else if (ext === '.yaml' || ext === '.yml') {
data = yaml.safeLoad(fileContents);
} else if (extension === '.csv') {
data = dsv.csv.parse(fileContents);
} else if (extension === '.tsv') {
data = dsv.tsv.parse(fileContents);
} else if (ext === '.csv') {
data = dsv.csvParse(fileContents);
} else {
return;
data = dsv.tsvParse(fileContents);
}
let obj = payload;
// remove the leading path, split into a list, and filter out empty strings
const dirs = path
.relative(cwd, dir)
.split(path.sep)
.filter(Boolean);
const dirs = dir.split(path.sep);
dirs.splice(0, depth); // dump the root dataDir
// add the filename to the path part list
dirs.push(name);
dirs.forEach(function (dir) {
if (!obj.hasOwnProperty(dir)) {
obj[dir] = {};
}
obj = obj[dir];
});
obj[basename] = data;
dset(payload, dirs, data);
});

@@ -62,0 +46,0 @@

{
"name": "quaff",
"version": "2.0.0",
"version": "3.0.0",
"description": "Collect JSON/YAML/YML/CSV/TSV files from a source folder and convert them into a single object.",

@@ -12,3 +12,3 @@ "repository": "rdmurphy/quaff",

"engines": {
"node": ">=4"
"node": ">=6"
},

@@ -29,12 +29,31 @@ "scripts": {

"devDependencies": {
"coveralls": "^2.11.6",
"coveralls": "^3.0.2",
"husky": "^1.1.1",
"istanbul": "^0.4.2",
"mocha": "^2.3.4",
"mocha-lcov-reporter": "^1.0.0"
"mocha": "^5.2.0",
"mocha-lcov-reporter": "^1.0.0",
"precise-commits": "^1.0.2",
"prettier": "^1.14.3"
},
"dependencies": {
"d3-dsv": "^0.1.13",
"glob": "^6.0.4",
"js-yaml": "^3.2.7"
"d3-dsv": "^1.0.10",
"dset": "^2.0.1",
"fast-glob": "^2.2.3",
"js-yaml": "^3.12.0",
"parse-json": "^4.0.0"
},
"prettier": {
"arrowParens": "avoid",
"bracketSpacing": true,
"printWidth": 80,
"semi": true,
"singleQuote": true,
"tabWidth": 2,
"trailingComma": "es5"
},
"husky": {
"hooks": {
"pre-commit": "precise-commits"
}
}
}

@@ -17,3 +17,3 @@ ![](http://i.imgur.com/yC80ftQ.png)

Requires `node>=4`.
Requires `node>=6`.

@@ -20,0 +20,0 @@ ## Usage

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