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

ky

Package Overview
Dependencies
Maintainers
1
Versions
79
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

ky - npm Package Compare versions

Comparing version 1.2.4 to 1.3.0

1

distribution/core/constants.js

@@ -38,2 +38,3 @@ export const supportsRequestStreams = (() => {

parseJson: true,
stringifyJson: true,
searchParams: true,

@@ -40,0 +41,0 @@ prefixUrl: true,

2

distribution/core/Ky.js

@@ -172,3 +172,3 @@ import { HTTPError } from '../errors/HTTPError.js';

if (this._options.json !== undefined) {
this._options.body = JSON.stringify(this._options.json);
this._options.body = this._options.stringifyJson?.(this._options.json) ?? JSON.stringify(this._options.json);
this.request.headers.set('content-type', this._options.headers.get('content-type') ?? 'application/json');

@@ -175,0 +175,0 @@ this.request = new globalThis.Request(this.request, { body: this._options.body });

@@ -48,2 +48,27 @@ import type { LiteralUnion, Required } from './common.js';

/**
User-defined JSON-stringifying function.
Use-cases:
1. Stringify JSON with a custom `replacer` function.
@default JSON.stringify()
@example
```
import ky from 'ky';
import {DateTime} from 'luxon';
const json = await ky('https://example.com', {
stringifyJson: data => JSON.stringify(data, (key, value) => {
if (key.endsWith('_at')) {
return DateTime.fromISO(value).toSeconds();
}
return value;
})
}).json();
```
*/
stringifyJson?: (data: unknown) => string;
/**
Search parameters to include in the request URL. Setting this will override all existing search parameters in the input URL.

@@ -50,0 +75,0 @@

{
"name": "ky",
"version": "1.2.4",
"version": "1.3.0",
"description": "Tiny and elegant HTTP client based on the browser Fetch API",

@@ -5,0 +5,0 @@ "license": "MIT",

@@ -158,2 +158,4 @@ <div align="center">

In addition to all the [`fetch` options](https://developer.mozilla.org/en-US/docs/Web/API/fetch#options), it supports these options:
##### method

@@ -430,2 +432,27 @@

##### stringifyJson
Type: `Function`\
Default: `JSON.stringify()`
User-defined JSON-stringifying function.
Use-cases:
1. Stringify JSON with a custom `replacer` function.
```js
import ky from 'ky';
import {DateTime} from 'luxon';
const json = await ky('https://example.com', {
stringifyJson: data => JSON.stringify(data, (key, value) => {
if (key.endsWith('_at')) {
return DateTime.fromISO(value).toSeconds();
}
return value;
})
}).json();
```
##### fetch

@@ -432,0 +459,0 @@

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

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