es7-typescript-starter
Version:
An es7/typescript starter for building javascript libraries
178 lines (157 loc) • 4.92 kB
JavaScript
(function () {
;
/**
* 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.
*/
/**
* 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.
*/
/**
* 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
* ```
*/
function power(base, exponent) {
// This is a proposed es7 operator, which should be transpiled by Typescript
return Math.pow(base, exponent);
}
/*! *****************************************************************************
Copyright (c) Microsoft Corporation. All rights reserved.
Licensed under the Apache License, Version 2.0 (the "License"); you may not use
this file except in compliance with the License. You may obtain a copy of the
License at http://www.apache.org/licenses/LICENSE-2.0
THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY IMPLIED
WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE,
MERCHANTABLITY OR NON-INFRINGEMENT.
See the Apache Version 2.0 License for specific language governing permissions
and limitations under the License.
***************************************************************************** */
/* global Reflect, Promise */
function __awaiter(thisArg, _arguments, P, generator) {
return new (P || (P = Promise))(function (resolve, reject) {
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
function rejected(value) { try { step(generator.throw(value)); } catch (e) { reject(e); } }
function step(result) { result.done ? resolve(result.value) : new P(function (resolve) { resolve(result.value); }).then(fulfilled, rejected); }
step((generator = generator.apply(thisArg, _arguments || [])).next());
});
}
/**
* 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']`
*/
/**
* 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']`
*/ function asyncABC() {
return __awaiter(this, void 0, void 0, function* () {
function somethingSlow(index) {
let storage = 'abc'.charAt(index);
return new Promise(resolve => {
// here we pretend to wait on the network
setTimeout(() => resolve(storage), 0);
});
}
let a = yield somethingSlow(0);
let b = yield somethingSlow(1);
let c = yield somethingSlow(2);
return [a, b, c];
});
}
var output = '';
function log(str) {
console.log(str);
output += str + '\n';
}
function logAndAlert(data) {
log('✔ asyncABC returned: ' + data);
window.alert(output);
}
log('Output:');
if (power(3, 4) === 81) {
log('✔ power(3,4) === 81');
}
else {
log('The "power" method seems to be broken.');
}
asyncABC().then(function (abc) { return logAndAlert(abc); });
}());
//# sourceMappingURL=test.js.map