Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

typescript-fetch

Package Overview
Dependencies
Maintainers
1
Versions
4
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

typescript-fetch - npm Package Compare versions

Comparing version 0.0.2 to 0.0.3

6

CHANGELOG.md
# typescript-fetch
## 0.0.3
### Patch Changes
- [`6b7bc10`](https://github.com/jacob-ebey/typescript-fetch/commit/6b7bc101b17e606b2ba01775e2444e07807c781f) Thanks [@jacob-ebey](https://github.com/jacob-ebey)! - add `json()` helper
## 0.0.2

@@ -4,0 +10,0 @@

@@ -7,1 +7,8 @@ export function typeRequest(input, init) {

}
export function json(data, init) {
init = (typeof init === "number" ? { status: init } : init) || {};
const headers = new Headers(init?.headers);
init.headers = headers;
headers.set("Content-Type", "application/json");
return new Response(JSON.stringify(data), init);
}

@@ -0,1 +1,3 @@

import { Jsonifiable, Jsonify } from "type-fest";
export type RequestMethod =

@@ -116,1 +118,32 @@ | "GET"

}
export interface TypedResponseInit<Status extends number>
extends globalThis.ResponseInit {
status?: Status;
}
export function json<Data extends Jsonifiable, Status extends number>(
data: Data,
init: Status
): TypedResponseJSON<Status, Jsonify<Data>>;
export function json<Data extends Jsonifiable, Status extends number>(
data: Data,
init: TypedResponseInit<Status>
): TypedResponseJSON<Status, Jsonify<Data>>;
export function json<Data extends Jsonifiable, Status extends 200>(
data: Data,
init?: never
): TypedResponseJSON<Status, Jsonify<Data>>;
export function json<Data extends Jsonifiable, Status extends number>(
data: Data,
init?: globalThis.ResponseInit | Status
): TypedResponseJSON<Status, Jsonify<Data>> {
init = (typeof init === "number" ? { status: init } : init) || {};
const headers = new Headers(init?.headers);
init.headers = headers;
headers.set("Content-Type", "application/json");
return new Response(JSON.stringify(data), init) as TypedResponseJSON<
Status,
Jsonify<Data>
>;
}

5

package.json
{
"name": "typescript-fetch",
"version": "0.0.2",
"version": "0.0.3",
"main": "dist/index.js",

@@ -9,2 +9,5 @@ "types": "dist/index.d.ts",

},
"dependencies": {
"type-fest": "^3.3.0"
},
"devDependencies": {

@@ -11,0 +14,0 @@ "typescript": "^4.9.3"

.turbo/turbo-build.log

Sorry, the diff of this file is not supported yet

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