Socket
Socket
Sign inDemoInstall

raml-sanitize

Package Overview
Dependencies
Maintainers
1
Versions
22
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

raml-sanitize

Sanitization of RAML parameters into strict values


Version published
Weekly downloads
1.3K
decreased by-18.63%
Maintainers
1
Weekly downloads
 
Created
Source

RAML Sanitize

Strict sanitization of RAML parameters into correct values and types. Allows for types to be plugged in dynamically.

Why?

This module sanitizes values using the RAML parameter syntax. You should use this if you need to convert any request parameters (usually strings) into the corresponding JavaScript types. For example, form request bodies, query parameters and headers all have no concept of types. After running sanitization, you can use raml-validate to validate the strict values.

Installation

npm install raml-sanitize --save

Usage

The module exports a function that needs to be invoked to get a sanitization instance.

var sanitize = require('raml-sanitize')();

var user = sanitize({
  username: {
    type: 'string'
  },
  password: {
    type: 'string'
  },
  birthday: {
    type: 'date'
  },

});

user({
  username: 'blakeembrey',
  password: 'hunter2',
  birthday: 'Mon, 23 Jun 2014 01:19:34 GMT'
});
// => { username: 'blakeembrey', password: 'hunter2', birthday: new Date() }

Type sanitization

The module comes with built-in type sanitization of all RAML parameters - string, number, integer, date and boolean. To add a new type sanitization, add a new property with the corresponding name to the sanitize.TYPES object.

Rule sanitization

The module can be extended with rule sanitization by adding properties to the sanitize.RULES object.

Caveats

Empty Values

Any empty values (null and undefined) will be returned.

Numbers

Only valid JavaScript numbers will be correctly sanitized. Any invalid or infinite number will return NaN.

Integers

Only valid integers and valid JavaScript numbers will sanitize. Any invalid integer or infinite number will return NaN.

Booleans

Only false, 0, "false", "0" and "" will return false. Everything else is considered true.

Dates

Date sanitization will always return a date object. In the case of an invalid date, you will receive an invalid date object.

License

MIT

Keywords

FAQs

Package last updated on 23 Jun 2014

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