New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

quick-res

Package Overview
Dependencies
Maintainers
1
Versions
11
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

quick-res

A set of small utilities that makes Response. q.json(), q.text(), q.html(), .... can make your code shorter and more readable while also providing good support for Tree-Shaking.

  • 0.0.11
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
7.2K
decreased by-13.23%
Maintainers
1
Weekly downloads
 
Created
Source

quick-res

🚀 A set of small utilities that makes Response. q.json(), q.text(), q.html(), .... can make your code shorter and more readable while also providing good support for Tree-Shaking.

npm install quick-res
  • Works fine with any kinds of worker that supports Web Standard API.
  • Supports both CommonJS and ESM.
  • Small! Only 922 bytes (ESM). See screenshot.

Usage

Cloudflare workers example:

import * as quick from 'quick-res';

export default {
  async fetch(req: Request): Promise<Response> {
    const u = new URL(req.url);

    if (u.pathname === '/check') {
      const version = u.searchParams.get('version');
      if (!version) {
        return quick.text('Invalid', 400);
      }
      return quick.json({ version });
    }

    return quick.notFound();
  },
};

Tree-Shaking

Tree-Shaking is enabled by default. Your bundler should only include functions that you use.

API

text(string, status?, headers?)
text(string, responseInit?)

Responds as text/plain.

html(string, status?, headers?)
html(string, responseInit?)

Responds as text/html.

json(object, status?, headers?)
json(object, responseInit?)

Responds as application/json. object will be automatically converted to JSON using JSON.stringify.

resp(bodyInit, status?, headers?)
resp(bodyInit, responseInit?)

Responds stream or whatever you want.

notFound()
redirect

Not included. Use Response.redirect instead.

Create your own utilities

import * as quick from 'quick-res';

export function forbidden() {
  return quick.text('Forbidden', 403);
}

export function badRequest(info: unknown) {
  return quick.json(info, 400);
}

export function internalError(error: Error) {
  return quick.text(error.message, 500);
}

Screenshot

Only 922 bytes (ESM)

small code

LICENSE

New BSD License ©Ninh Pham - ReeganExE

Keywords

FAQs

Package last updated on 25 Sep 2023

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc