Skip to content

Commit

Permalink
chore: add "esbuild" example (#119)
Browse files Browse the repository at this point in the history
* chore: add esbuild example

* chore: remove `.gitignore` file

Co-authored-by: Luke Edwards <[email protected]>
  • Loading branch information
osdevisnot and lukeed committed Jul 13, 2021
1 parent 271b7f1 commit d56753e
Show file tree
Hide file tree
Showing 6 changed files with 90 additions and 0 deletions.
11 changes: 11 additions & 0 deletions examples/esbuild/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"private": true,
"scripts": {
"test": "uvu -r esbuild-register tests"
},
"devDependencies": {
"esbuild": "0.12.15",
"esbuild-register": "2.6.0",
"uvu": "^0.5.1"
}
}
11 changes: 11 additions & 0 deletions examples/esbuild/src/math.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
export function sum(a: number, b: number): number {
return a + b;
}

export function div(a: number, b: number): number {
return a / b;
}

export function mod(a: number, b: number): number {
return a % b;
}
7 changes: 7 additions & 0 deletions examples/esbuild/src/utils.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
export function capitalize(str: string): string {
return str[0].toUpperCase() + str.substring(1);
}

export function dashify(str: string): string {
return str.replace(/([a-zA-Z])(?=[A-Z\d])/g, '$1-').toLowerCase();
}
26 changes: 26 additions & 0 deletions examples/esbuild/tests/math.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import { test } from 'uvu';
import * as assert from 'uvu/assert';
import * as math from '../src/math';

test('sum', () => {
assert.type(math.sum, 'function');
assert.is(math.sum(1, 2), 3);
assert.is(math.sum(-1, -2), -3);
assert.is(math.sum(-1, 1), 0);
});

test('div', () => {
assert.type(math.div, 'function');
assert.is(math.div(1, 2), 0.5);
assert.is(math.div(-1, -2), 0.5);
assert.is(math.div(-1, 1), -1);
});

test('mod', () => {
assert.type(math.mod, 'function');
assert.is(math.mod(1, 2), 1);
assert.is(math.mod(-3, -2), -1);
assert.is(math.mod(7, 4), 3);
});

test.run();
18 changes: 18 additions & 0 deletions examples/esbuild/tests/utils.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import { test } from 'uvu';
import * as assert from 'uvu/assert';
import * as utils from '../src/utils';

test('capitalize', () => {
assert.type(utils.capitalize, 'function');
assert.is(utils.capitalize('hello'), 'Hello');
assert.is(utils.capitalize('foo bar'), 'Foo bar');
});

test('dashify', () => {
assert.type(utils.dashify, 'function');
assert.is(utils.dashify('fooBar'), 'foo-bar');
assert.is(utils.dashify('FooBar'), 'foo-bar');
assert.is(utils.dashify('foobar'), 'foobar');
});

test.run();
17 changes: 17 additions & 0 deletions examples/esbuild/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
{
"compilerOptions": {
"outDir": "build",
"target": "esnext",
"module": "esnext",
"noImplicitAny": true,
"moduleResolution": "node",
"forceConsistentCasingInFileNames": true
},
"include": [
"@types/**/*",
"src/**/*"
],
"exclude": [
"node_modules"
]
}

0 comments on commit d56753e

Please sign in to comment.