type-guardians 1.1.0 → 1.1.1

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.
Files changed (3) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +62 -1
  3. package/package.json +1 -1
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2025 Petr Chalupa
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md CHANGED
@@ -1 +1,62 @@
1
- # Type Guardian
1
+ # Type Guardian
2
+
3
+ Type Guardian is a lightweight, zero-dependency TypeScript library that provides a collection of type guards and assertions to help you write safer and more readable code.
4
+
5
+ ## Installation
6
+
7
+ Install the package using your favorite package manager:
8
+
9
+ ```bash
10
+ npm install type-guardians
11
+ # or
12
+ yarn add type-guardians
13
+ # or
14
+ pnpm add type-guardians
15
+ ```
16
+
17
+ ## Usage
18
+
19
+ Type Guardian offers two types of functions for each data type: `is` functions for type guarding and `assert` functions for type assertions.
20
+
21
+ ### `is` functions
22
+
23
+ `is` functions are type guards that return a boolean value indicating whether the input value is of the expected type. You can use them in `if` statements to narrow down the type of a variable.
24
+
25
+ ```typescript
26
+ import { isString } from "type-guardians/string";
27
+
28
+ function greet(name: unknown) {
29
+ if (isString(name)) {
30
+ // name is now of type string
31
+ console.log(`Hello, ${name}!`);
32
+ } else {
33
+ console.log("Hello, guest!");
34
+ }
35
+ }
36
+ ```
37
+
38
+ ### `assert` functions
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.
41
+
42
+ ```typescript
43
+ import { assertNumber } from "type-guardians/number";
44
+
45
+ function double(value: unknown) {
46
+ assertNumber(value);
47
+ // value is now of type number
48
+ return value * 2;
49
+ }
50
+ ```
51
+
52
+ ## API
53
+
54
+ ### String
55
+
56
+ - `isString(value: unknown): value is string`
57
+ - `assertString(value: unknown): asserts value is string`
58
+
59
+ ### Number
60
+
61
+ - `isNumber(value: unknown): value is number`
62
+ - `assertNumber(value: unknown): asserts value is number`
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "type-guardians",
3
- "version": "1.1.0",
3
+ "version": "1.1.1",
4
4
  "description": "",
5
5
  "keywords": [],
6
6
  "repository": "https://github.com/pchalupa/type-guardians",