is-kit 1.0.1 → 1.0.3

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/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/dist/index.js CHANGED
@@ -144,7 +144,7 @@ var isObject = define(
144
144
  var isPlainObject = define((value) => {
145
145
  if (!isObject(value)) return false;
146
146
  const proto = Object.getPrototypeOf(value);
147
- return proto === Object.prototype || proto === null;
147
+ return proto === null || Object.getPrototypeOf(proto) === null;
148
148
  });
149
149
  var isArray = define(Array.isArray);
150
150
  var isDate = define(
@@ -159,15 +159,18 @@ var isMap = define(
159
159
  var isSet = define(
160
160
  (value) => getTag(value) === "[object Set]"
161
161
  );
162
- var isPromiseLike = define(
163
- (value) => !!value && typeof value.then === "function"
164
- );
165
- var isIterable = define(
166
- (value) => !!value && typeof value === "object" && typeof value[Symbol.iterator] === "function"
167
- );
168
- var isAsyncIterable = define(
169
- (value) => !!value && typeof value === "object" && typeof value[Symbol.asyncIterator] === "function"
170
- );
162
+ var isPromiseLike = define((value) => {
163
+ if (!isObject(value) && !isFunction(value)) return false;
164
+ return typeof value.then === "function";
165
+ });
166
+ var isIterable = define((value) => {
167
+ if (!isObject(value) && !isFunction(value)) return false;
168
+ return typeof value[Symbol.iterator] === "function";
169
+ });
170
+ var isAsyncIterable = define((value) => {
171
+ if (!isObject(value) && !isFunction(value)) return false;
172
+ return typeof value[Symbol.asyncIterator] === "function";
173
+ });
171
174
  var isArrayBuffer = define(
172
175
  (value) => getTag(value) === "[object ArrayBuffer]"
173
176
  );
package/dist/index.mjs CHANGED
@@ -69,7 +69,7 @@ var isObject = define(
69
69
  var isPlainObject = define((value) => {
70
70
  if (!isObject(value)) return false;
71
71
  const proto = Object.getPrototypeOf(value);
72
- return proto === Object.prototype || proto === null;
72
+ return proto === null || Object.getPrototypeOf(proto) === null;
73
73
  });
74
74
  var isArray = define(Array.isArray);
75
75
  var isDate = define(
@@ -84,15 +84,18 @@ var isMap = define(
84
84
  var isSet = define(
85
85
  (value) => getTag(value) === "[object Set]"
86
86
  );
87
- var isPromiseLike = define(
88
- (value) => !!value && typeof value.then === "function"
89
- );
90
- var isIterable = define(
91
- (value) => !!value && typeof value === "object" && typeof value[Symbol.iterator] === "function"
92
- );
93
- var isAsyncIterable = define(
94
- (value) => !!value && typeof value === "object" && typeof value[Symbol.asyncIterator] === "function"
95
- );
87
+ var isPromiseLike = define((value) => {
88
+ if (!isObject(value) && !isFunction(value)) return false;
89
+ return typeof value.then === "function";
90
+ });
91
+ var isIterable = define((value) => {
92
+ if (!isObject(value) && !isFunction(value)) return false;
93
+ return typeof value[Symbol.iterator] === "function";
94
+ });
95
+ var isAsyncIterable = define((value) => {
96
+ if (!isObject(value) && !isFunction(value)) return false;
97
+ return typeof value[Symbol.asyncIterator] === "function";
98
+ });
96
99
  var isArrayBuffer = define(
97
100
  (value) => getTag(value) === "[object ArrayBuffer]"
98
101
  );
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "is-kit",
3
- "version": "1.0.1",
3
+ "version": "1.0.3",
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",