Security News
tea.xyz Spam Plagues npm and RubyGems Package Registries
Tea.xyz, a crypto project aimed at rewarding open source contributions, is once again facing backlash due to an influx of spam packages flooding public package registries.
@momsfriendlydevco/express-middleware-formatter
Advanced tools
Readme
Express middleware to provide alternate formatting of data when requested.
var emf = require('@momsfriendlydevco/express-middleware-formatter');
app.get('/api/data', emf(), function(req, res) {
res.send(someData);
});
# If /api/data is requested - normal JSON will be sent
# If /api/data?format=csv - JSON data will be transformed into CSV
# If /api/data?format=xlsx - JSON data will be transformed into XLSX
# etc.
Function which returns formatting middleware.
Supported options:
Option | Type | Default | Description |
---|---|---|---|
filename | string | Unset | If set this will be the filename used for any output format that requires a filename, overriding their own format specific filenames |
forceArray | boolean | false | Wrap the data in an array if the data provided is an object |
format | string or function | See source | Forced format to return as a string or if a function how to determine the format. By default this uses the req.query.format property if present |
key | string | null | Extract tabular data from this key path (dotted or array notation is supported) instead of assuming the whole JSON response is the tabular data |
unpack | function or array <function> | Undefined | A function or array of functions to run to mangle the data into something that can be processed, promise returns are supported. Called as (data, req, res, settings) |
csv | object | CSV specific options | |
csv.filename | string | "Exported Data.csv" | Default filename when exporting as CSV |
html | object | HTML specific options | |
html.download | boolean | false | If false, the HTML will be shown in the browser, if true the file will be forced as a download |
html.filename | string | "Exported Data.html" | Default filename when exporting as HTML |
html.footer | string | (Simple HTML footer) | Set the HTML suffix after outputting the body content for HTML |
html.header | string | (Simple HTML header) | Set the HTML prefix before outputting the body content for HTML |
html.passthru | boolean | false | Force the HTML output plugin to compute the data but not resolve the response - used internally by upstream formatters like pdf |
ods | object | ODS specific options | |
ods.filename | string | "Exported Data.ods" | Default filename when exporting as ODS |
pdf | object | PDF specific options | |
pdf.download | boolean | true | If false, the PDF will be shown in the browser (if the browser supports it), if true the file will be forced as a download |
pdf.filename | string | "Exported Data.pdf" | Default filename when exporting as PDF |
xlsx | object | XLSX specific options | |
xlsx.checkArray | boolean | true | Verify that the input is an array, disable this if picking your own fields when using xlsx.template |
xlsx.filename | string | "Exported Data.xlsx" | Default filename when exporting as XLSX |
xlsx.sheetName | string | "Exported Data" | Default sheet name in the exported file |
xlsx.template | string or function | If specified use @mfdc/spreadsheet-templater to format the XLSX output (see notes) | |
xlsx.templateData | function | (req, res, settings, content) => content | How to mangle the content data before its passed to @mfdc/spreadsheet-templater |
NOTES:
res.send()
/ res.json()
Express functions, EMF must be installed as a middleware before calls to those functions occur. Thus: app.get('/somwhere', emf(), (res, res) => ...)
is valid, app.get('/somwhere', (res, res) => ..., emf())
is not.key
occurs before unpack
is processedunpack
are evaluated in series, any combination of simple function return and promise return are supportedxlsx.template
is specified or if it returns a path to a valid file it the input data (post unpack
) will be passed to @mfdc/spreadsheet-templater for formatting. This allows a template XLSX file which gets passed the input dataxlsx.template
is a function it is called as (req, res, emfSettings, content)
xlsx.template
is an async function or returns a promise it will be resolved asynchronously before continuingxlsx.template
is specifiedAn object of all the supported output formats. The key is the short format name (csv
, pdf
etc.) with the key as the export of the format module.
Function used internally to take a nested object and return an flattened object in dotted notation.
Function used internally to expand dotted notation object keys into a nested object.
FAQs
ExpressJS middleware that provides alternative output formats from JSON data
The npm package @momsfriendlydevco/express-middleware-formatter receives a total of 23 weekly downloads. As such, @momsfriendlydevco/express-middleware-formatter popularity was classified as not popular.
We found that @momsfriendlydevco/express-middleware-formatter demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 5 open source maintainers 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
Tea.xyz, a crypto project aimed at rewarding open source contributions, is once again facing backlash due to an influx of spam packages flooding public package registries.
Security News
As cyber threats become more autonomous, AI-powered defenses are crucial for businesses to stay ahead of attackers who can exploit software vulnerabilities at scale.
Security News
UnitedHealth Group disclosed that the ransomware attack on Change Healthcare compromised protected health information for millions in the U.S., with estimated costs to the company expected to reach $1 billion.