
Product
Introducing Module Reachability: Focus on the Vulnerabilities That Matter
Module Reachability filters out unreachable CVEs so you can focus on vulnerabilities that actually matter to your application.
Collect JS/JSON/YAML/YML/CSV/TSV/ArchieML files from a source folder and convert them into a single object.
quaff
is now a pure ESM package. It can no longer be require()
'd from CommonJS. If this functionality is still needed please continue to use quaff@^4
.
parse-json
(for better JSON error support), js-yaml
and d3-dsv
to read files efficientlynpm install quaff --save-dev
quaff
requires Node.js 12.20.0 or later.
Assume a folder with this structure.
data/
mammals/
cats.json
dogs.json
bears.csv
birds/
parrots.yml
story.aml
After import
'ing quaff
:
import { load } from 'quaff';
const data = await load('./data/');
console.log(data);
And the results...
{
"mammals": {
"cats": ["Marty", "Sammy"],
"dogs": ["Snazzy", "Cally"],
"bears": [
{
"name": "Steve",
"type": "Polar bear"
},
{
"name": "Angelica",
"type": "Sun bear"
}
]
},
"birds": {
"parrots": {
"alive": ["Buzz"],
"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." }
]
}
}
}
As of 5.0.0
it's now possible to load a single file at a time, enabling more custom approaches in case load
doesn't work exactly the way you'd like.
import { loadFile } from 'quaff';
const data = await loadFile('./data/mammals/bears.csv');
console.log(data);
And the results...
[
{
"name": "Steve",
"type": "Polar bear"
},
{
"name": "Angelica",
"type": "Sun bear"
}
]
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 default
a function, an async function or value. All three of these are valid and return the same value:
export default [
{
name: 'Pudge',
instagram: 'https://instagram.com/pudgethecorgi/',
},
];
export default () => [
{
name: 'Pudge',
instagram: 'https://instagram.com/pudgethecorgi/',
},
];
export default async () => [
{
name: 'Pudge',
instagram: 'https://instagram.com/pudgethecorgi/',
},
];
The final example above is the most interesting one - async
functions also work! This means you can write code to hit API endpoints, or do other asynchronous work, and quaff
will wait for those to resolve.
import fetch from 'node-fetch';
export default 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!
import {apiHelper } from 'my-callback-api';
export default () => {
return new Promise((resolve, reject) => {
apiHelper('people', (err, data) => {
if (err) return reject(err);
// quaff will take it from here!
resolve(data);
});
});
};
By Ryan Murphy.
Available under the MIT license.
[5.0.0] - 2021-06-12
quaff
individual file processor is now available at loadFile
. This makes it possible to tap into all of quaff
's processors to load a single file. The newly named load
export works the same as before and uses loadFile
behind the scenes..cjs
and .mjs
extensions.quaff
is now a pure ESM package. It can no longer be require()
'd from CommonJS. If this functionality is still needed please continue to use quaff@^4
. It is also possible to dynamically import ESM in CommonJS (await import('quaff')
) if that is compatible with your use case.quaff
no longer has a default export and now uses two named exports - load
and loadFile
.FAQs
Collect JS/JSON/YAML/YML/CSV/TSV/ArchieML files from a source folder and convert them into a single object.
The npm package quaff receives a total of 252 weekly downloads. As such, quaff popularity was classified as not popular.
We found that quaff demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Product
Module Reachability filters out unreachable CVEs so you can focus on vulnerabilities that actually matter to your application.
Company News
Socket is bringing best-in-class reachability analysis into the platform — cutting false positives, accelerating triage, and cementing our place as the leader in software supply chain security.
Product
Socket is introducing a new way to organize repositories and apply repository-specific security policies.