is-kit 1.0.1 → 1.0.2

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 (2) hide show
  1. package/README.md +42 -19
  2. package/package.json +1 -1
package/README.md CHANGED
@@ -16,7 +16,7 @@
16
16
  Lightweight, zero-dependency toolkit for building `isFoo` style type guards in TypeScript.
17
17
  Runtime-safe 🛡️, composable 🧩, and ergonomic ✨.
18
18
 
19
- [👉 See full document](https://is-kit-docs.vercel.app/)
19
+ [📚 full documentation](https://is-kit-docs.vercel.app/)
20
20
 
21
21
  ## Why?
22
22
 
@@ -60,32 +60,55 @@ Build `is` functions from tiny, composable pieces:
60
60
  ```ts
61
61
  import {
62
62
  define,
63
- predicateToRefine,
64
63
  and,
65
64
  or,
66
65
  not,
67
- isString,
66
+ struct,
67
+ oneOfValues,
68
+ optional,
68
69
  isNumber,
70
+ isString,
71
+ predicateToRefine,
69
72
  } from 'is-kit';
70
73
 
71
- // 1. define small pieces
72
- const isShortString = define<string>(
73
- (value) => isString(value) && value.length <= 3
74
+ // Define small guards
75
+ const isShortString = define<string>((v) => isString(v) && v.length <= 3);
76
+ const isPositive = and(
77
+ isNumber,
78
+ predicateToRefine<number>((v) => v > 0)
74
79
  );
75
- const isPositive = predicateToRefine<number>((num) => num > 0);
76
-
77
- // 2. compose them
78
- const isPositiveNumber = and(isNumber, isPositive);
79
- const shortOrPositive = or(isShortString, isPositiveNumber);
80
- const isOther = not(shortOrPositive);
81
80
 
82
- // 3. use them
83
- shortOrPositive('foo'); // true
84
- shortOrPositive(42); // true
85
- isOther(false); // true
81
+ // Combine them (or / not)
82
+ const isShortOrPositive = or(isShortString, isPositive);
83
+ const isOther = not(isShortOrPositive);
84
+
85
+ // Define object shapes
86
+ const isRole = oneOfValues(['admin', 'member'] as const);
87
+ const isUser = struct({
88
+ id: isPositive, // number > 0
89
+ name: isString, // string
90
+ role: isRole, // 'admin' | 'member'
91
+ nickname: optional(isShortString), // string <= 3 | undefined
92
+ });
93
+
94
+ // Use them
95
+ isPositive(3); // true
96
+ isShortOrPositive('foo'); // true
97
+ isShortOrPositive(false); // false
98
+ isOther('x'); // true
99
+
100
+ const maybeUser: unknown = { id: 7, name: 'Rin', role: 'admin' };
101
+ if (isUser(maybeUser)) {
102
+ // The type is narrowed inside this block
103
+ maybeUser.role; // 'admin' | 'member'
104
+ maybeUser.nickname?.toUpperCase();
105
+ }
86
106
  ```
87
107
 
88
- These primitives plug into higher-level combinators like `struct` when you need to shape objects.
108
+ Composed guards stay reusable:
109
+ `isPositive` can be used standalone or as part of a `struct` definition.
110
+
111
+ When validating complex shapes, reach for `struct` — and friends like `arrayOf`, `recordOf`, or `oneOf`.
89
112
 
90
113
  ## Core Ideas
91
114
 
@@ -96,9 +119,9 @@ These primitives plug into higher-level combinators like `struct` when you need
96
119
 
97
120
  ## API Reference
98
121
 
99
- [👉 See full document](https://is-kit-docs.vercel.app/)
122
+ For full API details and runnable examples, visit
100
123
 
101
- 👉 See the docs app under `docs/` (API Reference section). Each helper is documented with runnable examples.
124
+ [📚 See full document](https://is-kit-docs.vercel.app/)
102
125
 
103
126
  ## Development
104
127
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "is-kit",
3
- "version": "1.0.1",
3
+ "version": "1.0.2",
4
4
  "description": "Make 'isXXX' easier. Let's make your code type safe and more readable!",
5
5
  "main": "./dist/index.js",
6
6
  "module": "./dist/index.mjs",