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 4.0.0-alpha to 4.0.0

CHANGELOG.md

14

index.js

@@ -8,2 +8,3 @@ // internal

// packages
const archieml = require('archieml');
const dset = require('dset');

@@ -17,3 +18,4 @@ const dsv = require('d3-dsv');

const cwd = path.normalize(rawPath);
const files = await glob('**/*.{js,json,yaml,yml,csv,tsv}', {
const files = await glob('**/*.{js,json,yaml,yml,csv,tsv,aml}', {
absolute: true,

@@ -32,2 +34,3 @@ cwd,

if (ext === '.js') {
// js path
data = require(file);

@@ -42,9 +45,16 @@

if (ext === '.json') {
// json path
data = parseJson(fileContents, file);
} else if (ext === '.yaml' || ext === '.yml') {
// yaml path
data = yaml.safeLoad(fileContents);
} else if (ext === '.csv') {
// csv path
data = dsv.csvParse(fileContents);
} else if (ext === '.tsv') {
// tsv path
data = dsv.tsvParse(fileContents);
} else {
data = dsv.tsvParse(fileContents);
// aml path
data = archieml.load(fileContents);
}

@@ -51,0 +61,0 @@ }

5

package.json
{
"name": "quaff",
"version": "4.0.0-alpha",
"version": "4.0.0",
"description": "Collect JSON/YAML/YML/CSV/TSV files from a source folder and convert them into a single object.",

@@ -37,5 +37,6 @@ "repository": "rdmurphy/quaff",

"precise-commits": "^1.0.2",
"prettier": "^1.15.3"
"prettier": "^1.16.1"
},
"dependencies": {
"archieml": "^0.4.2",
"d3-dsv": "^1.0.10",

@@ -42,0 +43,0 @@ "dset": "^2.0.1",

<p align="center">
<img src="https://i.imgur.com/yC80ftQ.png" width="150" height="217" alt="quaff">
</p>
<h1 align="center">
quaff
</h1>
<p align="center">
<br><br>

@@ -11,10 +16,8 @@ <a href="https://www.npmjs.org/package/quaff"><img src="https://img.shields.io/npm/v/quaff.svg?style=flat" alt="npm"></a>

# quaff
## Key features
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.
- 🚚 A **data pipeline helper** written in Node.js 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 JS, AML ([ArchieML](http://archieml.org)), JSON, YAML, CSV and/or TSV files and **get a JavaScript object back that reflects the folder's structure and content/exports**
- 🤓 Under the hood it uses [`parse-json`](https://github.com/sindresorhus/parse-json) (for better JSON error support), [`js-yaml`](https://github.com/nodeca/js-yaml) and [`d3-dsv`](https://github.com/d3/d3-dsv) to **read files efficently**
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), [`js-yaml`](https://github.com/nodeca/js-yaml) and [`d3-dsv`](https://github.com/d3/d3-dsv) to read files.
## Installation

@@ -26,3 +29,3 @@

Requires `node>=8`.
`quaff` requires **Node.js 8 or later**.

@@ -33,3 +36,3 @@ ## Usage

```
```txt
data/

@@ -42,2 +45,3 @@ mammals/

parrots.yml
story.aml
```

@@ -48,5 +52,6 @@

```js
var quaff = require('quaff');
var data = quaff('./data/');
const quaff = require('quaff');
const data = await quaff('./data/');
console.log(data);

@@ -77,2 +82,9 @@ ```

"dead": ["Moose"]
},
"story": {
"title": "All about birds",
"prose": [
{ "type": "text", "value": "Do you know how great birds are?" },
{ "type": "text", "value": "Come with me on this journey." }
]
}

@@ -83,2 +95,66 @@ }

## Advanced Usage with JavaScript files
One of the biggest features added in `quaff` 4.0 is the ability to load JavaScript files. But how exactly does that work?
JavaScript files that are consumed by `quaff` have to follow one simple rule - they must export a default function (or value) at `module.exports`. All three of these are valid and return the same value:
```js
module.exports = [
{
name: 'Pudge',
instagram: 'https://instagram.com/pudgethecorgi/',
},
];
```
```js
module.exports = () => [
{
name: 'Pudge',
instagram: 'https://instagram.com/pudgethecorgi/',
},
];
```
```js
module.exports = async () => [
{
name: 'Pudge',
instagram: 'https://instagram.com/pudgethecorgi/',
},
];
```
The final example above is the most interesting one - `async` functions are supported! This means you can write code to hit API endpoints, or do other asynchronous work, and `quaff` will wait for those to resolve as it prepares the data object it returns.
```js
const fetch = require('node-fetch');
module.exports = async () => {
const res = await fetch('https://my-cool-api/');
const data = await res.json();
// whatever the API returned will be added to the quaff object!
return data;
};
```
Don't have a `Promise` to do async work with? Working with a callback interface? Just wrap it in one!
```js
const apiHelper = require('my-callback-api');
module.exports = () => {
return new Promise((resolve, reject) => {
apiHelper('people', (err, data) => {
if (err) return reject(err);
// quaff will take it from here!
resolve(data);
});
});
};
```
## License

@@ -85,0 +161,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