Registry / storage / axios-date-transformer

axios-date-transformer

JSON →
library1.2.1jsnpmunverified

Automatically converts ISO 8601 date strings (with millisecond precision) in Axios JSON response data to JavaScript Date objects. v1.2.1 is current. Lightweight, TypeScript-first, no external dependencies beyond Axios. Releases appear infrequent but stable. Key differentiator: simple drop-in transformer for Axios instances vs manual parsing or full-date-lib overhead.

npm install axios-date-transformer
INSTALL
IMPORT
SIG · AXIOS-DATE-TRANSFO
A
axios-date-transformer
storagejavascriptv1.2.1
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.

createAxiosDateTransformer
import { createAxiosDateTransformer } from 'axios-date-transformer'
const createAxiosDateTransformer = require('axios-date-transformer')
ESM/CJS dual support, but requires named import from package, not default.
addAxiosDateTransformer
import { addAxiosDateTransformer } from 'axios-date-transformer'
import addAxiosDateTransformer from 'axios-date-transformer'
Named export, not default export.
type AxiosDateTransformerOptions
import type { AxiosDateTransformerOptions } from 'axios-date-transformer'
import { AxiosDateTransformerOptions } from 'axios-date-transformer'
Type-only export, available in TypeScript declarations.

Creates an Axios instance that automatically converts ISO date strings to Date objects.

import { createAxiosDateTransformer } from 'axios-date-transformer'; const api = createAxiosDateTransformer({ baseURL: 'https://jsonplaceholder.typicode.com', }); async function fetchData() { const res = await api.get('/posts/1'); // response data's date strings (if any) are now Date objects console.log(res.data); } fetchData();
Debug
Known issues
gotchaOnly transforms response JSON data; does not handle request data or headers, and does not transform nested date strings.
fix
For nested or non-ISO formats, preprocess response.data manually or use a library like 'superjson'.
affects: >=1.0.0
gotchaDate conversion only applies to strings that match ISO 8601 with milliseconds (e.g., /\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}\.\d{3}Z/). Other date formats are left as strings.
fix
Ensure your API returns dates in the expected ISO with milliseconds format, or extend the regex.
affects: >=1.0.0
deprecatedThe package uses `moment` internally? No, it uses native Date. No deprecated APIs.
fix
N/A
affects: >=1.0.0
Errors
Common errors & fixes
Cannot find module 'axios-date-transformer'
Package not installed or wrong import path (e.g., missing 'axios-date-transformer/src').
fix
Run `npm install axios-date-transformer` and ensure import matches: `import { ... } from 'axios-date-transformer'`.
TypeError: (0 , axios_date_transformer.createAxiosDateTransformer) is not a function
Using require() incorrectly (e.g., `const { createAxiosDateTransformer } = require('axios-date-transformer')` is fine, but default import from CJS may fail).
fix
Use `import { createAxiosDateTransformer } from 'axios-date-transformer'` in an ESM context, or `const { createAxiosDateTransformer } = require('axios-date-transformer')` in CJS.
Property 'createAxiosDateTransformer' does not exist on type 'typeof import(...)'
TypeScript issue due to missing type declarations or incorrect module resolution.
fix
Ensure you have `axios` installed and TypeScript is using `node` moduleResolution. The package ships types, but you might need to check tsconfig.json.
Upgrade
Version history
1.2.1latest on npm
Audit
Dependencies
axiosrequiredpeer dependency, transformer integrates directly into Axios request/response pipeline
Agent activity
50 hits · last 30 days
node
42
OpenAI (training)
1
Resources
axios-date-transformer — npm install axios-date-transformer · libregistry