GoogleFeud/ts-runtime-checks (ts-runtime-checks)
### [`v0.4.0`](https://togithub.com/GoogleFeud/ts-runtime-checks/releases/tag/v0.4.0)
[Compare Source](https://togithub.com/GoogleFeud/ts-runtime-checks/compare/v0.3.3...v0.4.0)
#### Additions
- A `createMatch` utility function that creates pattern-matching functions.
```ts
// We want the match function to return a string and to accept a number
const resolver = createMatch([
// Match arm which catches the values 0 or 1
(_: 0 | 1) => "not many",
// Match arm which catches any number less than 9
(_: Max<9>) => "a few",
// Match arm which catches any number that hasn't already been caught
(_: number) => "lots"
]);
// Transpiles to:
const resolver = value_1 => {
if (typeof value_1 === "number") {
if (value_1 === 1 || value_1 === 0) return "not many";
else if (value_1 < 9) return "a few";
else return "lots";
}
};
```
- `Eq` utility marker which compares a value to an expression, skipping validation of the value type.
#### Changes
- `Min`, `Max`, `Float`, and `Int` utility markers now combine with the `number` type by default, so doing `number & Min<3>` for example is excessive.
- `Matches` utility marker now combines with the `string` type by default.
#### Bug fixes
- Unions that include the `boolean` type no longer generate excessive code.
- Random comments no longer get added to output ([#26](https://togithub.com/GoogleFeud/ts-runtime-checks/issues/26))
### [`v0.3.3`](https://togithub.com/GoogleFeud/ts-runtime-checks/releases/tag/v0.3.3)
[Compare Source](https://togithub.com/GoogleFeud/ts-runtime-checks/compare/v0.3.2...v0.3.3)
#### Additions
- `rawError` option on `check` function.
- Raw error data now includes `ID` and `Value` from `Check`s.
#### Bug fixes
- Fixes [#28](https://togithub.com/GoogleFeud/ts-runtime-checks/issues/28).
- Fixes [#29](https://togithub.com/GoogleFeud/ts-runtime-checks/issues/29).
- Fixes [#30](https://togithub.com/GoogleFeud/ts-runtime-checks/issues/30).
### [`v0.3.2`](https://togithub.com/GoogleFeud/ts-runtime-checks/releases/tag/v0.3.2)
[Compare Source](https://togithub.com/GoogleFeud/ts-runtime-checks/compare/v0.3.1...v0.3.2)
#### Additions
- You can use the `Assert` marker in class methods, constructors and getters/setters.
#### Bug fixes
- Fixes [#25](https://togithub.com/GoogleFeud/ts-runtime-checks/issues/25)
### [`v0.3.1`](https://togithub.com/GoogleFeud/ts-runtime-checks/releases/tag/v0.3.1)
[Compare Source](https://togithub.com/GoogleFeud/ts-runtime-checks/compare/v0.3.0...v0.3.1)
#### Bug fixes
- Fixes [#23](https://togithub.com/GoogleFeud/ts-runtime-checks/issues/23).
- The generation of recursive functions for types with type parameters is now correct:
```ts
interface Value {
val1?: Value,
val2?: Value,
value: T
}
const isValid = is>(...);
// Transpiles to:
function value_6(param_4) { return typeof param_4 === "object" && param_4 !== null && typeof param_4.value === "string" && (param_4.val1 === undefined || value_6(param_4.val1)) && (param_4.val2 === undefined || value_6(param_4.val2)); }
function value_7(param_5) { return typeof param_5 === "object" && param_5 !== null && typeof param_5.value === "number" && (param_5.val1 === undefined || value_6(param_5.val1)) && (param_5.val2 === undefined || value_7(param_5.val2)); }
const isValid = value_7(...);
```
### [`v0.3.0`](https://togithub.com/GoogleFeud/ts-runtime-checks/releases/tag/v0.3.0)
[Compare Source](https://togithub.com/GoogleFeud/ts-runtime-checks/compare/v0.2.0...v0.3.0)
#### Breaking changes
- Removed the `If` utility marker.
- Removed the `Str` utility marker.
- Removed the `Num` utility marker.
- Removed the `Arr` utility marker.
- You can no longer use JSDoc tags to specify extra checks.
#### Additions
- A new utility type, `Check` which is a lot more flexible than `If`.
- Allows you to provide a custom error message.
- You can now use the `$parent` function to access the value's parent object.
- You can chain checks with the `&` (intersection) operator.
```ts
function test(value: Assert & Max<10>>) {
}
// Transpiles to:
function test(value) {
if (typeof value !== "number" || Number.isInteger(value) || value < 1 || value > 10)
throw new Error("Expected value to be a number, to be a float, to be greater than 1, to be less than 10");
}
```
- The library provides built-in `Check`s: `Min`, `Max`, `Int`, `Float`, `MinLen`, `MaxLen`, `Length`, `Matches`, `Not`, and `Or`.
#### Bug fixes
- Fixes [#16](https://togithub.com/GoogleFeud/ts-runtime-checks/issues/16)
- Fixes issue with `check` utility function generating code that may throw an error
Configuration
📅 Schedule: Branch creation - At any time (no schedule defined), Automerge - At any time (no schedule defined).
🚦 Automerge: Enabled.
♻ Rebasing: Whenever PR becomes conflicted, or you tick the rebase/retry checkbox.
🔕 Ignore: Close this PR and you won't be reminded about this update again.
[ ] If you want to rebase/retry this PR, check this box
This PR has been generated by Mend Renovate. View repository job log here.
This PR contains the following updates:
0.2.0
->0.4.0
Release Notes
GoogleFeud/ts-runtime-checks (ts-runtime-checks)
### [`v0.4.0`](https://togithub.com/GoogleFeud/ts-runtime-checks/releases/tag/v0.4.0) [Compare Source](https://togithub.com/GoogleFeud/ts-runtime-checks/compare/v0.3.3...v0.4.0) #### Additions - A `createMatch` utility function that creates pattern-matching functions. ```ts // We want the match function to return a string and to accept a number const resolver = createMatchConfiguration
📅 Schedule: Branch creation - At any time (no schedule defined), Automerge - At any time (no schedule defined).
🚦 Automerge: Enabled.
♻ Rebasing: Whenever PR becomes conflicted, or you tick the rebase/retry checkbox.
🔕 Ignore: Close this PR and you won't be reminded about this update again.
This PR has been generated by Mend Renovate. View repository job log here.