Skip to content

Instantly share code, notes, and snippets.

@y-takagi
Last active August 10, 2020 02:41
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save y-takagi/af13956b8e5981015841141a34fd16ee to your computer and use it in GitHub Desktop.
Save y-takagi/af13956b8e5981015841141a34fd16ee to your computer and use it in GitHub Desktop.
Add local plugin to dayjs.

Add local plugin to dayjs.

// dayjs.ext.ts

import dayjs from 'dayjs';

declare module 'dayjs' {
  interface Dayjs {
    toISODate(): string;
  }
}

const plugin = (_option: any, dayjsClass: any, _dayjsFactory: any) => {
  const proto = dayjsClass.prototype;
  proto.toISODate = function (): string {
    return this.format('YYYY-MM-DD');
  };
};

dayjs.extend(plugin);

Import dayjs.ext.ts at main.ts(Angular) to apply.

// main.ts

import './app/utils/dayjs.ext'

Reference

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment