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 1.1.0 to 2.0.0

48

index.js
'use strict';
var fs = require('fs');
var glob = require('glob');
var path = require('path');
var yaml = require('js-yaml');
const fs = require('fs');
const glob = require('glob');
const path = require('path');
const yaml = require('js-yaml');
const dsv = require('d3-dsv');
function normalizePath(dir) {
var cleanDir = path.normalize(dir);
function normalizePath (dir) {
const cleanDir = path.normalize(dir);

@@ -19,20 +20,25 @@ if (cleanDir.slice(-path.sep.length) !== path.sep) {

module.exports = function(rawDataDir) {
var dataDir = normalizePath(rawDataDir);
var depth = dataDir.split(path.sep).length - 1;
var files = glob.sync(dataDir + '**/*.{json,yaml,yml}');
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}');
var payload = {};
const payload = {};
files.forEach(function(file) {
var extension = path.extname(file);
var basename = path.basename(file, extension);
var dir = path.normalize(path.dirname(file));
files.forEach(function (file) {
const extension = path.extname(file);
const basename = path.basename(file, extension);
const dir = path.normalize(path.dirname(file));
const fileContents = fs.readFileSync(file, 'utf8');
var data;
let data;
if (extension === '.json') {
data = JSON.parse(fs.readFileSync(file, 'utf8'));
data = JSON.parse(fileContents);
} else if (extension === '.yaml' || extension === '.yml') {
data = yaml.safeLoad(fs.readFileSync(file, 'utf8'));
data = yaml.safeLoad(fileContents);
} else if (extension === '.csv') {
data = dsv.csv.parse(fileContents);
} else if (extension === '.tsv') {
data = dsv.tsv.parse(fileContents);
} else {

@@ -42,8 +48,8 @@ return;

var obj = payload;
let obj = payload;
var dirs = dir.split(path.sep);
const dirs = dir.split(path.sep);
dirs.splice(0, depth); // dump the root dataDir
dirs.forEach(function(dir) {
dirs.forEach(function (dir) {
if (!obj.hasOwnProperty(dir)) {

@@ -50,0 +56,0 @@ obj[dir] = {};

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

@@ -12,6 +12,8 @@ "author": "Ryan Murphy <ryan@rdmurphy.org>",

"engines": {
"node": ">=0.10.0"
"node": ">=4"
},
"scripts": {
"test": "mocha"
"test": "mocha",
"coverage": "istanbul cover _mocha",
"coveralls": "cat ./coverage/lcov.info | coveralls"
},

@@ -22,11 +24,17 @@ "keywords": [

"yaml",
"yml"
"yml",
"csv",
"tsv"
],
"devDependencies": {
"mocha": "^2.2.1"
"coveralls": "^2.11.6",
"istanbul": "^0.4.2",
"mocha": "^2.3.4",
"mocha-lcov-reporter": "^1.0.0"
},
"dependencies": {
"glob": "^5.0.3",
"d3-dsv": "^0.1.13",
"glob": "^6.0.4",
"js-yaml": "^3.2.7"
}
}
![](http://i.imgur.com/yC80ftQ.png)
# quaff [![Build Status](https://travis-ci.org/rdmurphy/quaff.svg?branch=master)](https://travis-ci.org/rdmurphy/quaff) [![Dependencies](https://david-dm.org/rdmurphy/quaff.svg)](https://david-dm.org/rdmurphy/quaff)
# quaff [![Build Status](https://travis-ci.org/rdmurphy/quaff.svg?branch=master)](https://travis-ci.org/rdmurphy/quaff) [![Dependencies](https://david-dm.org/rdmurphy/quaff.svg)](https://david-dm.org/rdmurphy/quaff) [![Coverage Status](https://coveralls.io/repos/rdmurphy/quaff/badge.svg?branch=master&service=github)](https://coveralls.io/github/rdmurphy/quaff?branch=master)
A data pipeline helper written in node that works similar to [Middleman](https://middlemanapp.com/)'s [Data Files](https://middlemanapp.com/advanced/data_files/) collector.
Point the library at a folder filled with JSON and/or YAML files and get a JavaScript object back that reflects the folder's structure. Great for pulling data in to templates!
Point the library at a folder filled with JSON, YAML, CSV and/or TSV files and get a JavaScript object back that reflects the folder's structure. Great for pulling data in to templates!
Under the hood it uses JavaScript's built in [JSON support](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/JSON) and [`js-yaml`](https://github.com/nodeca/js-yaml) to read files.
Under the hood it uses JavaScript's built in [JSON support](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/JSON), [`js-yaml`](https://github.com/nodeca/js-yaml) and [`d3-dsv`](https://github.com/d3/d3-dsv) to read files.

@@ -17,3 +17,3 @@ ## Installation

Requires the latest `iojs` or `node>=0.12.0`.
Requires `node>=4`.

@@ -29,2 +29,3 @@ ## Usage

dogs.json
bears.csv
birds/

@@ -55,2 +56,12 @@ parrots.yml

"Cally"
],
"bears": [
{
"name": "Steve",
"type": "Polar bear"
},
{
"name": "Angelica",
"type": "Sun bear"
}
]

@@ -57,0 +68,0 @@ },

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