@polka/parse
Advanced tools
Comparing version 1.0.0-next.1 to 1.0.0-next.3
28
index.js
@@ -1,6 +0,6 @@ | ||
const { parse } = require('querystring'); | ||
const { decode } = require('querystring'); | ||
const noop = x => x; | ||
exports.parse = function (opts={}) { | ||
function parse(opts={}) { | ||
const { type, encoding='utf-8', parser=noop } = opts; | ||
@@ -52,23 +52,29 @@ const limit = opts.limit || 100 * 1024; // 100kb | ||
exports.json = function (opts={}) { | ||
function json(opts={}) { | ||
const { limit, parser=JSON.parse } = opts; | ||
const type = opts.type || 'application/json'; | ||
return exports.parse({ type, parser, limit }); | ||
return parse({ type, parser, limit }); | ||
} | ||
exports.urlencoded = function (opts={}) { | ||
const { parser=parse, limit } = opts; | ||
function urlencoded(opts={}) { | ||
const { parser=decode, limit } = opts; | ||
const type = opts.type || 'application/x-www-form-urlencoded'; | ||
return exports.parse({ type, parser, limit }); | ||
return parse({ type, parser, limit }); | ||
} | ||
exports.raw = function (opts={}) { | ||
function raw(opts={}) { | ||
const { limit, encoding=null } = opts; | ||
const type = opts.type || 'application/octet-stream'; | ||
return exports.parse({ limit, type, encoding }); | ||
return parse({ limit, type, encoding }); | ||
} | ||
exports.text = function (opts={}) { | ||
function text(opts={}) { | ||
const { limit, type='text/plain' } = opts; | ||
return exports.parse({ limit, type }); | ||
return parse({ limit, type }); | ||
} | ||
exports.json = json; | ||
exports.parse = parse; | ||
exports.raw = raw; | ||
exports.text = text; | ||
exports.urlencoded = urlencoded; |
{ | ||
"version": "1.0.0-next.1", | ||
"version": "1.0.0-next.3", | ||
"name": "@polka/parse", | ||
"repository": "lukeed/polka", | ||
"description": "WIP", | ||
"module": "index.mjs", | ||
"main": "index.js", | ||
"license": "MIT", | ||
"files": [ | ||
"*.js" | ||
"*.js", | ||
"*.mjs" | ||
], | ||
@@ -18,3 +21,3 @@ "author": { | ||
}, | ||
"gitHead": "8d32406bd3fa924b648df3e67ed32da502293904" | ||
"gitHead": "602086f1f4f1a6103e0589b04b69f8b4d934f0fc" | ||
} |
5309
4
128