Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 23 additions & 0 deletions types/ethereum-block-by-date/ethereum-block-by-date-tests.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import EthDater = require('ethereum-block-by-date');
import { providers } from 'ethers';
import Web3 from 'web3';

const provider = new providers.CloudflareProvider();
new EthDater(provider); // $ExpectType EthDater

const web3 = new Web3(new Web3.providers.HttpProvider(''));
const dater = new EthDater(web3); // $ExpectType EthDater

// $ExpectType BlockResult
dater.getDate(new Date());
// $ExpectType BlockResult
dater.getDate('2016-07-20T13:20:40Z');
// $ExpectType BlockResult
dater.getDate('2016-07-20T13:20:40Z', false);

// $ExpectType BlockResult[]
dater.getEvery('weeks', '2019-09-02T12:00:00Z', '2019-09-30T12:00:00Z');
// $ExpectType BlockResult[]
dater.getEvery('weeks', '2019-09-02T12:00:00Z', '2019-09-30T12:00:00Z', 2);
// $ExpectType BlockResult[]
dater.getEvery('weeks', '2019-09-02T12:00:00Z', '2019-09-30T12:00:00Z', 3, false);
47 changes: 47 additions & 0 deletions types/ethereum-block-by-date/index.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
// Type definitions for ethereum-block-by-date 1.4
// Project: https://github.com/monosux/ethereum-block-by-date
// Definitions by: Alexandre ABRIOUX <https://github.com/alexandre-abrioux>
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped

import { DurationInputObject, MomentInput } from 'moment';
import { providers as EthersProviders } from 'ethers';
import Web3 from 'web3';

export = EthDater;
export as namespace EthDater;

declare namespace EthDater {
interface BlockResult {
block: number;
timestamp: number;
date: string;
}
}

declare class EthDater {
constructor(provider: EthersProviders.Provider | Web3);

/**
* Search for the closest block on the chain corresponding to the input date.
* @param date Date, required. Any valid moment.js value: string, milliseconds, Date() object, moment() object.
* @param blockAfter Block after, optional. Search for the nearest block before or after the given date. By default, true.
*/
getDate(date: MomentInput, blockAfter?: boolean): EthDater.BlockResult;

/**
* Returns an array of blocks corresponding to periods.
* For example: every first block of Monday's noons of October 2019.
* @param period Period, required. Valid value: years, quarters, months, weeks, days, hours, minutes.
* @param startDate Start date, required. Any valid moment.js value: string, milliseconds, Date() object, moment() object.
* @param endDate End date, required. Any valid moment.js value: string, milliseconds, Date() object, moment() object.
* @param every Duration, optional, integer. By default, 1.
* @param blockAfter Block after, optional. Search for the nearest block before or after the given date. By default, true.
*/
getEvery(
period: keyof DurationInputObject,
startDate: MomentInput,
endDate: MomentInput,
every?: number,
blockAfter?: boolean,
): EthDater.BlockResult[];
}
8 changes: 8 additions & 0 deletions types/ethereum-block-by-date/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"private": true,
"dependencies": {
"moment": "^2.29.1",
"ethers": "^5.4.5",
"web3": "^1.5.2"
}
}
23 changes: 23 additions & 0 deletions types/ethereum-block-by-date/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
{
"compilerOptions": {
"module": "commonjs",
"lib": [
"es6"
],
"noImplicitAny": true,
"noImplicitThis": true,
"strictFunctionTypes": true,
"strictNullChecks": true,
"baseUrl": "../",
"typeRoots": [
"../"
],
"types": [],
"noEmit": true,
"forceConsistentCasingInFileNames": true
},
"files": [
"index.d.ts",
"ethereum-block-by-date-tests.ts"
]
}
1 change: 1 addition & 0 deletions types/ethereum-block-by-date/tslint.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{ "extends": "@definitelytyped/dtslint/dt.json" }