@vercel/edge
Advanced tools
Comparing version 0.1.2 to 0.2.0
@@ -189,2 +189,31 @@ interface ModifiedRequest { | ||
export { CITY_HEADER_NAME, COUNTRY_HEADER_NAME, ExtraResponseInit, Geo, IP_HEADER_NAME, LATITUDE_HEADER_NAME, LONGITUDE_HEADER_NAME, ModifiedRequest, REGION_HEADER_NAME, REQUEST_ID_HEADER_NAME, geolocation, ipAddress, next, rewrite }; | ||
/** | ||
* Builds a response object from a serializable JavaScript object: | ||
* - sets the 'Content-Type' response header to 'application/json' | ||
* - sets the response body from provided data | ||
* | ||
* @see {@link https://fetch.spec.whatwg.org/#dom-response-json} | ||
* @param data serialized data | ||
* @param init optional custom response status, statusText and headers | ||
* | ||
* @example | ||
* <caption>Building a JSON response</caption> | ||
* | ||
* ```ts | ||
* import { json } from '@vercel/edge'; | ||
* | ||
* const response = json({ notification: { success: true, content: 'worked' } }, { headers: {'x-custom': '1' }}) | ||
* ``` | ||
*/ | ||
declare function json(data: any, init?: ResponseInit): Response; | ||
/* eslint-disable no-var */ | ||
declare global { | ||
// must be `var` to work | ||
var process: { | ||
env: Record<string, string>; | ||
}; | ||
} | ||
export { CITY_HEADER_NAME, COUNTRY_HEADER_NAME, ExtraResponseInit, Geo, IP_HEADER_NAME, LATITUDE_HEADER_NAME, LONGITUDE_HEADER_NAME, ModifiedRequest, REGION_HEADER_NAME, REQUEST_ID_HEADER_NAME, geolocation, ipAddress, json, next, rewrite }; |
@@ -32,2 +32,3 @@ "use strict"; | ||
ipAddress: () => ipAddress, | ||
json: () => json, | ||
next: () => next, | ||
@@ -102,2 +103,7 @@ rewrite: () => rewrite | ||
} | ||
// src/response.ts | ||
function json(data, init) { | ||
return Response.json(data, init); | ||
} | ||
// Annotate the CommonJS export names for ESM import in node: | ||
@@ -114,4 +120,5 @@ 0 && (module.exports = { | ||
ipAddress, | ||
json, | ||
next, | ||
rewrite | ||
}); |
@@ -25,2 +25,3 @@ # @vercel/edge | ||
- [ipAddress](README.md#ipaddress) | ||
- [json](README.md#json) | ||
- [next](README.md#next) | ||
@@ -173,2 +174,45 @@ - [rewrite](README.md#rewrite) | ||
### json | ||
▸ **json**(`data`, `init?`): `Response` | ||
Builds a response object from a serializable JavaScript object: | ||
- sets the 'Content-Type' response header to 'application/json' | ||
- sets the response body from provided data | ||
**`See`** | ||
[https://fetch.spec.whatwg.org/#dom-response-json](https://fetch.spec.whatwg.org/#dom-response-json) | ||
**`Example`** | ||
<caption>Building a JSON response</caption> | ||
```ts | ||
import { json } from '@vercel/edge'; | ||
const response = json( | ||
{ notification: { success: true, content: 'worked' } }, | ||
{ headers: { 'x-custom': '1' } } | ||
); | ||
``` | ||
#### Parameters | ||
| Name | Type | Description | | ||
| :------ | :------------- | :------------------------------------------------------ | | ||
| `data` | `any` | serialized data | | ||
| `init?` | `ResponseInit` | optional custom response status, statusText and headers | | ||
#### Returns | ||
`Response` | ||
#### Defined in | ||
[src/response.ts:19](https://github.com/vercel/vercel/blob/main/packages/edge/src/response.ts#L19) | ||
--- | ||
### next | ||
@@ -175,0 +219,0 @@ |
{ | ||
"name": "@vercel/edge", | ||
"version": "0.1.2", | ||
"version": "0.2.0", | ||
"license": "MIT", | ||
@@ -34,3 +34,3 @@ "main": "dist/index.js", | ||
}, | ||
"gitHead": "8d2c0fec89b34c98e0a6123516d54407fc1cb738" | ||
"gitHead": "5ae7c2f4525a675dc0b24aeecc878096cf4ce2b2" | ||
} |
@@ -6,1 +6,4 @@ export type { ExtraResponseInit } from './middleware-helpers'; | ||
export * from './edge-headers'; | ||
export * from './response'; | ||
import './published-types.d.ts'; |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
55338
22
972