npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2025 – Pkg Stats / Ryan Hefner

ng-http-date-core

v11.0.0

Published

Detects and parses dates in Angular Http reponses and creates Date-objects within the reponse

Readme

NgHttpDate

What?

NgHttpDate is an Angular library that detects dates in HTTP JSON reponses and modifies the responses to contain Date objects (or Day.js or Moment via Plugin) instead of String objects.

Installation

Install ng-http-date via npm or yarn or any other compatible packet manager:

npm i ng-http-date

If you're not using the current Angular version you should use an older version of ng-http-date:

| Angular | 11.x | 10.x | 9.x | 8.2.x | older | |--------------|------|------|-----|-------|---------------| | ng-http-date | 11.x | 10.x | 9.x | 8.x | not supported |

Import the NgHttpDateModule in your root module:

import {NgHttpDateModule} from 'ng-http-date-core';

@NgModule({
  declarations: [...],
  imports: [
    ...
    NgHttpDateModule.forRoot(),
    ...
  ],
  providers: [...],
  bootstrap: [...]
})
export class AppModule {
  ...
}

Why?

Angular is not converting dates in JSON to EcmaScript Date objects. Even if you declare properties of your HTTP call return type as Date they're just Strings at runtime:

export class ResultOfHttpCall {
  someProperty: Date;
}

...

this.http.get<ResultOfHttpCall>('someURL').subscribe((result: ResultOfHttpCall) => {
  typeof result.someProperty; // string
  result.someProperty.toISOString(); // ERROR: someProperty.toISOString is not a function
}

How?

NgHttpDate registers an HttpInterceptor which tests each property of the response via an ISO8601 regex. When a date is detected, the response is modified to create a Date object for that property.

Configuration

Per default only ISO8601 date strings are converted. In addition, all strings that correspond to an ISO8601 date are converted, which means that e.g. '2000' or '0001' also become a date. To configure this behavior you can pass a configuration object to the modules forRoot method:

import {NgHttpDateModule} from 'ng-http-date-core';

@NgModule({
  declarations: [...],
  imports: [
    ...
    NgHttpDateModule.forRoot({iso8601Only: false}), // converts RFC 2822 timestamps
    ...
  ],
  providers: [...],
  bootstrap: [...]
})
export class AppModule {
  ...
}

You have the following configuration options:

  • iso8601Only (default false) - pass true to convert every string that can be converted to a Date (or moment or Dayjs) object. This has a negative impact on performance.
  • customRegex (default undefined) - pass a custom RegExp which decides if a string is converted or not. This will set iso8601Only to false.
  • debug (default false) - pass true to print some more or less helpful debug messages to the browser console.

Performance

The core library is 2 kB gzipped. The gzipped size of the plugins is 1 kB each. The detection and creation of Date objects has nearly no performance impact. For example, modifying a small size nested JSON object 1.000.000 times is done in ~ 8 seconds. That's 0.008 ms per object.

Plugins

If you want NgHttpDate to use Day.js objects or Moment objects instead of EcmaScript Dates you can install the appropriate plugin:

Installation of ng-http-date-dayjs

Installation of ng-http-date-moment

What's next?

Currently only ISO8601 compliant dates are recognized and converted. It's planned for the next minor release to provide a way to configure this behavior.