Skip to content

mariusc23/express-query-date

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

express-query-date

Convert query strings to dates for express/connect applications.

npm build status

Installation

npm install --save express-query-date

Getting Started

The module will recursively attempt to parse every property in req.query.

Load it right after bodyParser:

var dateParser = require('express-query-date');

// [...]

app.use(bodyParser.json());
app.use(dateParser());

Without

// ?a=2015-01-01T05:00:00.000Z&b[c]=2015-01-01T05:00:00.000Z
console.log(req.query);
// => { a: '2015-01-01T05:00:00.000Z', b: { c: '2015-01-01T05:00:00.000Z' } }

With

// ?a=2015-01-01T05:00:00.000Z&b[c]=2015-01-01T05:00:00.000Z
console.log(req.query);
// => { a: Date 2015-01-01T05:00:00.000Z, b: { c: Date 2015-01-01T05:00:00.000Z } }

Formats

Default:

['x', moment.ISO_8601]

To use your own, provide them when initializing the module:

app.use(dateParser({
  formats: ['MM-DD-YYYY']
}));

See moment.js documentation for more.

Strict Mode

Strict format matching is on by default. To disable this, set options.strict to false when initializing the module.

app.use(dateParser({
  strict: false
}));

License

Copyright (c) 2015 Marius Craciunoiu. Licensed under the MIT license.

About

Convert query strings to dates for express/connect applications.

Resources

License

Stars

Watchers

Forks

Packages

No packages published