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 🙏

© 2024 – Pkg Stats / Ryan Hefner

@vanrossumict/material-dayjs-adapter

v0.0.10

Published

A MatDateAdapter for Dayjs to reduce dependency sizes when compared to MomentJS based adapters.

Downloads

38

Readme

MaterialDayjsAdapter

Fork of @tabuckner/material-dayjs-adapter with localization added.

An adapter to use Dayjs instead of MomentJS in an effort to reduce dependency size. Feel free to create an issue or submit a PR.

If coming from @angular/material-moment-adapter, using the default locale and UTC plugins you can reduce your dependency size by ~560kb

Heavily inspired by @angular/material-moment-adapter NPM.

This library was generated with Angular CLI version 8.2.14.

Dependency Size Reduction

MomentJS comes bundled with a lot of stuff that you may not need--for instance, locales. If you find that MaterialDayJsAdapter suits your needs well, you could see some substantial size cost savings. In most situations you will see a reduction of ~560kb in webpack-bundle-analyzer.

An Example Project

Using a brand new app generated with the @angular/cli, an app was set up using both MomentJS Date Adapter and Dayjs Date Adapter. Production build statics were then analyzed with webpack-bundle-analyzer.

Stats

| Chunk Name | MomentJS | Dayjs | Size Reduction | | ----------------------------- | :------: | :-----: | -------------: | | chunk {0} runtime-es2015.js | 1.45 kB | 1.45 kB | 0% | | chunk {0} runtime-es5.js | 1.45 kB | 1.45 kB | 0% | | chunk {1} main-es2015.js | 775 kB | 42 kB | 43% | | chunk {1} main-es5.js | 838 kB | 505 kB | 40% | | chunk {2} polyfills-es2015.js | 36.4 kB | 36.4 kB | 0% | | chunk {3} polyfills-es5.js | 123 kB | 123 kB | 0% | | chunk {4} styles.css | 62.7 kB | 62.7 kB | 0% |

MomentJS

Minimal Project with MomentJS Date Adapter momentjs date adapter bundle size analyzer graph momentjs cli stats

Dayjs

Minimal Project with Dayjs Date Adapter dayjs date adapter bundle size analyzer graph dayjs cli stats

How To Use

Import Module

import { MatDayjsDateModule } from '@vanrossumict/material-dayjs-adapter';

@NgModule({
 ...
  imports: [
    ...
    MatDatepickerModule,
    MatDayjsDateModule,
    ...
  ],
  ...
})
export class AppModule { }

Localization

Import the locales you need from DayJS and set the current locale

  1. Globally for DayJS
  2. To the Date Adapter itself For example in your AppComponent:
import { DateAdapter } from '@angular/material';
import dayjs, { Dayjs } from 'dayjs';
import 'dayjs/locale/nl';
...
export class AppComponent {
  constructor(private dateAdapter: DateAdapter<Dayjs>) { 
    this.setLocale('nl');
  }

  setLocale(locale: string) {
    dayjs.locale(locale);
    this.dateAdapter.setLocale(locale);
  }
...

Optionally Provide A Configuration

import { MatDayjsDateModule, MAT_DAYJS_DATE_ADAPTER_OPTIONS } from '@vanrossumict/material-dayjs-adapter';
@NgModule({
  ...
  providers: [
    { provide: MAT_DAYJS_DATE_ADAPTER_OPTIONS, useValue: { useUtc: true } }
  ],
  ...
})
export class AppModule { }

Currently Supported Options

export interface DayJsDateAdapterOptions {
  /**
   * Turns the use of utc dates on or off.
   * Changing this will change how Angular Material components like DatePicker output dates.
   * {@default false}
   */
  useUtc?: boolean;
}

Development

Code scaffolding

Run ng generate component component-name --project material-dayjs-adapter to generate a new component. You can also use ng generate directive|pipe|service|class|guard|interface|enum|module --project material-dayjs-adapter.

Note: Don't forget to add --project material-dayjs-adapter or else it will be added to the default project in your angular.json file.

Build

Run ng build material-dayjs-adapter to build the project. The build artifacts will be stored in the dist/ directory.

Publishing

After building your library with ng build material-dayjs-adapter, go to the dist folder cd dist/material-dayjs-adapter and run npm publish.

Running unit tests

Run ng test material-dayjs-adapter to execute the unit tests via Karma.

Further help

To get more help on the Angular CLI use ng help or go check out the Angular CLI README.