Socket
Socket
Sign inDemoInstall

mande

Package Overview
Dependencies
Maintainers
1
Versions
36
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

mande - npm Package Compare versions

Comparing version 2.0.6 to 2.0.7

10

CHANGELOG.md

@@ -0,1 +1,11 @@

## [2.0.7](https://github.com/posva/mande/compare/v2.0.6...v2.0.7) (2023-07-25)
### Bug Fixes
- **types:** specify types in package ([7678c66](https://github.com/posva/mande/commit/7678c665668263be60edb6bebc0fbd9aa50e1631)), closes [#401](https://github.com/posva/mande/issues/401)
### Features
- allow stringify option ([afd0c5e](https://github.com/posva/mande/commit/afd0c5e22fc3ac81423725b67a46e12d3541d29d)), closes [#399](https://github.com/posva/mande/issues/399) [#382](https://github.com/posva/mande/issues/382)
## [2.0.6](https://github.com/posva/mande/compare/v2.0.5...v2.0.6) (2023-02-28)

@@ -2,0 +12,0 @@

28

dist/mande.d.ts

@@ -8,3 +8,3 @@ /**

*/
export declare const defaults: Options & Pick<Required<Options>, 'headers' | 'responseAs'>;
export declare const defaults: _OptionsDefaults;

@@ -44,3 +44,3 @@ declare type InferArgs<F> = F extends (api: MandeInstance, ...args: infer A) => any ? A : never;

*/
options: Required<Pick<OptionsRaw, 'headers'>> & Pick<OptionsRaw, 'responseAs' | 'query'>;
options: Required<Pick<OptionsRaw, 'headers'>> & Omit<OptionsRaw, 'headers'>;
/**

@@ -124,5 +124,6 @@ * Sends a GET request to the given url.

/**
* Creates an Nuxt SSR compatible function that automatically proxies cookies
* to requests and works transparently on the server and client (it still
* requires a fetch polyfill on Node).
* Creates an Nuxt 2 SSR compatible function that automatically proxies cookies to requests and works transparently on
* the server and client (it still requires a fetch polyfill on Node). Note this is only needed if you need to proxy
* cookies to the server.
*
* @example

@@ -160,4 +161,21 @@ * ```js

headers?: Record<string, string>;
/**
* Optional function to stringify the body of the request for POST and PUT requests. Defaults to `JSON.stringify`.
*/
stringify?: (data: unknown) => string;
}
/**
* Used internally for merged options.
* @internal
*/
export declare type _OptionsDefaults = Options & Pick<Required<Options>, 'headers' | 'responseAs' | 'stringify'>;
/**
* Used internally for merged options
*
* @internal
*/
export declare type _OptionsMerged = _OptionsDefaults & Pick<Required<Options>, 'method'>;
export declare interface OptionsRaw<R extends ResponseAsTypes = ResponseAsTypes> extends Omit<Options<R>, 'headers' | 'signal'> {

@@ -164,0 +182,0 @@ /**

17

dist/mande.iife.js
/*!
* mande v2.0.5
* mande v2.0.6
* (c) 2023 Eduardo San Martin Morote

@@ -47,2 +47,3 @@ * @license MIT

},
stringify: JSON.stringify,
};

@@ -95,7 +96,9 @@ /**

// if (__DEV__ && query && urlInstance.search)
// TODO: use URL and URLSearchParams
url += stringifyQuery(query);
// only stringify body if it's a POST/PUT/PATCH, otherwise it could be the options object
// it's not used by GET/DELETE but it would also be wasteful
if (method[0] === 'P' && data)
mergedOptions.body = JSON.stringify(data);
if (method[0] === 'P' && data) {
mergedOptions.body = mergedOptions.stringify(data);
}
// we check the localFetch here to account for global fetch polyfills and msw in tests

@@ -123,2 +126,3 @@ const localFetch = typeof fetch != 'undefined' ? fetch : fetchPolyfill;

}
// Has better browser support and is way smaller than `class MandeError extends Error`
let err = new Error(response.statusText);

@@ -142,5 +146,6 @@ err.response = response;

/**
* Creates an Nuxt SSR compatible function that automatically proxies cookies
* to requests and works transparently on the server and client (it still
* requires a fetch polyfill on Node).
* Creates an Nuxt 2 SSR compatible function that automatically proxies cookies to requests and works transparently on
* the server and client (it still requires a fetch polyfill on Node). Note this is only needed if you need to proxy
* cookies to the server.
*
* @example

@@ -147,0 +152,0 @@ * ```js

/*!
* mande v2.0.5
* mande v2.0.6
* (c) 2023 Eduardo San Martin Morote
* @license MIT
*/
var Mande=function(e){"use strict";let t=/^\/+/;const n={responseAs:"json",headers:{Accept:"application/json","Content-Type":"application/json"}};return e.defaults=n,e.mande=function(e,s={},r){function o(s,o,i,a={}){let u,l;"object"==typeof o?(u="",a=i||o||{},l=o):(u=o,l=i);let p=Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({},n),c),{method:s}),a),{headers:(d=Object.assign(Object.assign(Object.assign({},n.headers),c.headers),a.headers),Object.keys(d).reduce(((e,t)=>(null!=d[t]&&(e[t]=d[t]),e)),{}))});var d;let b=Object.assign(Object.assign(Object.assign({},n.query),c.query),a.query),{responseAs:f}=p;u=function(e,n){return e+(n&&(e.endsWith("/")?n.replace(t,""):n.startsWith("/")?n:"/"+n))}(e,"number"==typeof u?""+u:u||""),u+=function(e){let t=Object.keys(e).map((t=>[t,e[t]].map(encodeURIComponent).join("="))).join("&");return t?"?"+t:""}(b),"P"===s[0]&&l&&(p.body=JSON.stringify(l));const j="undefined"!=typeof fetch?fetch:r;if(!j)throw new Error("No fetch function exists. Make sure to include a polyfill on Node.js.");return j(u,p).then((e=>Promise.all([e,"response"===f?e:e[f]().catch((()=>null))]))).then((([e,t])=>{if(e.status>=200&&e.status<300)return"response"!==f&&204==e.status?null:t;let n=new Error(e.statusText);throw n.response=e,n.body=t,n}))}const c=Object.assign({query:{},headers:{}},s);return{options:c,post:o.bind(null,"POST"),put:o.bind(null,"PUT"),patch:o.bind(null,"PATCH"),get:(e,t)=>o("GET",e,null,t),delete:(e,t)=>o("DELETE",e,null,t)}},e.nuxtWrap=function(e,t){const n=t.length;return function(){let s=e,r=Array.from(arguments);if(arguments.length===n){s=Object.assign({},e);const[t]=r.splice(0,1);t(s)}return t.call(null,s,...r)}},Object.defineProperty(e,"__esModule",{value:!0}),e}({});
var Mande=function(e){"use strict";let t=/^\/+/;const n={responseAs:"json",headers:{Accept:"application/json","Content-Type":"application/json"},stringify:JSON.stringify};return e.defaults=n,e.mande=function(e,s={},r){function o(s,o,c,a={}){let u,l;"object"==typeof o?(u="",a=c||o||{},l=o):(u=o,l=c);let p=Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({},n),i),{method:s}),a),{headers:(d=Object.assign(Object.assign(Object.assign({},n.headers),i.headers),a.headers),Object.keys(d).reduce(((e,t)=>(null!=d[t]&&(e[t]=d[t]),e)),{}))});var d;let f=Object.assign(Object.assign(Object.assign({},n.query),i.query),a.query),{responseAs:b}=p;u=function(e,n){return e+(n&&(e.endsWith("/")?n.replace(t,""):n.startsWith("/")?n:"/"+n))}(e,"number"==typeof u?""+u:u||""),u+=function(e){let t=Object.keys(e).map((t=>[t,e[t]].map(encodeURIComponent).join("="))).join("&");return t?"?"+t:""}(f),"P"===s[0]&&l&&(p.body=p.stringify(l));const j="undefined"!=typeof fetch?fetch:r;if(!j)throw new Error("No fetch function exists. Make sure to include a polyfill on Node.js.");return j(u,p).then((e=>Promise.all([e,"response"===b?e:e[b]().catch((()=>null))]))).then((([e,t])=>{if(e.status>=200&&e.status<300)return"response"!==b&&204==e.status?null:t;let n=new Error(e.statusText);throw n.response=e,n.body=t,n}))}const i=Object.assign({query:{},headers:{}},s);return{options:i,post:o.bind(null,"POST"),put:o.bind(null,"PUT"),patch:o.bind(null,"PATCH"),get:(e,t)=>o("GET",e,null,t),delete:(e,t)=>o("DELETE",e,null,t)}},e.nuxtWrap=function(e,t){const n=t.length;return function(){let s=e,r=Array.from(arguments);if(arguments.length===n){s=Object.assign({},e);const[t]=r.splice(0,1);t(s)}return t.call(null,s,...r)}},Object.defineProperty(e,"__esModule",{value:!0}),e}({});
{
"name": "mande",
"version": "2.0.6",
"description": "Some awesome description",
"packageManager": "pnpm@7.28.0",
"version": "2.0.7",
"description": "800 bytes modern wrapper around fetch with smart defaults",
"packageManager": "pnpm@8.6.10",
"main": "index.js",

@@ -14,2 +14,3 @@ "module": "dist/mande.mjs",

".": {
"types": "./dist/mande.d.ts",
"node": {

@@ -80,17 +81,17 @@ "import": {

"devDependencies": {
"@microsoft/api-documenter": "^7.21.5",
"@microsoft/api-extractor": "^7.34.4",
"@nuxt/types": "^2.16.0",
"@rollup/plugin-alias": "^4.0.3",
"@microsoft/api-documenter": "^7.22.30",
"@microsoft/api-extractor": "^7.36.3",
"@nuxt/types": "^2.17.1",
"@rollup/plugin-alias": "^4.0.4",
"@rollup/plugin-replace": "^5.0.2",
"@size-limit/preset-small-lib": "^8.2.4",
"@types/jest": "^29.4.0",
"@size-limit/preset-small-lib": "^8.2.6",
"@types/jest": "^29.5.3",
"codecov": "^3.8.3",
"conventional-changelog-cli": "^2.2.2",
"fetch-mock-jest": "^1.5.1",
"jest": "^29.4.3",
"node-fetch": "^2.6.9",
"jest": "^29.6.1",
"node-fetch": "^2.6.12",
"pascalcase": "^1.0.0",
"prettier": "^2.8.4",
"rimraf": "^4.1.2",
"prettier": "^2.8.8",
"rimraf": "^5.0.1",
"rollup": "^2.79.1",

@@ -100,6 +101,6 @@ "rollup-plugin-commonjs": "^10.1.0",

"rollup-plugin-terser": "^7.0.2",
"rollup-plugin-typescript2": "^0.34.1",
"size-limit": "^8.2.4",
"ts-jest": "^29.0.5",
"typescript": "^4.9.5"
"rollup-plugin-typescript2": "^0.35.0",
"size-limit": "^8.2.6",
"ts-jest": "^29.1.1",
"typescript": "^5.1.6"
},

@@ -106,0 +107,0 @@ "repository": {

@@ -1,2 +0,2 @@

# mande [![Build Status](https://badgen.net/circleci/github/posva/mande/master)](https://circleci.com/gh/posva/mande) [![npm package](https://badgen.net/npm/v/mande)](https://www.npmjs.com/package/mande) [![coverage](https://badgen.net/codecov/c/github/posva/mande/master)](https://codecov.io/github/posva/mande) [![thanks](https://badgen.net/badge/thanks/♥/pink)](https://github.com/posva/thanks)
# mande [![build status](https://github.com/posva/mande/workflows/test/badge.svg?branch=main)](https://github.com/posva/mande/actions/workflows/test.yml?query=branch%3Amain) [![npm package](https://badgen.net/npm/v/mande)](https://www.npmjs.com/package/mande) [![coverage](https://badgen.net/codecov/c/github/posva/mande/master)](https://codecov.io/github/posva/mande) [![thanks](https://badgen.net/badge/thanks/♥/pink)](https://github.com/posva/thanks)

@@ -120,5 +120,7 @@ > Simple, light and extensible wrapper around fetch with smart defaults

todos.get<{ text: string, id: number, isFinished: boolean }[]>().then(todos => {
// todos is correctly typed
})
todos
.get<{ text: string; id: number; isFinished: boolean }[]>()
.then((todos) => {
// todos is correctly typed
})
```

@@ -181,2 +183,14 @@

### Cookbook
#### Timeout
You can timeout requests by using the native `AbortSignal`:
```ts
mande('/api').get('/users', { signal: AbortSignal.timeout(200) })
```
This is supported by [all modern browsers](https://developer.mozilla.org/en-US/docs/Web/API/AbortSignal/timeout_static).
## Related

@@ -183,0 +197,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

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