1
0
mirror of synced 2025-11-08 21:07:23 +00:00

feat(CLI): v2

This commit is contained in:
Jason Dreyzehner
2018-03-10 14:01:34 -05:00
parent 335a988dd8
commit 260a7d37bb
27 changed files with 3967 additions and 1550 deletions

View File

@@ -1,3 +1,4 @@
// tslint:disable:no-expression-statement
import { test } from 'ava';
import { asyncABC } from './async';

View File

@@ -17,13 +17,13 @@
*
* @returns a Promise which should contain `['a','b','c']`
*/
export async function asyncABC() {
function somethingSlow(index: 0 | 1 | 2) {
export async function asyncABC(): Promise<ReadonlyArray<string>> {
function somethingSlow(index: 0 | 1 | 2): Promise<string> {
const storage = 'abc'.charAt(index);
return new Promise<string>(resolve => {
// here we pretend to wait on the network
setTimeout(() => resolve(storage), 0);
});
return new Promise<string>(resolve =>
// later...
resolve(storage)
);
}
const a = await somethingSlow(0);
const b = await somethingSlow(1);

View File

@@ -1,3 +1,4 @@
// tslint:disable:no-expression-statement no-object-mutation
import { Macro, test } from 'ava';
import { sha256, sha256Native } from './hash';

View File

@@ -13,7 +13,7 @@ import shaJs from 'sha.js';
*
* @returns sha256 message digest
*/
export function sha256(message: string) {
export function sha256(message: string): string {
return shaJs('sha256')
.update(message)
.digest('hex');
@@ -22,9 +22,16 @@ export function sha256(message: string) {
/**
* A faster implementation of [[sha256]] which requires the native Node.js module. Browser consumers should use [[sha256]], instead.
*
* ### Example (es imports)
* ```js
* import { sha256Native as sha256 } from 'typescript-starter'
* sha256('test')
* // => '9f86d081884c7d659a2feaa0c55ad015a3bf4f1b2b0b822cd15d6c15b0f00a08'
* ```
*
* @returns sha256 message digest
*/
export function sha256Native(message: string) {
export function sha256Native(message: string): string {
return createHash('sha256')
.update(message)
.digest('hex');

View File

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

View File

@@ -19,7 +19,7 @@
* @returns Comment describing the return type.
* @anotherNote Some other value.
*/
export function double(value: number) {
export function double(value: number): number {
return value * 2;
}
@@ -40,7 +40,7 @@ export function double(value: number) {
* // => 8
* ```
*/
export function power(base: number, exponent: number) {
export function power(base: number, exponent: number): number {
// This is a proposed es7 operator, which should be transpiled by Typescript
return base ** exponent;
}