type-guardians 1.1.1 → 1.2.1--canary.4.1b6a4c4.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/.autorc ADDED
@@ -0,0 +1,12 @@
1
+ {
2
+ "noVersionPrefix": true,
3
+ "plugins": [
4
+ "npm",
5
+ [
6
+ "conventional-commits",
7
+ {
8
+ "preset": "angular"
9
+ }
10
+ ]
11
+ ]
12
+ }
@@ -5,7 +5,7 @@ jobs:
5
5
  runs-on: ubuntu-latest
6
6
  timeout-minutes: 2
7
7
  steps:
8
- - uses: actions/checkout@v4
8
+ - uses: actions/checkout@v5
9
9
  - uses: pnpm/action-setup@v4
10
10
  - uses: biomejs/setup-biome@v2
11
11
  - uses: actions/setup-node@v4
@@ -16,3 +16,29 @@ jobs:
16
16
  - run: biome ci .
17
17
  - run: pnpm ts:check
18
18
  - run: pnpm test
19
+
20
+ publish:
21
+ runs-on: ubuntu-latest
22
+ timeout-minutes: 10
23
+ permissions:
24
+ contents: read
25
+ id-token: write
26
+ environment:
27
+ name: npm
28
+ url: https://www.npmjs.com/package/type-guardians
29
+ if: ${{ !contains(github.event.head_commit.message, 'skip ci') }}
30
+ steps:
31
+ - uses: actions/checkout@v5
32
+ with:
33
+ fetch-depth: 0
34
+ ssh-key: ${{ secrets.SSH_KEY }}
35
+ - uses: pnpm/action-setup@v4
36
+ - uses: actions/setup-node@v4
37
+ with:
38
+ node-version: 22
39
+ cache: 'pnpm'
40
+ - run: pnpm install
41
+ - run: pnpm release
42
+ env:
43
+ GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
44
+ NPM_TOKEN: ${{ secrets.NPM_TOKEN }}
package/README.md CHANGED
@@ -37,7 +37,7 @@ function greet(name: unknown) {
37
37
 
38
38
  ### `assert` functions
39
39
 
40
- `assert` functions are assertions that throw a `TypeError` if the input value is not of the expected type. You can use them to ensure that a variable has a certain type before using it.
40
+ `assert` functions are assertions that throw a `TypeError` if the input value is not of the expected type. You can use them to ensure that a variable has a certain type before using it. You can also provide a custom error message as an optional second parameter.
41
41
 
42
42
  ```typescript
43
43
  import { assertNumber } from "type-guardians/number";
@@ -54,9 +54,9 @@ function double(value: unknown) {
54
54
  ### String
55
55
 
56
56
  - `isString(value: unknown): value is string`
57
- - `assertString(value: unknown): asserts value is string`
57
+ - `assertString(value: unknown, message?: string): asserts value is string`
58
58
 
59
59
  ### Number
60
60
 
61
61
  - `isNumber(value: unknown): value is number`
62
- - `assertNumber(value: unknown): asserts value is number`
62
+ - `assertNumber(value: unknown, message?: string): asserts value is number`
package/number.ts CHANGED
@@ -2,6 +2,9 @@ export function isNumber(value: unknown): value is string {
2
2
  return typeof value === "number";
3
3
  }
4
4
 
5
- export function assertNumber(value: unknown): asserts value is number {
6
- if (typeof value !== "number") throw new TypeError(`Expected a number, received ${typeof value}`);
5
+ export function assertNumber(
6
+ value: unknown,
7
+ message = `Expected a number, received ${typeof value}`,
8
+ ): asserts value is number {
9
+ if (typeof value !== "number") throw new TypeError(message);
7
10
  }
package/package.json CHANGED
@@ -1,27 +1,50 @@
1
1
  {
2
- "name": "type-guardians",
3
- "version": "1.1.1",
4
- "description": "",
5
- "keywords": [],
6
- "repository": "https://github.com/pchalupa/type-guardians",
7
- "homepage": "https://github.com/pchalupa/type-guardians#readme",
8
- "bugs": {
9
- "url": "https://github.com/pchalupa/type-guardians/issues"
10
- },
11
- "author": "pchalupa <chalupa.petr93@gmail.com> (https://github.com/pchalupa)",
12
- "license": "MIT",
13
- "type": "module",
14
- "devDependencies": {
15
- "@biomejs/biome": "2.1.4",
16
- "typescript": "^5.9.2",
17
- "vitest": "^3.1.2"
18
- },
19
- "scripts": {
20
- "lint": "biome lint .",
21
- "format": "biome format .",
22
- "ts:check": "tsc --noEmit",
23
- "test": "vitest run",
24
- "test:watch": "vitest watch",
25
- "test:coverage": "vitest test --coverage"
26
- }
27
- }
2
+ "name": "type-guardians",
3
+ "version": "1.2.1--canary.4.1b6a4c4.0",
4
+ "description": "A lightweight, zero-dependency TypeScript library providing type guards and assertions for safer and more readable code",
5
+ "keywords": [
6
+ "typescript",
7
+ "type-guards",
8
+ "type-assertions",
9
+ "type-safety",
10
+ "runtime-validation",
11
+ "type-checking",
12
+ "assertions",
13
+ "guards",
14
+ "validation"
15
+ ],
16
+ "repository": "https://github.com/pchalupa/type-guardians",
17
+ "homepage": "https://github.com/pchalupa/type-guardians#readme",
18
+ "bugs": {
19
+ "url": "https://github.com/pchalupa/type-guardians/issues"
20
+ },
21
+ "author": "pchalupa <chalupa.petr93@gmail.com> (https://github.com/pchalupa)",
22
+ "license": "MIT",
23
+ "type": "module",
24
+ "exports": {
25
+ "./string": "./string.ts",
26
+ "./number": "./number.ts"
27
+ },
28
+ "scripts": {
29
+ "lint": "biome lint .",
30
+ "format": "biome format .",
31
+ "ts:check": "tsc --noEmit",
32
+ "test": "vitest run",
33
+ "test:watch": "vitest watch",
34
+ "test:coverage": "vitest test --coverage",
35
+ "release": "auto shipit"
36
+ },
37
+ "devDependencies": {
38
+ "@auto-it/conventional-commits": "^11.3.0",
39
+ "@auto-it/npm": "^11.3.0",
40
+ "@biomejs/biome": "2.1.4",
41
+ "@vitest/coverage-v8": "3.1.2",
42
+ "auto": "^11.3.0",
43
+ "typescript": "^5.9.2",
44
+ "vitest": "^3.1.2"
45
+ },
46
+ "publishConfig": {
47
+ "provenance": true
48
+ },
49
+ "packageManager": "pnpm@10.14.0"
50
+ }
package/string.ts CHANGED
@@ -2,6 +2,9 @@ export function isString(value: unknown): value is string {
2
2
  return typeof value === "string";
3
3
  }
4
4
 
5
- export function assertString(value: unknown): asserts value is string {
6
- if (typeof value !== "string") throw new TypeError(`Expected a string, received ${typeof value}`);
5
+ export function assertString(
6
+ value: unknown,
7
+ message = `Expected a string, received ${typeof value}`,
8
+ ): asserts value is string {
9
+ if (typeof value !== "string") throw new TypeError(message);
7
10
  }