https://github.com/mborne/ts-examples
[DEV] Some TypeScript examples written to get started with tooling setup (tsx, mocha, chai, nyc, tsup)
https://github.com/mborne/ts-examples
chai example mocha nyc tsx typescript
Last synced: 2 days ago
JSON representation
[DEV] Some TypeScript examples written to get started with tooling setup (tsx, mocha, chai, nyc, tsup)
- Host: GitHub
- URL: https://github.com/mborne/ts-examples
- Owner: mborne
- License: mit
- Created: 2023-12-21T10:14:47.000Z (about 2 years ago)
- Default Branch: master
- Last Pushed: 2024-07-24T14:41:10.000Z (over 1 year ago)
- Last Synced: 2025-07-18T02:21:32.272Z (7 months ago)
- Topics: chai, example, mocha, nyc, tsx, typescript
- Language: TypeScript
- Homepage:
- Size: 214 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# ts-examples
Some TypeScript examples written to get started with tooling setup ([tsx](https://tsx.is/getting-started), mocha, chai, nyc and [tsup](https://tsup.egoist.dev/)).
## Requirements
* [NodeJS >= 20](https://nodejs.org/fr)
## Examples
| Description | Source | Test | CLI |
| -------------------------------------------- | ------------------------------------ | ------------------------------------------------ | ------------------------------------ |
| `pow(x,n)` as `x^n` | [src/pow.ts](src/pow.ts) | [test/pow.spec.ts](test/pow.spec.ts) | |
| Fibonacci **generator** | [src/fibonacci.ts](src/fibonacci.ts) | [test/fibonacci.spec.ts](test/fibonacci.spec.ts) | [cli/fibonacci.ts](cli/fibonacci.ts) |
| Take n elements from a **generic** generator | [src/take.ts](src/take.ts) | [test/fibonacci.spec.ts](test/take.spec.ts) | [cli/take.ts](cli/take.ts) |
## Usage
### Run cli examples
```bash
npx tsx cli/fibonacci.ts
```
### Run tests
> See [.mocharc.json](.mocharc.json)
```bash
# run all tests
npm run test
# run single test file
npm run test test/pow.spec.ts
```
### Check test coverage
> See [.nycrc](.nycrc)
```bash
# run all tests
npm run coverage
```
### Bundling
See [tsup.config.ts](tsup.config.ts), [package.json - main, module, types and exports](package.json) :
```bash
npm run build
```
It allows :
* Usage in [index.html](index.html)
* Usage with `import` syntax (ES module) :
```js
import {pow} from '@mborne/ts-examples';
console.log(pow(10,3));
```
* Usage with `require` syntax (CommonJS) :
```js
const pow = require('@mborne/ts-examples').pow;
console.log(pow(10,3));
```
## Credits
Bunding method taken from [Turfjs](https://github.com/Turfjs/turf/blob/master/tsup.config.ts)
## License
[MIT](LICENSE)