-
-
Notifications
You must be signed in to change notification settings - Fork 99
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore(examples): add "typescript.module" demo;
- Similar to "typescript" example, but uses `"type": "module"` and source files only include ".js" files with ESM syntax. This matches the scenario(s) presented in #123 Also includes two approaches for solving this problem; see npm "scripts" section. Closes #123
- Loading branch information
Showing
8 changed files
with
112 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
/build |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
// NOTE: used for "test:alt" script only | ||
// @see https://github.com/lukeed/loadr | ||
export const loaders = ['tsm']; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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.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(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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.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(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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" | ||
] | ||
} |