Skip to content

Commit 5766925

Browse files
authored
Merge pull request #18 from dartess/feature/typings-ts
add typescript typings
2 parents 9a6d179 + 6f7075d commit 5766925

File tree

3 files changed

+54
-0
lines changed

3 files changed

+54
-0
lines changed

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
"version": "1.1.8",
44
"description": "React timer hook is a custom react hook built to handle timers(countdown), stopwatch and time logic/state in your react component.",
55
"main": "dist/index.js",
6+
"types": "dist/index.d.ts",
67
"scripts": {
78
"build:dev": "webpack --config webpack.dev.js && webpack-dev-server --open --config webpack.dev.js",
89
"build:prod": "rm -rf ./dist && webpack --config webpack.prod.js"

src/index.d.ts

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
interface TimerSettings {
2+
expiryTimestamp: number;
3+
onExpire?: () => void;
4+
}
5+
6+
interface TimerResult {
7+
seconds: number;
8+
minutes: number;
9+
hours: number;
10+
days: number;
11+
start: () => void;
12+
pause: () => void;
13+
resume: () => void;
14+
restart: (newExpiryTimestamp: number) => void;
15+
}
16+
17+
export function useTimer(settings: TimerSettings): TimerResult
18+
19+
interface StopwatchSettings {
20+
autoStart?: boolean;
21+
}
22+
23+
interface StopwatchResult {
24+
seconds: number;
25+
minutes: number;
26+
hours: number;
27+
days: number;
28+
start: () => void;
29+
pause: () => void;
30+
reset: () => void;
31+
}
32+
33+
export function useStopwatch(settings?: StopwatchSettings): StopwatchResult
34+
35+
interface TimeSettings {
36+
format?: '12-hour';
37+
}
38+
39+
interface TimeResult {
40+
seconds: number;
41+
minutes: number;
42+
hours: number;
43+
ampm: '' | 'pm' | 'am';
44+
}
45+
46+
export function useTime(settings?: TimeSettings): TimeResult

webpack.prod.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
const CopyWebpackPlugin = require('copy-webpack-plugin');
2+
13
module.exports = {
24
performance: {
35
hints: false
@@ -18,6 +20,11 @@ module.exports = {
1820
}
1921
}]
2022
},
23+
plugins: [
24+
new CopyWebpackPlugin([
25+
{ from: './src/index.d.ts', to: './' },
26+
]),
27+
],
2128
externals: [
2229
'react',
2330
/^react\/.+$/,

0 commit comments

Comments
 (0)