1
0
mirror of synced 2026-04-05 14:41:02 +00:00

feat: TS v4, tslint -> eslint, add cspell support (#240)

Update all dependencies, migrate from tslint (deprecated) to typescript-eslint, and add support for
cspell.

BREAKING CHANGE: migrated from tslint (deprecated) to eslint.
This commit is contained in:
Jason Dreyzehner
2020-09-01 19:13:25 -04:00
committed by GitHub
parent ab50e80ec8
commit 390041b510
31 changed files with 6526 additions and 4298 deletions

View File

@@ -1,7 +1,7 @@
// tslint:disable:no-expression-statement
import test from 'ava';
import { asyncABC } from './async';
test('getABC', async t => {
test('getABC', async (t) => {
t.deepEqual(await asyncABC(), ['a', 'b', 'c']);
});

View File

@@ -1,5 +1,5 @@
/**
* A sample async function (to demo Typescript's es7 async/await downleveling).
* A sample async function (to demo Typescript's es7 async/await down-leveling).
*
* ### Example (es imports)
* ```js
@@ -15,18 +15,18 @@
* // => ['a','b','c']
* ```
*
* @returns a Promise which should contain `['a','b','c']`
* @returns a Promise which should contain `['a','b','c']`
*/
export async function asyncABC(): Promise<ReadonlyArray<string>> {
function somethingSlow(index: 0 | 1 | 2): Promise<string> {
export const asyncABC = async () => {
const somethingSlow = (index: 0 | 1 | 2) => {
const storage = 'abc'.charAt(index);
return new Promise<string>(resolve =>
return new Promise<string>((resolve) =>
// later...
resolve(storage)
);
}
};
const a = await somethingSlow(0);
const b = await somethingSlow(1);
const c = await somethingSlow(2);
return [a, b, c];
}
};

View File

@@ -1,11 +1,11 @@
// tslint:disable:no-expression-statement no-object-mutation
import test from 'ava';
import { sha256, sha256Native } from './hash';
test(
'sha256',
(t, input: string, expected: string) => {
t.is(sha256(input), expected);
async (t, input: string, expected: string) => {
t.is(await sha256(input), expected);
t.is(sha256Native(input), expected);
},
'test',

View File

@@ -1,5 +1,6 @@
import { createHash } from 'crypto';
import shaJs from 'sha.js';
import { binToHex, instantiateSha256, utf8ToBin } from '@bitauth/libauth';
/**
* Calculate the sha256 digest of a string.
@@ -7,32 +8,34 @@ import shaJs from 'sha.js';
* ### Example (es imports)
* ```js
* import { sha256 } from 'typescript-starter'
* sha256('test')
* // => '9f86d081884c7d659a2feaa0c55ad015a3bf4f1b2b0b822cd15d6c15b0f00a08'
*
* (async () => {
* console.log(await sha256('test'));
* // => '9f86d081884c7d659a2feaa0c55ad015a3bf4f1b2b0b822cd15d6c15b0f00a08'
* });
* ```
*
* @param message - the string to hash
* @returns sha256 message digest
*/
export function sha256(message: string): string {
return shaJs('sha256')
.update(message)
.digest('hex');
}
export const sha256 = async (message: string) => {
const sha256 = await instantiateSha256();
return binToHex(sha256.hash(utf8ToBin(message)));
};
/**
* A faster implementation of [[sha256]] which requires the native Node.js module. Browser consumers should use [[sha256]], instead.
* A synchronous implementation of `sha256` which uses the native Node.js
* module. (Browser consumers should use the `sha256` method.)
*
* ### Example (es imports)
* ```js
* import { sha256Native as sha256 } from 'typescript-starter'
* sha256('test')
* console.log(sha256('test'));
* // => '9f86d081884c7d659a2feaa0c55ad015a3bf4f1b2b0b822cd15d6c15b0f00a08'
* ```
*
* @param message - the string to hash
* @returns sha256 message digest
*/
export function sha256Native(message: string): string {
return createHash('sha256')
.update(message)
.digest('hex');
}
export const sha256Native = (message: string) => {
return createHash('sha256').update(message).digest('hex');
};

View File

@@ -1,11 +1,11 @@
// tslint:disable:no-expression-statement
import test from 'ava';
import { double, power } from './number';
test('double', t => {
test('double', (t) => {
t.is(double(2), 4);
});
test('power', t => {
test('power', (t) => {
t.is(power(2, 4), 16);
});

View File

@@ -1,5 +1,5 @@
/**
* Multiplies a value by 2. (Also a full example of Typedoc's functionality.)
* Multiplies a value by 2. (Also a full example of TypeDoc's functionality.)
*
* ### Example (es module)
* ```js
@@ -15,16 +15,17 @@
* // => 8
* ```
*
* @param value Comment describing the `value` parameter.
* @returns Comment describing the return type.
* @anotherNote Some other value.
* @param value - Comment describing the `value` parameter.
* @returns Comment describing the return type.
* @anotherNote Some other value.
*/
export function double(value: number): number {
export const double = (value: number) => {
return value * 2;
}
};
/**
* Raise the value of the first parameter to the power of the second using the es7 `**` operator.
* Raise the value of the first parameter to the power of the second using the
* es7 exponentiation operator (`**`).
*
* ### Example (es module)
* ```js
@@ -39,8 +40,12 @@ export function double(value: number): number {
* console.log(power(2,3))
* // => 8
* ```
* @param base - the base to exponentiate
* @param exponent - the power to which to raise the base
*/
export function power(base: number, exponent: number): number {
// This is a proposed es7 operator, which should be transpiled by Typescript
export const power = (base: number, exponent: number) => {
/**
* This es7 exponentiation operator is transpiled by TypeScript
*/
return base ** exponent;
}
};