Skip to content

Commit 341481a

Browse files
[ethereum-block-by-date] add type definitions
1 parent 8ffa44f commit 341481a

File tree

5 files changed

+102
-0
lines changed

5 files changed

+102
-0
lines changed
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
import EthDater = require('ethereum-block-by-date');
2+
import { providers } from 'ethers';
3+
import Web3 from 'web3';
4+
5+
const provider = new providers.CloudflareProvider();
6+
new EthDater(provider); // $ExpectType EthDater
7+
8+
const web3 = new Web3(new Web3.providers.HttpProvider(''));
9+
const dater = new EthDater(web3); // $ExpectType EthDater
10+
11+
// $ExpectType BlockResult
12+
dater.getDate(new Date());
13+
// $ExpectType BlockResult
14+
dater.getDate('2016-07-20T13:20:40Z');
15+
// $ExpectType BlockResult
16+
dater.getDate('2016-07-20T13:20:40Z', false);
17+
18+
// $ExpectType BlockResult[]
19+
dater.getEvery('weeks', '2019-09-02T12:00:00Z', '2019-09-30T12:00:00Z');
20+
// $ExpectType BlockResult[]
21+
dater.getEvery('weeks', '2019-09-02T12:00:00Z', '2019-09-30T12:00:00Z', 2);
22+
// $ExpectType BlockResult[]
23+
dater.getEvery('weeks', '2019-09-02T12:00:00Z', '2019-09-30T12:00:00Z', 3, false);
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
// Type definitions for ethereum-block-by-date 1.4
2+
// Project: https://github.com/monosux/ethereum-block-by-date
3+
// Definitions by: Alexandre ABRIOUX <https://github.com/alexandre-abrioux>
4+
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
5+
6+
import { DurationInputObject, MomentInput } from 'moment';
7+
import { providers as EthersProviders } from 'ethers';
8+
import Web3 from 'web3';
9+
10+
export = EthDater;
11+
export as namespace EthDater;
12+
13+
declare namespace EthDater {
14+
interface BlockResult {
15+
block: number;
16+
timestamp: number;
17+
date: string;
18+
}
19+
}
20+
21+
declare class EthDater {
22+
constructor(provider: EthersProviders.Provider | Web3);
23+
24+
/**
25+
* Search for the closest block on the chain corresponding to the input date.
26+
* @param date Date, required. Any valid moment.js value: string, milliseconds, Date() object, moment() object.
27+
* @param blockAfter Block after, optional. Search for the nearest block before or after the given date. By default, true.
28+
*/
29+
getDate(date: MomentInput, blockAfter?: boolean): EthDater.BlockResult;
30+
31+
/**
32+
* Returns an array of blocks corresponding to periods.
33+
* For example: every first block of Monday's noons of October 2019.
34+
* @param period Period, required. Valid value: years, quarters, months, weeks, days, hours, minutes.
35+
* @param startDate Start date, required. Any valid moment.js value: string, milliseconds, Date() object, moment() object.
36+
* @param endDate End date, required. Any valid moment.js value: string, milliseconds, Date() object, moment() object.
37+
* @param every Duration, optional, integer. By default, 1.
38+
* @param blockAfter Block after, optional. Search for the nearest block before or after the given date. By default, true.
39+
*/
40+
getEvery(
41+
period: keyof DurationInputObject,
42+
startDate: MomentInput,
43+
endDate: MomentInput,
44+
every?: number,
45+
blockAfter?: boolean,
46+
): EthDater.BlockResult[];
47+
}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
{
2+
"private": true,
3+
"dependencies": {
4+
"moment": "^2.29.1",
5+
"ethers": "^5.4.5",
6+
"web3": "^1.5.2"
7+
}
8+
}
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
{
2+
"compilerOptions": {
3+
"module": "commonjs",
4+
"lib": [
5+
"es6"
6+
],
7+
"noImplicitAny": true,
8+
"noImplicitThis": true,
9+
"strictFunctionTypes": true,
10+
"strictNullChecks": true,
11+
"baseUrl": "../",
12+
"typeRoots": [
13+
"../"
14+
],
15+
"types": [],
16+
"noEmit": true,
17+
"forceConsistentCasingInFileNames": true
18+
},
19+
"files": [
20+
"index.d.ts",
21+
"ethereum-block-by-date-tests.ts"
22+
]
23+
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
{ "extends": "@definitelytyped/dtslint/dt.json" }

0 commit comments

Comments
 (0)