Some TypeScript examples written to get started with tooling setup (tsx, mocha, chai, nyc and tsup).
Description | Source | Test | CLI |
---|---|---|---|
pow(x,n) as x^n |
src/pow.ts | test/pow.spec.ts | |
Fibonacci generator | src/fibonacci.ts | test/fibonacci.spec.ts | cli/fibonacci.ts |
Take n elements from a generic generator | src/take.ts | test/fibonacci.spec.ts | cli/take.ts |
npx tsx cli/fibonacci.ts
See .mocharc.json
# run all tests
npm run test
# run single test file
npm run test test/pow.spec.ts
See .nycrc
# run all tests
npm run coverage
See tsup.config.ts, package.json - main, module, types and exports :
npm run build
It allows :
- Usage in index.html
- Usage with
import
syntax (ES module) :
import {pow} from '@mborne/ts-examples';
console.log(pow(10,3));
- Usage with
require
syntax (CommonJS) :
const pow = require('@mborne/ts-examples').pow;
console.log(pow(10,3));
Bunding method taken from Turfjs