chore(release): 1.0.0
This commit is contained in:
6
src/lib/asyncOps.spec.ts
Normal file
6
src/lib/asyncOps.spec.ts
Normal file
@@ -0,0 +1,6 @@
|
||||
import { test } from 'ava'
|
||||
import { asyncABC } from '../'
|
||||
|
||||
test('getABC', async t => {
|
||||
t.deepEqual(await asyncABC(), ['a','b', 'c'])
|
||||
})
|
||||
32
src/lib/asyncOps.ts
Normal file
32
src/lib/asyncOps.ts
Normal file
@@ -0,0 +1,32 @@
|
||||
/**
|
||||
* A sample async function (to demo Typescript's es7 async/await downleveling).
|
||||
*
|
||||
* ### Example (es imports)
|
||||
* ```js
|
||||
* import { asyncABC } from 'es7-typescript-starter'
|
||||
* console.log(await asyncABC())
|
||||
* // => ['a','b','c']
|
||||
* ```
|
||||
*
|
||||
* ### Example (commonjs)
|
||||
* ```js
|
||||
* var double = require('es7-typescript-starter').asyncABC;
|
||||
* asyncABC().then(console.log);
|
||||
* // => ['a','b','c']
|
||||
* ```
|
||||
*
|
||||
* @returns a Promise which should contain `['a','b','c']`
|
||||
*/
|
||||
export async function asyncABC() {
|
||||
function somethingSlow(index: 0 | 1 | 2) {
|
||||
let storage = 'abc'.charAt(index)
|
||||
return new Promise<string>(resolve => {
|
||||
// here we pretend to wait on the network
|
||||
setTimeout(() => resolve(storage), 0)
|
||||
})
|
||||
}
|
||||
let a = await somethingSlow(0)
|
||||
let b = await somethingSlow(1)
|
||||
let c = await somethingSlow(2)
|
||||
return [a, b, c]
|
||||
}
|
||||
10
src/lib/numberOps.spec.ts
Normal file
10
src/lib/numberOps.spec.ts
Normal file
@@ -0,0 +1,10 @@
|
||||
import { test } from 'ava'
|
||||
import { double, power } from '../'
|
||||
|
||||
test('double', t => {
|
||||
t.deepEqual(double(2), 4)
|
||||
})
|
||||
|
||||
test('power', t => {
|
||||
t.deepEqual(power(2,4), 16)
|
||||
})
|
||||
46
src/lib/numberOps.ts
Normal file
46
src/lib/numberOps.ts
Normal file
@@ -0,0 +1,46 @@
|
||||
/**
|
||||
* Multiplies a value by 2. (Also a full example of Typedoc's functionality.)
|
||||
*
|
||||
* ### Example (es module)
|
||||
* ```js
|
||||
* import { double } from 'es7-typescript-starter'
|
||||
* console.log(double(4))
|
||||
* // => 8
|
||||
* ```
|
||||
*
|
||||
* ### Example (commonjs)
|
||||
* ```js
|
||||
* var double = require('es7-typescript-starter').double;
|
||||
* console.log(double(4))
|
||||
* // => 8
|
||||
* ```
|
||||
*
|
||||
* @param value Comment describing the `value` parameter.
|
||||
* @returns Comment describing the return type.
|
||||
* @anotherNote Some other value.
|
||||
*/
|
||||
export function double (value: number) {
|
||||
return value * 2
|
||||
}
|
||||
|
||||
/**
|
||||
* Raise the value of the first parameter to the power of the second using the es7 `**` operator.
|
||||
*
|
||||
* ### Example (es module)
|
||||
* ```js
|
||||
* import { power } from 'es7-typescript-starter'
|
||||
* console.log(power(2,3))
|
||||
* // => 8
|
||||
* ```
|
||||
*
|
||||
* ### Example (commonjs)
|
||||
* ```js
|
||||
* var power = require('es7-typescript-starter').power;
|
||||
* console.log(power(2,3))
|
||||
* // => 8
|
||||
* ```
|
||||
*/
|
||||
export function power (base: number, exponent: number) {
|
||||
// This is a proposed es7 operator, which should be transpiled by Typescript
|
||||
return base ** exponent
|
||||
}
|
||||
Reference in New Issue
Block a user