diff --git a/examples/typescript.module/.gitignore b/examples/typescript.module/.gitignore new file mode 100644 index 0000000..796b96d --- /dev/null +++ b/examples/typescript.module/.gitignore @@ -0,0 +1 @@ +/build diff --git a/examples/typescript.module/loadr.mjs b/examples/typescript.module/loadr.mjs new file mode 100644 index 0000000..30a8a8c --- /dev/null +++ b/examples/typescript.module/loadr.mjs @@ -0,0 +1,3 @@ +// NOTE: used for "test:alt" script only +// @see https://github.com/lukeed/loadr +export const loaders = ['tsm']; diff --git a/examples/typescript.module/package.json b/examples/typescript.module/package.json new file mode 100644 index 0000000..1c366b0 --- /dev/null +++ b/examples/typescript.module/package.json @@ -0,0 +1,13 @@ +{ + "private": true, + "type": "module", + "scripts": { + "test": "tsm node_modules/uvu/bin.js tests", + "test:alt": "loadr -- uvu tests" + }, + "devDependencies": { + "loadr": "^0.1.1", + "tsm": "^2.0.0", + "uvu": "^0.5.1" + } +} diff --git a/examples/typescript.module/src/math.js b/examples/typescript.module/src/math.js new file mode 100644 index 0000000..1345e83 --- /dev/null +++ b/examples/typescript.module/src/math.js @@ -0,0 +1,17 @@ +/** + * @param {number} a + * @param {number} b + */ +export const sum = (a, b) => a + b; + +/** + * @param {number} a + * @param {number} b + */ +export const div = (a, b) => a / b; + +/** + * @param {number} a + * @param {number} b + */ +export const mod = (a, b) => a % b; diff --git a/examples/typescript.module/src/utils.js b/examples/typescript.module/src/utils.js new file mode 100644 index 0000000..8f87574 --- /dev/null +++ b/examples/typescript.module/src/utils.js @@ -0,0 +1,13 @@ +/** + * @param {string} str + */ +export function capitalize(str) { + return str[0].toUpperCase() + str.substring(1); +} + +/** + * @param {string} str + */ +export function dashify(str) { + return str.replace(/([a-zA-Z])(?=[A-Z\d])/g, '$1-').toLowerCase(); +} diff --git a/examples/typescript.module/tests/math.ts b/examples/typescript.module/tests/math.ts new file mode 100644 index 0000000..d90c0d8 --- /dev/null +++ b/examples/typescript.module/tests/math.ts @@ -0,0 +1,26 @@ +import { test } from 'uvu'; +import * as assert from 'uvu/assert'; +import * as math from '../src/math.js'; + +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(); diff --git a/examples/typescript.module/tests/utils.ts b/examples/typescript.module/tests/utils.ts new file mode 100644 index 0000000..516954b --- /dev/null +++ b/examples/typescript.module/tests/utils.ts @@ -0,0 +1,18 @@ +import { test } from 'uvu'; +import * as assert from 'uvu/assert'; +import * as utils from '../src/utils.js'; + +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(); diff --git a/examples/typescript.module/tsconfig.json b/examples/typescript.module/tsconfig.json new file mode 100644 index 0000000..f1e7570 --- /dev/null +++ b/examples/typescript.module/tsconfig.json @@ -0,0 +1,21 @@ +{ + "compilerOptions": { + "strict": true, + "allowJs": true, + "target": "esnext", + "noImplicitAny": true, + "moduleResolution": "node", + "forceConsistentCasingInFileNames": true, + "alwaysStrict": true, + "module": "esnext", + "checkJs": true, + "noEmit": true + }, + "include": [ + "src", + "tests" + ], + "exclude": [ + "node_modules" + ] +}