GithubHelp home page GithubHelp logo

418sec / node-sanitize Goto Github PK

View Code? Open in Web Editor NEW

This project forked from pocketly/node-sanitize

0.0 2.0 3.0 35 KB

Input sanitizing library for node.js

License: ISC License

Makefile 0.62% JavaScript 99.38%

node-sanitize's Introduction

node-sanitize

Input sanitizing library for node.js

Summary

This library is for the purpose of sanitizing user input. The examples below show some of the built in sanitizers. You can create your own custom sanitizers. Please refer to the tests for more examples of how to use this library.

Install

npm install --save sanitize

Test

npm test

Usage

var express = require('express');
var app = express();
app.use(require('sanitize').middleware);
app.get('/ping', function(req, res) {
	var param = req.queryInt('param');
	res.send('pong ' + (typeof param) + ' ' + param);
});
app.listen(8080);

Documentation

Sanitize Objects

sanitize.primitives(obj: PlainObject): PlainObject

This will remove all keys from a plain object that are not String, Integer, or Boolean. It's great for sanitizing objects before inserting into the database.

Express Middleware

req.headerInt(headerName: String): Integer

req.headerString(headerName: String): String

req.headerFloat(headerName: String): Float

req.headerEmail(headerName: String): String

req.headerPattern(headerName: String, pattern: RegExp): String

req.headerOneOf(headerName: String, arr: Array): String

req.bodyInt(bodyParam: String): Integer

req.bodyString(bodyParam: String): String

req.bodyFloat(bodyParam: String): Float

req.bodyEmail(bodyParam: String): String

req.bodyPattern(bodyParam: String, pattern: RegExp): String

req.bodyOneOf(bodyName: String, arr: Array): String

req.queryInt(queryParam: String): Integer

req.queryString(queryParam: String): String

req.queryFloat(queryParam: String): Float

req.queryEmail(queryParam: String): String

req.queryPattern(queryParam: String, pattern: RegExp): String

req.queryOneOf(queryName: String, arr: Array): String

req.paramInt(paramName: String): Integer

req.paramString(paramName: String): String

req.paramFloat(paramName: String): Float

req.paramEmail(paramName: String): String

req.paramPattern(paramName: String, pattern: RegExp): String

req.paramOneOf(paramName: String, arr: Array): String

node-sanitize's People

Contributors

janghwan avatar adamjaso avatar jlee-sazze avatar pmarrapese avatar philwaters avatar sonylnagale avatar

Watchers

James Cloos avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.