body-parsec
Advanced tools
Comparing version 2.0.20 to 2.1.0
@@ -12,4 +12,4 @@ /// <reference types="node" /> | ||
declare const text: () => (req: ReqWithBody, _res?: ServerResponse, next?: () => void) => Promise<void>; | ||
declare const form: () => (req: ReqWithBody, _res?: ServerResponse, next?: () => void) => Promise<void>; | ||
declare const urlencoded: () => (req: ReqWithBody, _res?: ServerResponse, next?: () => void) => Promise<void>; | ||
export { ReqWithBody, parsec as custom, form, json, raw, text }; | ||
export { ReqWithBody, parsec as custom, json, raw, text, urlencoded }; |
@@ -1,1 +0,1 @@ | ||
import{form,json,parsec,raw,text}from"./chunk.eERFDqZM.js";export{parsec as custom,form,json,raw,text}; | ||
import{json,parsec,raw,text,urlencoded}from"./chunk.VMHT7XW4.js";export{parsec as custom,json,raw,text,urlencoded}; |
@@ -14,4 +14,4 @@ /// <reference types="node" /> | ||
declare const text: () => (ctx: CtxWithBody, next?: Next) => Promise<void>; | ||
declare const form: () => (ctx: CtxWithBody, next?: Next) => Promise<void>; | ||
declare const urlencoded: () => (ctx: CtxWithBody, next?: Next) => Promise<void>; | ||
export { CtxWithBody, custom, form, json, raw, text }; | ||
export { CtxWithBody, custom, json, raw, text, urlencoded }; |
@@ -1,1 +0,1 @@ | ||
import{parsec}from"./chunk.eERFDqZM.js";import{parse}from"querystring";const custom=(fn=body=>body)=>async(ctx,next)=>{await parsec(fn)(ctx.req,ctx.res);next==null?void 0:next()};const json=()=>async(ctx,next)=>{await custom(x=>JSON.parse(x.toString()))(ctx);next==null?void 0:next()};const raw=()=>async(ctx,next)=>{await custom(x=>x)(ctx);next==null?void 0:next()};const text=()=>async(ctx,next)=>{await custom(x=>x.toString())(ctx);next==null?void 0:next()};const form=()=>async(ctx,next)=>{await custom(x=>parse(x.toString()))(ctx);next==null?void 0:next()};export{custom,form,json,raw,text}; | ||
import{parsec}from"./chunk.VMHT7XW4.js";import{parse}from"querystring";const custom=(fn=body=>body)=>async(ctx,next)=>{await parsec(fn)(ctx.req,ctx.res);next==null?void 0:next()};const json=()=>async(ctx,next)=>{await custom(x=>JSON.parse(x.toString()))(ctx);next==null?void 0:next()};const raw=()=>async(ctx,next)=>{await custom(x=>x)(ctx);next==null?void 0:next()};const text=()=>async(ctx,next)=>{await custom(x=>x.toString())(ctx);next==null?void 0:next()};const urlencoded=()=>async(ctx,next)=>{await custom(x=>parse(x.toString()))(ctx);next==null?void 0:next()};export{custom,json,raw,text,urlencoded}; |
{ | ||
"name": "body-parsec", | ||
"version": "2.0.20", | ||
"version": "2.1.0", | ||
"repository": "https://github.com/talentlessguy/parsec.git", | ||
@@ -27,15 +27,15 @@ "author": "talentlessguy <pilll.PL22@gmail.com>", | ||
"devDependencies": { | ||
"@tinyhttp/app": "^0.2.41", | ||
"@tinyhttp/app": "^0.2.62", | ||
"@types/express": "^4.17.7", | ||
"@types/jest": "^26.0.9", | ||
"@types/koa": "^2.11.3", | ||
"@types/node": "^14.0.27", | ||
"@types/jest": "^26.0.10", | ||
"@types/koa": "^2.11.4", | ||
"@types/node": "^14.6.2", | ||
"@types/supertest": "^2.0.10", | ||
"express": "^4.17.1", | ||
"jest": "^26.3.0", | ||
"jest": "^26.4.2", | ||
"koa": "^2.12.0", | ||
"supertest": "^4.0.2", | ||
"ts-jest": "^26.2.0", | ||
"tsup": "^3.4.2", | ||
"typescript": "^3.9.7" | ||
"ts-jest": "^26.3.0", | ||
"tsup": "^3.6.1", | ||
"typescript": "^4.0.2" | ||
}, | ||
@@ -53,4 +53,4 @@ "files": [ | ||
"express": "^4.17.1", | ||
"koa": "^2.13.0" | ||
"koa": "^2.12.0" | ||
} | ||
} |
@@ -10,3 +10,3 @@ # parsec 🌌 | ||
Modern asynchronous body parser for Node.js. | ||
Tiniest body parser ever for Node.js. | ||
@@ -21,4 +21,4 @@ It puts all the data into `req.body` so you don't have to create a separate array for it. | ||
- built with `async` / `await` ⏩ | ||
- JSON / raw / form / text data support 🛠 | ||
- tiny package size (796 b) 📦 | ||
- JSON / raw / urlencoded / text data support 🛠 | ||
- tiny package size (879B) 📦 | ||
- no dependencies 🔥 | ||
@@ -48,3 +48,3 @@ - [tinyhttp](https://github.com/talentlessguy/tinyhttp), Koa and Express support | ||
import { createServer } = from 'http' | ||
import { josn } from 'body-parsec' | ||
import { json } from 'body-parsec' | ||
@@ -73,7 +73,7 @@ createServer(async (req, res) => { | ||
import { App } from '@tinyhttp/app' | ||
import { form } from 'body-parsec' | ||
import { urlencoded } from 'body-parsec' | ||
const app = new App() | ||
app.use(form()).post('/', (req, res) => { | ||
app.use(urlencoded()).post('/', (req, res) => { | ||
res.send(req.body) | ||
@@ -89,13 +89,13 @@ }) | ||
import Express from 'express' | ||
import { form } from 'body-parsec' | ||
import { urlencoded } from 'body-parsec' | ||
const app = Express() | ||
app.use(form()) | ||
app.use(urlencoded()) | ||
app.get('/', (req, res) => { | ||
res.send(` | ||
<form method="POST" action="/"> | ||
<urlencoded method="POST" action="/"> | ||
<input name="name" /> | ||
</form> | ||
</urlencoded> | ||
`) | ||
@@ -135,3 +135,3 @@ }) | ||
Minimal body parsing without any formatting (even without converting to string): | ||
Minimal body parsing without any urlencodedatting (even without converting to string): | ||
@@ -156,3 +156,3 @@ ```js | ||
You can use `parsec` as a a handler for `IncomingMessage` with a custom formatter. | ||
You can use `parsec` as a a handler for `IncomingMessage` with a custom urlencodedatter. | ||
@@ -177,3 +177,3 @@ Here we make a request body upper case: | ||
#### `parsec.form(req)` | ||
#### `parsec.urlencoded(req)` | ||
@@ -184,3 +184,3 @@ Parses request body using `querystring.parse`. | ||
// Request: curl -d 'username=pro_gamer' | ||
await parsec.form()(req) | ||
await parsec.urlencoded()(req) | ||
res.end(req.body.username) // pro_gamer | ||
@@ -187,0 +187,0 @@ ``` |
@@ -39,3 +39,3 @@ import { ServerResponse as Response, IncomingMessage } from 'http' | ||
const form = () => async (req: ReqWithBody, _res?: Response, next?: () => void) => { | ||
const urlencoded = () => async (req: ReqWithBody, _res?: Response, next?: () => void) => { | ||
await parsec((x) => qs.parse(x.toString()))(req, _res) | ||
@@ -45,2 +45,2 @@ next?.() | ||
export { parsec as custom, json, raw, text, form } | ||
export { parsec as custom, json, raw, text, urlencoded } |
@@ -32,3 +32,3 @@ import * as parsec from './index' | ||
const form = () => async (ctx: CtxWithBody, next?: Next) => { | ||
const urlencoded = () => async (ctx: CtxWithBody, next?: Next) => { | ||
await custom((x) => qs.parse(x.toString()))(ctx) | ||
@@ -38,2 +38,2 @@ next?.() | ||
export { custom, json, raw, text, form } | ||
export { custom, json, raw, text, urlencoded } |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Minified code
QualityThis package contains minified code. This may be harmless in some cases where minified code is included in packaged libraries, however packages on npm should not minify code.
Found 1 instance in 1 package
25379
27
212
8