Skip to content

[DEV] Some TypeScript examples written to get started with tooling setup (tsx, mocha, chai, nyc, tsup)

License

Notifications You must be signed in to change notification settings

mborne/ts-examples

Repository files navigation

ts-examples

Some TypeScript examples written to get started with tooling setup (tsx, mocha, chai, nyc and tsup).

Requirements

Examples

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

Usage

Run cli examples

npx tsx cli/fibonacci.ts

Run tests

See .mocharc.json

# run all tests
npm run test
# run single test file
npm run test test/pow.spec.ts

Check test coverage

See .nycrc

# run all tests
npm run coverage

Bundling

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));

Credits

Bunding method taken from Turfjs

License

MIT

About

[DEV] Some TypeScript examples written to get started with tooling setup (tsx, mocha, chai, nyc, tsup)

Topics

Resources

License

Stars

Watchers

Forks