Registry / devops / axios-add-transforms

axios-add-transforms

JSON →
library0.4.15jsnpmunverified

A utility library for Axios that provides a declarative way to add request/response/error transforms to Axios instances. Version 0.4.15 (latest) is stable with infrequent releases. It allows defining matchers based on URL patterns and HTTP methods to apply custom transformation functions to request data, response data, and error handling, including retry logic. Ships TypeScript types. Differentiates from plain interceptors by offering a pattern-based configuration approach.

npm install axios-add-transforms
INSTALL
IMPORT
SIG · AXIOS-ADD-TRANSFOR
A
axios-add-transforms
devopsjavascriptv0.4.15
harness data pending
Install & Compatibility
Where this runs

No compatibility data collected yet for this library.

Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

default
import Transforms from 'axios-add-transforms'
const Transforms = require('axios-add-transforms')
The package uses CommonJS internally but can be imported as default in ES modules. The default export is the Transforms class. In TypeScript, you may need to use `import Transforms from 'axios-add-transforms'` with esModuleInterop enabled.
TransformsOptions
import type { TransformsOptions } from 'axios-add-transforms'
import { TransformsOptions } from 'axios-add-transforms' (transpiles but unused at runtime)
Type-only import to avoid emitting import at runtime. Available since v0.3.0.
MatcherConfig
import type { MatcherConfig } from 'axios-add-transforms'
Exported interface for matcher configuration; use type import for TypeScript.

Demonstrates creating a Transforms instance with a matcher that modifies request data for URLs matching /^\/users\/?$/, applying the transform to an Axios instance, and making a request.

import Transforms from 'axios-add-transforms'; import axios from 'axios'; const myAxios = axios.create({}); const transforms = new Transforms({ context: () => ({ axios: myAxios }), matchers: [ { test: /^\/users\/?$/, transform: { request: ({ data, params, headers }) => ({ data: { _foo: data.foo, _bar: data.bar }, params, headers, }), }, }, ], }); transforms.applyTransform(myAxios); myAxios({ url: '/users/', data: { foo: 'foo', bar: 'bar' }, }).then(() => { console.log('Request transformed'); });
Debug
Known issues
gotchaThe `test` property in matchers is evaluated against the URL string; make sure your regex does not match unexpected URLs.
fix
Use anchored regex patterns (e.g., /^\/users\/?$/) to avoid matching substrings.
affects: >=0.1.0
deprecatedThe `addInterceptors` method on Transforms instances is deprecated. Use `applyTransform` instead.
fix
Replace `transforms.addInterceptors(axiosInstance)` with `transforms.applyTransform(axiosInstance)`.
affects: >=0.3.0
gotchaThe `context` property in TransformsOptions is a factory function that must return an object; the factory may be called multiple times.
fix
Ensure the factory returns a stable object to avoid recreation of context resources.
affects: >=0.1.0
breakingIn v0.4.0, the default export changed from a function to a class. Code using `import Transforms from 'axios-add-transforms'` as a function will break.
fix
Update to use `new Transforms()` constructor. For older code, import the class constructor and instantiate.
affects: <0.4.0
Errors
Common errors & fixes
TypeError: Transforms is not a constructor
Importing the package as a class but using it without `new` in versions prior to 0.4.0 or mismatched import style.
fix
Use the correct import for v0.4.0+: `import Transforms from 'axios-add-transforms'` and then `new Transforms({...})`.
Cannot find module 'axios-add-transforms' or its corresponding type declarations
TypeScript not configured to resolve type definitions for the package.
fix
Ensure `node_modules` types are included in tsconfig.json (`"types": ["node", "axios-add-transforms"]`) and that `esModuleInterop` is enabled.
Upgrade
Version history
0.4.15latest on npm
Audit
Dependencies
axiosrequiredPeer dependency; library works as a plugin for Axios.
Agent activity
12 hits · last 30 days
node
10
OpenAI (training)
1
Resources
axios-add-transforms — npm install axios-add-transforms · libregistry