Skip to content

Commit

Permalink
Add type definitions for plugins
Browse files Browse the repository at this point in the history
  • Loading branch information
ypresto committed Nov 29, 2018
1 parent 963fd2a commit 648ba53
Show file tree
Hide file tree
Showing 10 changed files with 89 additions and 0 deletions.
6 changes: 6 additions & 0 deletions test/plugin/isBetween.d.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import * as dayjs from 'dayjs'
import * as isBetween from 'dayjs/plugin/isBetween'

dayjs.extend(isBetween)

dayjs('2010-10-20').isBetween('2010-10-19', dayjs('2010-10-25')) === true
6 changes: 6 additions & 0 deletions test/plugin/isLeapYear.d.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import * as dayjs from 'dayjs'
import * as isLeapYear from 'dayjs/plugin/isLeapYear'

dayjs.extend(isLeapYear)

dayjs('2010-10-20').isLeapYear() === false
20 changes: 20 additions & 0 deletions test/plugin/relativeTime.d.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import * as dayjs from 'dayjs'
import * as relativeTime from 'dayjs/plugin/relativeTime'

dayjs.extend(relativeTime)

dayjs().fromNow().trim()
dayjs().fromNow(true).trim()

dayjs().from(dayjs()).trim()
dayjs().from(123, true).trim()
dayjs().from('2018-01-23').trim()
dayjs().from(new Date(), true).trim()

dayjs().toNow().trim()
dayjs().toNow(true).trim()

dayjs().to(dayjs()).trim()
dayjs().to(123, true).trim()
dayjs().to('2018-01-23').trim()
dayjs().to(new Date(), true).trim()
6 changes: 6 additions & 0 deletions test/plugin/weekOfYear.d.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import * as dayjs from 'dayjs'
import * as weekOfYear from 'dayjs/plugin/weekOfYear'

dayjs.extend(weekOfYear)

dayjs('2010-10-20').week() === 43
4 changes: 4 additions & 0 deletions types/plugin/advancedFormat.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
import { PluginFunc } from 'dayjs'

declare const plugin: PluginFunc
export = plugin
4 changes: 4 additions & 0 deletions types/plugin/buddhistEra.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
import { PluginFunc } from 'dayjs'

declare const plugin: PluginFunc
export = plugin
10 changes: 10 additions & 0 deletions types/plugin/isBetween.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import { PluginFunc, DateType } from 'dayjs'

declare const plugin: PluginFunc
export = plugin

declare module 'dayjs' {
interface Dayjs {
isBetween(a: DateType, b: DateType): boolean
}
}
10 changes: 10 additions & 0 deletions types/plugin/isLeapYear.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import { PluginFunc } from 'dayjs'

declare const plugin: PluginFunc
export = plugin

declare module 'dayjs' {
interface Dayjs {
isLeapYear(): boolean
}
}
13 changes: 13 additions & 0 deletions types/plugin/relativeTime.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import { PluginFunc, DateType } from 'dayjs'

declare const plugin: PluginFunc
export = plugin

declare module 'dayjs' {
interface Dayjs {
fromNow(withoutSuffix?: boolean): string
from(compared: DateType, withoutSuffix?: boolean): string
toNow(withoutSuffix?: boolean): string
to(compared: DateType, withoutSuffix?: boolean): string
}
}
10 changes: 10 additions & 0 deletions types/plugin/weekOfYear.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import { PluginFunc } from 'dayjs'

declare const plugin: PluginFunc
export = plugin

declare module 'dayjs' {
interface Dayjs {
week(): number
}
}

0 comments on commit 648ba53

Please sign in to comment.