Security News
Node.js EOL Versions CVE Dubbed the "Worst CVE of the Year" by Security Experts
Critics call the Node.js EOL CVE a misuse of the system, sparking debate over CVE standards and the growing noise in vulnerability databases.
gatherator helps you to fetch data from different resources and work with the response, in a fluently generator based way.
npm install gatherator
If you ever wanted to fetch unlimited data from any kind of resource and format, the gatherator will be the library which makes your life easy. Out of the box we support HTTP and File resources as well as JSON and XML formated data, but you can easily create your own retrievers and parsers. After you successfully fetched your data, we also support you with the possibility to modify each single iterated value.
You are interested now? Give it a chance!
Creates an async generator, which could be used to iterate through the whole response of your retriever. It takes some options to modify the retriever, parse the raw fetched data and transform the result in the way you will need it.
const { createGenerator, retriever: { createHttpRetriever } } = require('../index')
const generator = await createGenerator({
uri: 'https://mock.server.com/get-data',
retriever: createHttpRetriever({ json: true })
})
// iterate through the generator and log out the data
for await (const data of generator) {
console.log(data)
}
Option | Type | Description |
---|---|---|
uri | `{string | function}` |
retriever | {function} | Provides the possibility to fetch data from the uri. |
getRetrieverOptions | {function} | Will always be executed before fetching data and gives you the possibility modify the retriever options. For example raise an offset property. |
parsers | {[functions]} | A list of transformers to made the raw fetched data be readable for JavaScript. |
transformers | {[functions]} | A list of transformers, which will be executed on each iterated value. |
...other | {*} | All other given options will be used as default retriever options, which can later be modified with the getRetrieverOptions option. |
Returns a retriever function, which executes an http request with request-promise.
const { retriever: { createHttpRetriever } } = require('../index')
const retriever = createHttpRetriever() // takes optional options for the http operation
Returns a retriever function, which executes an file read with fs-extra.
const { retriever: { createFileRetriever } } = require('../index')
const retriever = createFileRetriever() // takes optional options for the file operation
Parser functions are the transformers for the raw retriever response. They will be used to transform the response to a valid JSON object.
Set the path to the root element we want to gather. Mostly this will be the path to a list ob objects.
const { parser: { setRootPath } } = require('../index')
setRootPath('data.list') // takes the path to the root
Transforms the raw HTTP response from a JSON string to a valid object.
const { parser: { stringToJson } } = require('../index')
stringToJson()
Transforms the raw HTTP response from a XML string to a valid object, with xml2js.
const { parser: { xmlToJson } } = require('../index')
xmlToJson() // takes optional xml parser options
Transformer functions helps you to prepare different modification operation, which will be executed for each element after the parsing process. The usecase for these function is just to prepare your own transformers to work with a generator.
Modifies the value by passing them to the given mapper function.
const { transformer: { map } } = require('../index')
const mapRenaming = map(({ name, ...other }) => ({ ...other, name: String(name).toUpperCase() }))
Filters out values by the result of the given filter function.
const { transformer: { filter } } = require('../index')
const filterOutSmallNames = map(({ name }) => String(name).length >= 6)
Modifies the value by passing them to the given mapper function and filters them out, if the modified value is undefined
.
const { transformer: { transform } } = require('../index')
const transformUpperCaseLongWords = map(({ name, ...other }) => {
if (String(name).length >= 6)) {
return { ...other, name: String(name).toUpperCase() }
}
}
FAQs
iterate over any resource
The npm package gatherator receives a total of 8 weekly downloads. As such, gatherator popularity was classified as not popular.
We found that gatherator 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.
Security News
Critics call the Node.js EOL CVE a misuse of the system, sparking debate over CVE standards and the growing noise in vulnerability databases.
Security News
cURL and Go security teams are publicly rejecting CVSS as flawed for assessing vulnerabilities and are calling for more accurate, context-aware approaches.
Security News
Bun 1.2 enhances its JavaScript runtime with 90% Node.js compatibility, built-in S3 and Postgres support, HTML Imports, and faster, cloud-first performance.