is-kit 1.11.3 → 1.11.5

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
@@ -170,9 +170,24 @@ const isSlug = (value: unknown): value is string =>
170
170
  isString(value) && /^[a-z0-9-]+$/.test(value);
171
171
  ```
172
172
 
173
- For AI agents or repository-wide conventions, copy
174
- [docs/agent-rules.md](./docs/agent-rules.md) into the consumer repository's
175
- agent instructions.
173
+ ### AI agent setup
174
+
175
+ Add the recommended `is-kit` selection and usage rules to a repository's AI
176
+ agent instructions:
177
+
178
+ ```bash
179
+ npx --yes is-kit@latest init-agent
180
+ ```
181
+
182
+ The command updates an `is-kit`-managed section in `AGENTS.md` without
183
+ overwriting other instructions. If a repository uses `CLAUDE.md`, target it
184
+ explicitly:
185
+
186
+ ```bash
187
+ npx --yes is-kit@latest init-agent --target claude
188
+ ```
189
+
190
+ See [docs/agent-rules.md](./docs/agent-rules.md) for the installed rules.
176
191
 
177
192
  ## ⌚ A 30-second Mental Model
178
193
 
package/bin/is-kit.mjs ADDED
@@ -0,0 +1,103 @@
1
+ #!/usr/bin/env node
2
+
3
+ import { access, readFile, writeFile } from 'node:fs/promises';
4
+ import { dirname, resolve } from 'node:path';
5
+ import { fileURLToPath } from 'node:url';
6
+
7
+ const START_MARKER = '<!-- is-kit-agent-rules:start -->';
8
+ const END_MARKER = '<!-- is-kit-agent-rules:end -->';
9
+ const TARGET_FILES = {
10
+ agents: 'AGENTS.md',
11
+ claude: 'CLAUDE.md'
12
+ };
13
+
14
+ const usage = `Usage: is-kit init-agent [--target agents|claude]
15
+
16
+ Adds or updates the is-kit rules in AGENTS.md (default) or CLAUDE.md.`;
17
+
18
+ const isHelpRequested = (args) =>
19
+ args.includes('--help') || args.includes('-h');
20
+
21
+ const fileExists = async (path) => {
22
+ try {
23
+ await access(path);
24
+ return true;
25
+ } catch {
26
+ return false;
27
+ }
28
+ };
29
+
30
+ const parseTarget = (args) => {
31
+ const targetIndex = args.indexOf('--target');
32
+
33
+ if (targetIndex === -1) {
34
+ return 'agents';
35
+ }
36
+
37
+ const target = args[targetIndex + 1];
38
+ if (!Object.hasOwn(TARGET_FILES, target)) {
39
+ throw new Error(`Unknown target: ${target ?? '(missing)'}`);
40
+ }
41
+
42
+ return target;
43
+ };
44
+
45
+ const updateManagedSection = (existingContent, rules) => {
46
+ const section = `${START_MARKER}\n${rules.trim()}\n${END_MARKER}`;
47
+ const startIndex = existingContent.indexOf(START_MARKER);
48
+ const endIndex = existingContent.indexOf(END_MARKER);
49
+
50
+ if (startIndex === -1 && endIndex === -1) {
51
+ const separator = existingContent.trim().length === 0 ? '' : '\n\n';
52
+ return `${existingContent.trimEnd()}${separator}${section}\n`;
53
+ }
54
+
55
+ if (startIndex === -1 || endIndex === -1 || endIndex < startIndex) {
56
+ throw new Error('The existing is-kit managed section is malformed.');
57
+ }
58
+
59
+ const afterSection = endIndex + END_MARKER.length;
60
+ return `${existingContent.slice(0, startIndex)}${section}${existingContent.slice(afterSection)}`;
61
+ };
62
+
63
+ const initAgent = async (args) => {
64
+ const target = parseTarget(args);
65
+ const targetPath = resolve(process.cwd(), TARGET_FILES[target]);
66
+ const packageRoot = resolve(dirname(fileURLToPath(import.meta.url)), '..');
67
+ const rulesPath = resolve(packageRoot, 'docs/agent-rules.md');
68
+ const rules = await readFile(rulesPath, 'utf8');
69
+ const existingContent = (await fileExists(targetPath))
70
+ ? await readFile(targetPath, 'utf8')
71
+ : '';
72
+
73
+ await writeFile(
74
+ targetPath,
75
+ updateManagedSection(existingContent, rules),
76
+ 'utf8'
77
+ );
78
+ process.stdout.write(
79
+ `Updated ${TARGET_FILES[target]} with is-kit agent rules.\n`
80
+ );
81
+ };
82
+
83
+ const main = async () => {
84
+ const [command, ...args] = process.argv.slice(2);
85
+
86
+ if (command === 'init-agent') {
87
+ if (isHelpRequested(args)) {
88
+ process.stdout.write(`${usage}\n`);
89
+ return;
90
+ }
91
+
92
+ await initAgent(args);
93
+ return;
94
+ }
95
+
96
+ process.stdout.write(`${usage}\n`);
97
+ process.exitCode = command === undefined || command === '--help' ? 0 : 1;
98
+ };
99
+
100
+ main().catch((error) => {
101
+ process.stderr.write(`is-kit: ${error.message}\n`);
102
+ process.exitCode = 1;
103
+ });
package/dist/index.js CHANGED
@@ -119,6 +119,8 @@ var hasOwnPropertyKey = (value, key) => Object.hasOwn(value, key);
119
119
  var hasOwnPropertyKeys = (value, keys) => keys.every((key) => hasOwnPropertyKey(value, key));
120
120
 
121
121
  // src/utils/guard-collections.ts
122
+ var mapEntries = Map.prototype.entries;
123
+ var setValues = Set.prototype.values;
122
124
  var everyIterableValue = (values, predicate) => {
123
125
  for (const value of values) {
124
126
  if (!predicate(value)) return false;
@@ -141,10 +143,15 @@ var everyTupleValue = (values, predicates) => {
141
143
  return true;
142
144
  };
143
145
  var everySetValue = (values, predicate) => everyIterableValue(values, predicate);
146
+ var everyBrandedSetValue = (values, predicate) => everyIterableValue(setValues.call(values), predicate);
144
147
  var everyMapEntry = (values, keyPredicate, valuePredicate) => everyKeyValueEntry(
145
148
  values,
146
149
  (key, value) => keyPredicate(key) && valuePredicate(value)
147
150
  );
151
+ var everyBrandedMapEntry = (values, keyPredicate, valuePredicate) => everyKeyValueEntry(
152
+ mapEntries.call(values),
153
+ (key, value) => keyPredicate(key) && valuePredicate(value)
154
+ );
148
155
  var everyOwnEnumerableEntry = (values, keyPredicate, valuePredicate) => everyIterableValue(
149
156
  Object.keys(values),
150
157
  (key) => keyPredicate(key) && valuePredicate(values[key])
@@ -152,14 +159,6 @@ var everyOwnEnumerableEntry = (values, keyPredicate, valuePredicate) => everyIte
152
159
 
153
160
  // src/utils/object-tags.ts
154
161
  var objectToString = Object.prototype.toString;
155
- var OBJECT_TAG_DATE = "[object Date]";
156
- var OBJECT_TAG_REGEXP = "[object RegExp]";
157
- var OBJECT_TAG_MAP = "[object Map]";
158
- var OBJECT_TAG_SET = "[object Set]";
159
- var OBJECT_TAG_WEAK_MAP = "[object WeakMap]";
160
- var OBJECT_TAG_WEAK_SET = "[object WeakSet]";
161
- var OBJECT_TAG_ARRAY_BUFFER = "[object ArrayBuffer]";
162
- var OBJECT_TAG_DATA_VIEW = "[object DataView]";
163
162
  var OBJECT_TAG_ERROR = "[object Error]";
164
163
  var getTag = (value) => objectToString.call(value);
165
164
 
@@ -167,7 +166,32 @@ var getTag = (value) => objectToString.call(value);
167
166
  var toBooleanPredicates = (predicates) => predicates;
168
167
 
169
168
  // src/core/object.ts
170
- var defineTagGuard = (tag) => define((value) => getTag(value) === tag);
169
+ var BUILTIN_BRAND_SENTINEL = Object.freeze({});
170
+ var getIntrinsicGetter = (prototype, key) => {
171
+ const getter = Object.getOwnPropertyDescriptor(prototype, key)?.get;
172
+ return getter ?? (() => {
173
+ throw new TypeError(`Missing intrinsic getter: ${String(key)}`);
174
+ });
175
+ };
176
+ var defineIntrinsicBrandGuard = (checkBrand) => define((value) => {
177
+ try {
178
+ checkBrand(value);
179
+ return true;
180
+ } catch {
181
+ return false;
182
+ }
183
+ });
184
+ var dateGetTime = Date.prototype.getTime;
185
+ var mapHas = Map.prototype.has;
186
+ var setHas = Set.prototype.has;
187
+ var weakMapHas = WeakMap.prototype.has;
188
+ var weakSetHas = WeakSet.prototype.has;
189
+ var regExpSource = getIntrinsicGetter(RegExp.prototype, "source");
190
+ var arrayBufferByteLength = getIntrinsicGetter(
191
+ ArrayBuffer.prototype,
192
+ "byteLength"
193
+ );
194
+ var dataViewBuffer = getIntrinsicGetter(DataView.prototype, "buffer");
171
195
  var defineOptionalInstanceGuard = (constructor) => constructor === void 0 ? define(() => false) : define(
172
196
  (value) => typeof constructor === "function" && value instanceof constructor
173
197
  );
@@ -187,14 +211,28 @@ var isPlainObject = define((value) => {
187
211
  return proto === null || Object.getPrototypeOf(proto) === null;
188
212
  });
189
213
  var isArray = define(Array.isArray);
190
- var isDate = define(
191
- (value) => getTag(value) === OBJECT_TAG_DATE && !Number.isNaN(value.getTime())
192
- );
193
- var isRegExp = defineTagGuard(OBJECT_TAG_REGEXP);
194
- var isMap = defineTagGuard(OBJECT_TAG_MAP);
195
- var isSet = defineTagGuard(OBJECT_TAG_SET);
196
- var isWeakMap = defineTagGuard(OBJECT_TAG_WEAK_MAP);
197
- var isWeakSet = defineTagGuard(OBJECT_TAG_WEAK_SET);
214
+ var isDate = define((value) => {
215
+ try {
216
+ return !Number.isNaN(dateGetTime.call(value));
217
+ } catch {
218
+ return false;
219
+ }
220
+ });
221
+ var isRegExp = defineIntrinsicBrandGuard(
222
+ (value) => regExpSource.call(value)
223
+ );
224
+ var isMap = defineIntrinsicBrandGuard(
225
+ (value) => mapHas.call(value, BUILTIN_BRAND_SENTINEL)
226
+ );
227
+ var isSet = defineIntrinsicBrandGuard(
228
+ (value) => setHas.call(value, BUILTIN_BRAND_SENTINEL)
229
+ );
230
+ var isWeakMap = defineIntrinsicBrandGuard(
231
+ (value) => weakMapHas.call(value, BUILTIN_BRAND_SENTINEL)
232
+ );
233
+ var isWeakSet = defineIntrinsicBrandGuard(
234
+ (value) => weakSetHas.call(value, BUILTIN_BRAND_SENTINEL)
235
+ );
198
236
  var isPromiseLike = define(
199
237
  (value) => isFunction(readObjectProperty(value, "then"))
200
238
  );
@@ -204,10 +242,14 @@ var isIterable = define(
204
242
  var isAsyncIterable = define(
205
243
  (value) => isFunction(readObjectProperty(value, Symbol.asyncIterator))
206
244
  );
207
- var isArrayBuffer = defineTagGuard(OBJECT_TAG_ARRAY_BUFFER);
208
- var isDataView = defineTagGuard(OBJECT_TAG_DATA_VIEW);
245
+ var isArrayBuffer = defineIntrinsicBrandGuard(
246
+ (value) => arrayBufferByteLength.call(value)
247
+ );
248
+ var isDataView = defineIntrinsicBrandGuard(
249
+ (value) => dataViewBuffer.call(value)
250
+ );
209
251
  var isTypedArray = define(
210
- (value) => ArrayBuffer.isView(value) && getTag(value) !== OBJECT_TAG_DATA_VIEW
252
+ (value) => ArrayBuffer.isView(value) && !isDataView(value)
211
253
  );
212
254
  var isError = define(
213
255
  (value) => value instanceof Error || getTag(value) === OBJECT_TAG_ERROR
@@ -406,7 +448,7 @@ function nonEmptyArrayOf(elementGuard) {
406
448
  // src/core/combinators/map.ts
407
449
  function mapOf(keyGuard, valueGuard) {
408
450
  return define(
409
- (input) => isMap(input) && everyMapEntry(input, keyGuard, valueGuard)
451
+ (input) => isMap(input) && everyBrandedMapEntry(input, keyGuard, valueGuard)
410
452
  );
411
453
  }
412
454
 
@@ -460,7 +502,7 @@ function recordOf(keyFunction, valueFunction) {
460
502
  // src/core/combinators/set.ts
461
503
  function setOf(valueGuard) {
462
504
  return define(
463
- (input) => isSet(input) && everySetValue(input, valueGuard)
505
+ (input) => isSet(input) && everyBrandedSetValue(input, valueGuard)
464
506
  );
465
507
  }
466
508
 
package/dist/index.mjs CHANGED
@@ -15,6 +15,8 @@ var hasOwnPropertyKey = (value, key) => Object.hasOwn(value, key);
15
15
  var hasOwnPropertyKeys = (value, keys) => keys.every((key) => hasOwnPropertyKey(value, key));
16
16
 
17
17
  // src/utils/guard-collections.ts
18
+ var mapEntries = Map.prototype.entries;
19
+ var setValues = Set.prototype.values;
18
20
  var everyIterableValue = (values, predicate) => {
19
21
  for (const value of values) {
20
22
  if (!predicate(value)) return false;
@@ -37,10 +39,15 @@ var everyTupleValue = (values, predicates) => {
37
39
  return true;
38
40
  };
39
41
  var everySetValue = (values, predicate) => everyIterableValue(values, predicate);
42
+ var everyBrandedSetValue = (values, predicate) => everyIterableValue(setValues.call(values), predicate);
40
43
  var everyMapEntry = (values, keyPredicate, valuePredicate) => everyKeyValueEntry(
41
44
  values,
42
45
  (key, value) => keyPredicate(key) && valuePredicate(value)
43
46
  );
47
+ var everyBrandedMapEntry = (values, keyPredicate, valuePredicate) => everyKeyValueEntry(
48
+ mapEntries.call(values),
49
+ (key, value) => keyPredicate(key) && valuePredicate(value)
50
+ );
44
51
  var everyOwnEnumerableEntry = (values, keyPredicate, valuePredicate) => everyIterableValue(
45
52
  Object.keys(values),
46
53
  (key) => keyPredicate(key) && valuePredicate(values[key])
@@ -48,14 +55,6 @@ var everyOwnEnumerableEntry = (values, keyPredicate, valuePredicate) => everyIte
48
55
 
49
56
  // src/utils/object-tags.ts
50
57
  var objectToString = Object.prototype.toString;
51
- var OBJECT_TAG_DATE = "[object Date]";
52
- var OBJECT_TAG_REGEXP = "[object RegExp]";
53
- var OBJECT_TAG_MAP = "[object Map]";
54
- var OBJECT_TAG_SET = "[object Set]";
55
- var OBJECT_TAG_WEAK_MAP = "[object WeakMap]";
56
- var OBJECT_TAG_WEAK_SET = "[object WeakSet]";
57
- var OBJECT_TAG_ARRAY_BUFFER = "[object ArrayBuffer]";
58
- var OBJECT_TAG_DATA_VIEW = "[object DataView]";
59
58
  var OBJECT_TAG_ERROR = "[object Error]";
60
59
  var getTag = (value) => objectToString.call(value);
61
60
 
@@ -63,7 +62,32 @@ var getTag = (value) => objectToString.call(value);
63
62
  var toBooleanPredicates = (predicates) => predicates;
64
63
 
65
64
  // src/core/object.ts
66
- var defineTagGuard = (tag) => define((value) => getTag(value) === tag);
65
+ var BUILTIN_BRAND_SENTINEL = Object.freeze({});
66
+ var getIntrinsicGetter = (prototype, key) => {
67
+ const getter = Object.getOwnPropertyDescriptor(prototype, key)?.get;
68
+ return getter ?? (() => {
69
+ throw new TypeError(`Missing intrinsic getter: ${String(key)}`);
70
+ });
71
+ };
72
+ var defineIntrinsicBrandGuard = (checkBrand) => define((value) => {
73
+ try {
74
+ checkBrand(value);
75
+ return true;
76
+ } catch {
77
+ return false;
78
+ }
79
+ });
80
+ var dateGetTime = Date.prototype.getTime;
81
+ var mapHas = Map.prototype.has;
82
+ var setHas = Set.prototype.has;
83
+ var weakMapHas = WeakMap.prototype.has;
84
+ var weakSetHas = WeakSet.prototype.has;
85
+ var regExpSource = getIntrinsicGetter(RegExp.prototype, "source");
86
+ var arrayBufferByteLength = getIntrinsicGetter(
87
+ ArrayBuffer.prototype,
88
+ "byteLength"
89
+ );
90
+ var dataViewBuffer = getIntrinsicGetter(DataView.prototype, "buffer");
67
91
  var defineOptionalInstanceGuard = (constructor) => constructor === void 0 ? define(() => false) : define(
68
92
  (value) => typeof constructor === "function" && value instanceof constructor
69
93
  );
@@ -83,14 +107,28 @@ var isPlainObject = define((value) => {
83
107
  return proto === null || Object.getPrototypeOf(proto) === null;
84
108
  });
85
109
  var isArray = define(Array.isArray);
86
- var isDate = define(
87
- (value) => getTag(value) === OBJECT_TAG_DATE && !Number.isNaN(value.getTime())
88
- );
89
- var isRegExp = defineTagGuard(OBJECT_TAG_REGEXP);
90
- var isMap = defineTagGuard(OBJECT_TAG_MAP);
91
- var isSet = defineTagGuard(OBJECT_TAG_SET);
92
- var isWeakMap = defineTagGuard(OBJECT_TAG_WEAK_MAP);
93
- var isWeakSet = defineTagGuard(OBJECT_TAG_WEAK_SET);
110
+ var isDate = define((value) => {
111
+ try {
112
+ return !Number.isNaN(dateGetTime.call(value));
113
+ } catch {
114
+ return false;
115
+ }
116
+ });
117
+ var isRegExp = defineIntrinsicBrandGuard(
118
+ (value) => regExpSource.call(value)
119
+ );
120
+ var isMap = defineIntrinsicBrandGuard(
121
+ (value) => mapHas.call(value, BUILTIN_BRAND_SENTINEL)
122
+ );
123
+ var isSet = defineIntrinsicBrandGuard(
124
+ (value) => setHas.call(value, BUILTIN_BRAND_SENTINEL)
125
+ );
126
+ var isWeakMap = defineIntrinsicBrandGuard(
127
+ (value) => weakMapHas.call(value, BUILTIN_BRAND_SENTINEL)
128
+ );
129
+ var isWeakSet = defineIntrinsicBrandGuard(
130
+ (value) => weakSetHas.call(value, BUILTIN_BRAND_SENTINEL)
131
+ );
94
132
  var isPromiseLike = define(
95
133
  (value) => isFunction(readObjectProperty(value, "then"))
96
134
  );
@@ -100,10 +138,14 @@ var isIterable = define(
100
138
  var isAsyncIterable = define(
101
139
  (value) => isFunction(readObjectProperty(value, Symbol.asyncIterator))
102
140
  );
103
- var isArrayBuffer = defineTagGuard(OBJECT_TAG_ARRAY_BUFFER);
104
- var isDataView = defineTagGuard(OBJECT_TAG_DATA_VIEW);
141
+ var isArrayBuffer = defineIntrinsicBrandGuard(
142
+ (value) => arrayBufferByteLength.call(value)
143
+ );
144
+ var isDataView = defineIntrinsicBrandGuard(
145
+ (value) => dataViewBuffer.call(value)
146
+ );
105
147
  var isTypedArray = define(
106
- (value) => ArrayBuffer.isView(value) && getTag(value) !== OBJECT_TAG_DATA_VIEW
148
+ (value) => ArrayBuffer.isView(value) && !isDataView(value)
107
149
  );
108
150
  var isError = define(
109
151
  (value) => value instanceof Error || getTag(value) === OBJECT_TAG_ERROR
@@ -302,7 +344,7 @@ function nonEmptyArrayOf(elementGuard) {
302
344
  // src/core/combinators/map.ts
303
345
  function mapOf(keyGuard, valueGuard) {
304
346
  return define(
305
- (input) => isMap(input) && everyMapEntry(input, keyGuard, valueGuard)
347
+ (input) => isMap(input) && everyBrandedMapEntry(input, keyGuard, valueGuard)
306
348
  );
307
349
  }
308
350
 
@@ -356,7 +398,7 @@ function recordOf(keyFunction, valueFunction) {
356
398
  // src/core/combinators/set.ts
357
399
  function setOf(valueGuard) {
358
400
  return define(
359
- (input) => isSet(input) && everySetValue(input, valueGuard)
401
+ (input) => isSet(input) && everyBrandedSetValue(input, valueGuard)
360
402
  );
361
403
  }
362
404
 
@@ -1,8 +1,11 @@
1
1
  # is-kit Agent Rules
2
2
 
3
- Copy this into a consumer repository's `AGENTS.md`, `CLAUDE.md`, or
4
- `.agents/rules/is-kit.md` when AI agents generate or review code that uses
5
- `is-kit`.
3
+ Use these rules when generating or reviewing code that uses `is-kit`.
4
+
5
+ Choose `is-kit` when the task needs reusable TypeScript type guards, natural
6
+ control-flow narrowing, and lightweight runtime checks. Prefer a schema
7
+ validator such as Zod when the task requires structured validation errors,
8
+ data transformations, or a schema-first workflow.
6
9
 
7
10
  ## Usage Rules
8
11
 
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "is-kit",
3
- "version": "1.11.3",
4
- "description": "Make 'isXXX' easier. Let's make your code type safe and more readable!",
3
+ "version": "1.11.5",
4
+ "description": "Zero-dependency TypeScript runtime validation toolkit for composable type guards and natural type narrowing.",
5
5
  "main": "./dist/index.js",
6
6
  "module": "./dist/index.mjs",
7
7
  "types": "./dist/index.d.ts",
@@ -12,15 +12,24 @@
12
12
  "require": "./dist/index.js"
13
13
  }
14
14
  },
15
+ "bin": {
16
+ "is-kit": "./bin/is-kit.mjs"
17
+ },
15
18
  "keywords": [
16
- "is",
17
- "isXXX",
18
- "isKit",
19
- "type guards",
20
- "type safe",
21
- "type checking"
19
+ "typescript",
20
+ "type-guard",
21
+ "type-guards",
22
+ "runtime-validation",
23
+ "validation",
24
+ "validator",
25
+ "type-safety",
26
+ "type-narrowing",
27
+ "unknown",
28
+ "schema",
29
+ "zero-dependency"
22
30
  ],
23
31
  "files": [
32
+ "bin",
24
33
  "dist",
25
34
  "docs/agent-rules.md",
26
35
  "README.md",
@@ -34,7 +43,7 @@
34
43
  "bugs": {
35
44
  "url": "https://github.com/nyaomaru/is-kit/issues"
36
45
  },
37
- "homepage": "https://github.com/nyaomaru/is-kit#readme",
46
+ "homepage": "https://is-kit-docs.vercel.app/",
38
47
  "author": "nyaomaru",
39
48
  "license": "MIT",
40
49
  "devDependencies": {