New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

custom-fields-middleware

Package Overview
Dependencies
Maintainers
1
Versions
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

custom-fields-middleware

Add custom fields to the response

  • 1.0.8
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
0
decreased by-100%
Maintainers
1
Weekly downloads
 
Created
Source

Custom Fields Middleware Build Status

Adds and transforms custom fields on the response

Usage

In Express, pass the middleware to app.use before the router

app.use(require('custom-fields-middleware'));

Assign a model to customfields from anywhere in your app


res.customfields = {
  id: 'foo',
  value: 'bar'
};

Assign a collection

res.customfields = [{id: 'foo', value: 'bar'}, {id: 'bar', value: 'bar'}];

Read the value(s)

res.customfields.foo // 'bar'
res.customfields.bar // 'baz'

Params

  • id: {String} required. The name of the value.
  • value: {*} required. The value to be assigned to the id.
  • transforms: {Array|String|Function} options. A function or list of functions to transforms the value.

Transforms

A transform is a function that takes two arguments, the value and the request object.


var square (value, req) => value * value;

res.customfields = {
  id: 'foo',
  value: 'bar',
  transforms: [square]
};

Built-in transforms include:

  • baseurl: prepends the value with req.baseUrl

Use a built-in transform by passing the name to the transforms field.

res.customfields = {
  id: 'foo',
  value: 'bar',
  transforms: ['baseurl']
};

Install

$ npm install custom-fields-middleware --save

Scripts

$ npm test
$ npm lint

Keywords

FAQs

Package last updated on 02 Feb 2016

Did you know?

Socket

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.

Install

Related posts

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