Skip to content

Commit 361d437

Browse files
yprestoiamkun
authored andcommitted
fix: Add plugin type definitions (#418)
1 parent 35e268a commit 361d437

27 files changed

+221
-19
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ coverage
1717
/plugin
1818
dayjs.min.js
1919
/esm
20+
index.d.ts
2021

2122
#dev
2223
demo.js

.npmignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ coverage
1515
# dev
1616
src
1717
test
18+
types
1819
build
1920
.babelrc
2021
.eslintrc.json
@@ -25,4 +26,4 @@ docs
2526

2627
#other
2728
.travis.yml
28-
karma.sauce.conf.js
29+
karma.sauce.conf.js

build/index.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ const configFactory = require('./rollup.config')
33
const fs = require('fs')
44
const util = require('util')
55
const path = require('path')
6+
const mergedirs = require('merge-dirs').default
67

78
const { promisify } = util
89

@@ -39,6 +40,8 @@ async function build(option) {
3940
input: './src/index.js',
4041
fileName: './dayjs.min.js'
4142
}))
43+
44+
mergedirs('./types/', './', 'overwrite')
4245
} catch (e) {
4346
console.error(e) // eslint-disable-line no-console
4447
}

package.json

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
"types": "index.d.ts",
77
"module": "dayjs.min.js",
88
"scripts": {
9-
"test": "TZ=Pacific/Auckland npm run test-tz && TZ=Europe/London npm run test-tz && npm run test-tz && jest",
9+
"test": "TZ=Pacific/Auckland npm run test-tz && TZ=Europe/London npm run test-tz && npm run test-tz && tsc && jest",
1010
"test-tz": "jest test/timezone.test --coverage=false",
1111
"lint": "./node_modules/.bin/eslint src/* test/* build/*",
1212
"prettier": "prettier --write \"docs/**/*.md\"",
@@ -84,11 +84,12 @@
8484
"karma": "^2.0.2",
8585
"karma-jasmine": "^1.1.2",
8686
"karma-sauce-launcher": "^1.1.0",
87+
"merge-dirs": "^0.2.1",
8788
"mockdate": "^2.0.2",
8889
"moment": "^2.22.0",
8990
"pre-commit": "^1.2.2",
9091
"prettier": "^1.16.1",
91-
"rollup": "^0.57.1",
92+
"rollup": "^0.67.3",
9293
"rollup-plugin-babel": "^4.0.0-beta.4",
9394
"rollup-plugin-uglify": "^3.0.0",
9495
"size-limit": "^0.18.0",

test/index.d.test.ts

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import dayjs from '../src'
1+
import * as dayjs from 'dayjs'
22

33
dayjs()
44

@@ -8,6 +8,12 @@ dayjs(730944000000)
88

99
dayjs(new Date(1993, 3, 1))
1010

11+
dayjs('05/02/69 1:02:03 PM -05:00', 'MM/DD/YY H:mm:ss A Z')
12+
13+
dayjs('05/02/69 1:02:03 PM -05:00', { format: 'MM/DD/YY H:mm:ss A Z' })
14+
15+
dayjs('1993-03-1', { locale: 'ja' })
16+
1117
dayjs().clone()
1218

1319
dayjs().isValid()
@@ -70,10 +76,16 @@ dayjs().isSame(dayjs())
7076

7177
dayjs().isAfter(dayjs())
7278

73-
dayjs().isBefore(dayjs(), 'minutes')
79+
dayjs().isBefore(dayjs(), 'minute')
7480

75-
dayjs().isSame(dayjs(), 'hours')
81+
dayjs().isSame(dayjs(), 'hour')
7682

7783
dayjs().isAfter(dayjs(), 'year')
7884

7985
dayjs('2000-01-01').isLeapYear()
86+
87+
dayjs.extend((o, c, d) => {
88+
o.locale.trim()
89+
new c().unix() // eslint-disable-line new-cap
90+
d().unix()
91+
})

test/plugin/dayOfYear.d.test.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
import * as dayjs from 'dayjs'
2+
import * as dayOfYear from 'dayjs/plugin/dayOfYear'
3+
4+
dayjs.extend(dayOfYear)
5+
6+
dayjs('2015-01-01T00:00:00.000').dayOfYear() === 1

test/plugin/isBetween.d.test.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
import * as dayjs from 'dayjs'
2+
import * as isBetween from 'dayjs/plugin/isBetween'
3+
4+
dayjs.extend(isBetween)
5+
6+
dayjs('2010-10-20').isBetween('2010-10-19', dayjs('2010-10-25')) === true

test/plugin/isLeapYear.d.test.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
import * as dayjs from 'dayjs'
2+
import * as isLeapYear from 'dayjs/plugin/isLeapYear'
3+
4+
dayjs.extend(isLeapYear)
5+
6+
dayjs('2010-10-20').isLeapYear() === false

test/plugin/isSameOrAfter.d.test.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
import * as dayjs from 'dayjs'
2+
import * as isSameOrAfter from 'dayjs/plugin/isSameOrAfter'
3+
4+
dayjs.extend(isSameOrAfter)
5+
6+
dayjs('2010-10-20').isSameOrAfter('2010-10-19', 'year') === true

test/plugin/isSameOrBefore.d.test.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
import * as dayjs from 'dayjs'
2+
import * as isSameOrBefore from 'dayjs/plugin/isSameOrBefore'
3+
4+
dayjs.extend(isSameOrBefore)
5+
6+
dayjs('2010-10-20').isSameOrBefore('2010-10-19', 'year') === true

0 commit comments

Comments
 (0)