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

feat(CLI): create CLI, begin work on v2

This commit is contained in:
Jason Dreyzehner
2018-02-22 02:20:38 -05:00
parent a211a54c1f
commit 76336c88db
25 changed files with 11069 additions and 5189 deletions

View File

@@ -1,6 +1,6 @@
import { test } from 'ava'
import { asyncABC } from 'typescript-starter'
import { test } from 'ava';
import { asyncABC } from './async';
test('getABC', async t => {
t.deepEqual(await asyncABC(), ['a','b', 'c'])
})
t.deepEqual(await asyncABC(), ['a', 'b', 'c']);
});

View File

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

View File

@@ -1,6 +1,17 @@
import { test } from 'ava'
import { sha256 } from 'typescript-starter'
import { Macro, test } from 'ava';
import { sha256, sha256Native } from './hash';
test('sha256', t => {
t.deepEqual(sha256('test'), '9f86d081884c7d659a2feaa0c55ad015a3bf4f1b2b0b822cd15d6c15b0f00a08')
})
const hash: Macro = (t, input: string, expected: string) => {
t.is(sha256(input), expected);
t.is(sha256Native(input), expected);
};
hash.title = (providedTitle: string, input: string, expected: string) =>
`${providedTitle}: ${input} => ${expected}`;
test(
'sha256',
hash,
'test',
'9f86d081884c7d659a2feaa0c55ad015a3bf4f1b2b0b822cd15d6c15b0f00a08'
);

View File

@@ -1,7 +1,8 @@
import { createHash } from 'crypto'
import { createHash } from 'crypto';
import shaJs from 'sha.js';
/**
* Calculate the sha256 digest of a string. On Node.js, this will use the native module, in the browser, it will fall back to a pure javascript implementation.
* Calculate the sha256 digest of a string.
*
* ### Example (es imports)
* ```js
@@ -12,6 +13,19 @@ import { createHash } from 'crypto'
*
* @returns sha256 message digest
*/
export function sha256 (message: string) {
return createHash('sha256').update(message).digest('hex')
export function sha256(message: string) {
return shaJs('sha256')
.update(message)
.digest('hex');
}
/**
* A faster implementation of [[sha256]] which requires the native Node.js module. Browser consumers should use [[sha256]], instead.
*
* @returns sha256 message digest
*/
export function sha256Native(message: string) {
return createHash('sha256')
.update(message)
.digest('hex');
}

View File

@@ -1,10 +1,10 @@
import { test } from 'ava'
import { double, power } from 'typescript-starter'
import { test } from 'ava';
import { double, power } from './number';
test('double', t => {
t.deepEqual(double(2), 4)
})
t.deepEqual(double(2), 4);
});
test('power', t => {
t.deepEqual(power(2,4), 16)
})
t.deepEqual(power(2, 4), 16);
});

View File

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