diff --git a/index.d.test.ts b/index.d.test.ts new file mode 100644 index 000000000..71a2ae5a9 --- /dev/null +++ b/index.d.test.ts @@ -0,0 +1,71 @@ +import dayjs from '.' + +dayjs() + +dayjs('1993-03-1') + +dayjs(730944000000) + +dayjs(new Date(1993, 3, 1)) + +dayjs().clone() + +dayjs().isValid() + +dayjs().year() + +dayjs().month() + +dayjs().date() + +dayjs().hour() + +dayjs().minute() + +dayjs().second() + +dayjs().millisecond() + +dayjs().set('month', 3) +dayjs().set('second', 30) + +dayjs().add(7, 'day') + +dayjs().subtract(7, 'year') + +dayjs().startOf('year') + +dayjs().endOf('month') + +dayjs().startOf('month').add(1, 'day').subtract(1, 'year') + +dayjs().format() +dayjs().format('[YYYY] MM-DDTHH:mm:ssZ') + +dayjs().diff(dayjs(), 'year') + +dayjs().valueOf() + +dayjs().unix() + +dayjs().daysInMonth() + +dayjs().toDate() + +dayjs().toArray() + +dayjs().toJSON() + +dayjs().toISOString() + +dayjs().toObject() + +dayjs().toString() + +dayjs().isBefore(dayjs()) + +dayjs().isSame(dayjs()) + +dayjs().isAfter(dayjs()) + +dayjs('2000-01-01').isLeapYear(dayjs()) diff --git a/index.d.ts b/index.d.ts new file mode 100644 index 000000000..d70fac9fd --- /dev/null +++ b/index.d.ts @@ -0,0 +1,83 @@ +// Type definitions for dayjs 1.0 +// Project: https://github.com/xx45/dayjs +// Definitions by: varHarrie + +type ConfigType = string | number | Date | Dayjs + +type UnitType = 'millisecond' | 'second' | 'minute' | 'hour' | 'day' | 'week' | 'month' | 'quarter' | 'year' | 'date' + +interface DayjsObject { + years: number + months: number + date: number + hours: number + minutes: number + seconds: number + milliseconds: number +} + +declare class Dayjs { + constructor (config?: ConfigType) + + clone(): Dayjs + + isValid(): boolean + + year(): number + + month(): number + + date(): number + + hour(): number + + minute(): number + + second(): number + + millisecond(): number + + set(unit: UnitType, value: number): Dayjs + + add(value: number, unit: UnitType): Dayjs + + subtract(value: number, unit: UnitType): Dayjs + + startOf(unit: UnitType): Dayjs + + endOf(unit: UnitType): Dayjs + + format(template?: string): string + + diff(dayjs: Dayjs, unit: UnitType, float?: boolean): number + + valueOf(): number + + unix(): number + + daysInMonth(): number + + toDate(): Date + + toArray(): number[] + + toJSON(): string + + toISOString(): string + + toObject(): Object + + toString(): string + + isBefore(dayjs: Dayjs): boolean + + isSame(dayjs: Dayjs) + + isAfter(dayjs: Dayjs) + + isLeapYear(dayjs?: Dayjs): boolean +} + +declare function dayjs (config?: ConfigType): Dayjs + +export default dayjs diff --git a/package.json b/package.json index 37830afc7..64d036f4d 100644 --- a/package.json +++ b/package.json @@ -3,6 +3,7 @@ "version": "0.0.0-development", "description": "", "main": "dist/dayjs.min.js", + "types": "index.d.ts", "scripts": { "test": "jest", "lint": "./node_modules/.bin/eslint src/* test/*",