-
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Output ESM format to browsers instead of IIFE
- Loading branch information
Showing
4 changed files
with
26 additions
and
34 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 |
---|---|---|
|
@@ -17,13 +17,13 @@ A [fluent API](https://en.wikipedia.org/wiki/Fluent_interface) for enforcing | |
To get started, add this dependency: | ||
|
||
```shell | ||
npm install --save @cowwoc/[email protected].0 | ||
npm install --save @cowwoc/[email protected].1 | ||
``` | ||
|
||
or [pnpm](https://pnpm.io/): | ||
|
||
```shell | ||
pnpm add @cowwoc/[email protected].0 | ||
pnpm add @cowwoc/[email protected].1 | ||
``` | ||
|
||
The contents of the API classes depend on which [modules](wiki/Supported_Libraries.md) are enabled. | ||
|
@@ -40,29 +40,29 @@ class Address | |
|
||
class PublicAPI | ||
{ | ||
constructor(name: string | null, age: number, address: Address | undefined) | ||
{ | ||
// To validate user input, cast them to "unknown" prior to type-checks. | ||
requireThat(name as unknown, "name").isString().length().isBetween(1, 30); | ||
requireThat(age as unknown, "age").isNumber().isBetween(18, 30); | ||
|
||
// Methods that conduct runtime type-checks, such as isString() or isNotNull(), update the | ||
// compile-time type returned by getActual(). | ||
const nameIsString: string = requireThat(name as unknown, "name").isString().getActual(); | ||
const address: Address = requireThat(address as unknown, "address").isInstance(Address).getActual(); | ||
} | ||
constructor(name: string | null, age: number, address: Address | undefined) | ||
{ | ||
// To validate user input, cast them to "unknown" prior to type-checks. | ||
requireThat(name as unknown, "name").isString().length().isBetween(1, 30); | ||
requireThat(age as unknown, "age").isNumber().isBetween(18, 30); | ||
|
||
// Methods that conduct runtime type-checks, such as isString() or isNotNull(), update the | ||
// compile-time type returned by getActual(). | ||
const nameIsString: string = requireThat(name as unknown, "name").isString().getActual(); | ||
const address: Address = requireThat(address as unknown, "address").isInstance(Address).getActual(); | ||
} | ||
} | ||
|
||
class PrivateAPI | ||
{ | ||
public static toCamelCase(text): string | ||
{ | ||
// Trusted input does not need to be casted to "unknown". The input type will be inferred | ||
// and runtime checks will be skipped. Notice the lack of isString() or isNumber() invocations | ||
// in the following code. | ||
assertThat(r => r.requireThat(name, "name").length().isBetween(1, 30)); | ||
assertThat(r => r.requireThat(age, "age").isBetween(18, 30)); | ||
} | ||
public static toCamelCase(text): string | ||
{ | ||
// Trusted input does not need to be casted to "unknown". The input type will be inferred | ||
// and runtime checks will be skipped. Notice the lack of isString() or isNumber() invocations | ||
// in the following code. | ||
assertThat(r => r.requireThat(name, "name").length().isBetween(1, 30)); | ||
assertThat(r => r.requireThat(age, "age").isBetween(18, 30)); | ||
} | ||
} | ||
``` | ||
|
||
|
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
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
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