UNPKG

tastypie

Version:

Tastypie is a webservice API framework for Node.js based on Django's Tastypie Framework. It provides a convenient, yet powerful and highly customizable, abstraction for creating REST-style interfaces

16 lines (12 loc) 516 B
var typecast = require('../string/typecast'); var getQuery = require('./getQuery'); /** * Get query parameter value. */ function getParam(url, param, shouldTypecast){ var regexp = new RegExp('(\\?|&)'+ param + '=([^&]*)'), //matches `?param=value` or `&param=value`, value = $2 result = regexp.exec( getQuery(url) ), val = (result && result[2])? result[2] : null; return shouldTypecast === false? val : typecast(val); } module.exports = getParam;