Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

raml-sanitize

Package Overview
Dependencies
Maintainers
2
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

  • 1.3.4
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
904
decreased by-28.48%
Maintainers
2
Weekly downloads
 
Created
Source

RAML Sanitize

NPM version Build status Test coverage Greenkeeper badge

Strict sanitization of RAML 0.8 named parameters and RAML 1.0 built-in types.

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',
    default: new Date()
  }
});

user({
  username: 'blakeembrey',
  password: 'hunter2'
});
// => { username: 'blakeembrey', password: 'hunter2', birthday: new Date() }

Module does not currently support wild-card parameters (RAML 0.8) and regular expression patterns in property declaration (RAML 1.0)

Type sanitization

The module comes with built-in type sanitization of string, number, integer, array, object, 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. A few core rules are implemented by default and can not be overriden - repeat, default and type.

Empty values

Empty values are automatically allowed to pass through sanitization. The only values considered to be empty are undefined and null.

Default values

When the value is empty and a default value has been provided, it will return the default value instead.

Repeated values (RAML 0.8)

When the repeat flag is set to true, the return value will be an array. If the value is not an array, it will be wrapped in an array. If the value is empty, an empty array will be returned.

Caveats

Limitations with types (RAML 1.0)

The module does not support neither Type Expressions nor Union Type.

Invalid Sanitization

If a sanitization is invalid, the original value will be returned instead.

Booleans

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

License

Apache 2.0

Keywords

FAQs

Package last updated on 17 May 2019

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