is-kit 1.6.4 → 1.7.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/README.md CHANGED
@@ -166,7 +166,7 @@ Use `not(...)` when you want the complement of an existing guard or refinement.
166
166
  Use `struct` for plain-object payloads. Keys are required by default.
167
167
 
168
168
  ```ts
169
- import { isNumber, isString, optionalKey, struct } from 'is-kit';
169
+ import { isNumber, isString, optional, optionalKey, struct } from 'is-kit';
170
170
 
171
171
  const isProfile = struct(
172
172
  {
@@ -176,14 +176,6 @@ const isProfile = struct(
176
176
  },
177
177
  { exact: true }
178
178
  );
179
- ```
180
-
181
- `optionalKey(guard)` means the property may be missing.
182
-
183
- If the property must exist but the value may be `undefined`, use `optional(guard)` instead.
184
-
185
- ```ts
186
- import { isString, optional, optionalKey, struct } from 'is-kit';
187
179
 
188
180
  const isConfig = struct({
189
181
  label: isString,
@@ -192,6 +184,12 @@ const isConfig = struct({
192
184
  });
193
185
  ```
194
186
 
187
+ `optionalKey(guard)` means the property may be missing.
188
+
189
+ Use `struct(schema, { exact: true })` when extra keys should be rejected.
190
+
191
+ If the property must exist but the value may be `undefined`, use `optional(guard)` instead.
192
+
195
193
  ### 5. Validate arrays, tuples, maps, sets, and records
196
194
 
197
195
  Collection combinators keep your element guards reusable.
@@ -202,12 +200,14 @@ import {
202
200
  isNumber,
203
201
  isString,
204
202
  mapOf,
203
+ nonEmptyArrayOf,
205
204
  recordOf,
206
205
  setOf,
207
206
  tupleOf
208
207
  } from 'is-kit';
209
208
 
210
209
  const isStringArray = arrayOf(isString);
210
+ const isNonEmptyTagList = nonEmptyArrayOf(isString);
211
211
  const isPoint = tupleOf(isNumber, isNumber);
212
212
  const isTagSet = setOf(isString);
213
213
  const isScoreMap = mapOf(isString, isNumber);
@@ -356,7 +356,7 @@ The library is organized around a few small building blocks:
356
356
  - **Primitives**: `isString`, `isNumber`, `isBoolean`, `isInteger`, ...
357
357
  - **Composition**: `define`, `and`, `andAll`, `or`, `not`, `oneOf`
358
358
  - **Object shapes**: `struct`, `optionalKey`, `hasKey`, `hasKeys`, `narrowKeyTo`
359
- - **Collections**: `arrayOf`, `tupleOf`, `setOf`, `mapOf`, `recordOf`
359
+ - **Collections**: `arrayOf`, `nonEmptyArrayOf`, `tupleOf`, `setOf`, `mapOf`, `recordOf`
360
360
  - **Literals**: `oneOfValues`, `equals`, `equalsBy`, `equalsKey`
361
361
  - **Nullish handling**: `nullable`, `nonNull`, `nullish`, `optional`, `required`
362
362
  - **Result helpers**: `safeParse`, `safeParseWith`, `assert`
package/dist/index.d.mts CHANGED
@@ -324,6 +324,13 @@ declare const isPrimitive: Guard<string | number | bigint | boolean | symbol | n
324
324
  * @returns Predicate narrowing to a readonly array of the guarded element type.
325
325
  */
326
326
  declare function arrayOf<F extends Predicate<unknown>>(elementGuard: F): Predicate<readonly GuardedOf<F>[]>;
327
+ /**
328
+ * Validates a non-empty array where every element satisfies the provided guard.
329
+ *
330
+ * @param elementGuard Guard applied to each array element.
331
+ * @returns Predicate narrowing to a readonly non-empty array of the guarded element type.
332
+ */
333
+ declare function nonEmptyArrayOf<F extends Predicate<unknown>>(elementGuard: F): Predicate<readonly [GuardedOf<F>, ...GuardedOf<F>[]]>;
327
334
 
328
335
  /**
329
336
  * Validates a set where every value satisfies the provided guard.
@@ -606,4 +613,4 @@ declare const everyOwnEnumerableEntry: (values: Record<string, unknown>, keyPred
606
613
  */
607
614
  declare const toBooleanPredicates: <A>(predicates: readonly ((value: A) => boolean)[]) => ReadonlyArray<(value: A) => boolean>;
608
615
 
609
- export { type ChainResult, type Guard, type GuardedOf, type GuardedWithin, type InferSchema, type OptionalSchemaField, type OutOfGuards, type ParseResult, type Predicate, type Primitive, type Refine, type RefineChain, type Refinement, type Schema, type SchemaField, and, andAll, arrayOf, assert, define, equals, equalsBy, equalsKey, everyArrayValue, everyMapEntry, everyOwnEnumerableEntry, everySetValue, everyTupleValue, guardIn, hasKey, hasKeys, isArray, isArrayBuffer, isAsyncIterable, isBigInt, isBlob, isBoolean, isDataView, isDate, isError, isFiniteNumber, isFunction, isInfiniteNumber, isInstanceOf, isInteger, isIterable, isMap, isNaN, isNegative, isNull, isNumber, isNumberPrimitive, isObject, isPlainObject, isPositive, isPrimitive, isPromiseLike, isRegExp, isSafeInteger, isSet, isString, isSymbol, isTypedArray, isURL, isUndefined, isWeakMap, isWeakSet, isZero, mapOf, narrowKeyTo, nonNull, not, nullable, nullish, oneOf, oneOfValues, optional, optionalKey, or, predicateToRefine, recordOf, required, safeParse, safeParseWith, setOf, struct, toBooleanPredicates, tupleOf };
616
+ export { type ChainResult, type Guard, type GuardedOf, type GuardedWithin, type InferSchema, type OptionalSchemaField, type OutOfGuards, type ParseResult, type Predicate, type Primitive, type Refine, type RefineChain, type Refinement, type Schema, type SchemaField, and, andAll, arrayOf, assert, define, equals, equalsBy, equalsKey, everyArrayValue, everyMapEntry, everyOwnEnumerableEntry, everySetValue, everyTupleValue, guardIn, hasKey, hasKeys, isArray, isArrayBuffer, isAsyncIterable, isBigInt, isBlob, isBoolean, isDataView, isDate, isError, isFiniteNumber, isFunction, isInfiniteNumber, isInstanceOf, isInteger, isIterable, isMap, isNaN, isNegative, isNull, isNumber, isNumberPrimitive, isObject, isPlainObject, isPositive, isPrimitive, isPromiseLike, isRegExp, isSafeInteger, isSet, isString, isSymbol, isTypedArray, isURL, isUndefined, isWeakMap, isWeakSet, isZero, mapOf, narrowKeyTo, nonEmptyArrayOf, nonNull, not, nullable, nullish, oneOf, oneOfValues, optional, optionalKey, or, predicateToRefine, recordOf, required, safeParse, safeParseWith, setOf, struct, toBooleanPredicates, tupleOf };
package/dist/index.d.ts CHANGED
@@ -324,6 +324,13 @@ declare const isPrimitive: Guard<string | number | bigint | boolean | symbol | n
324
324
  * @returns Predicate narrowing to a readonly array of the guarded element type.
325
325
  */
326
326
  declare function arrayOf<F extends Predicate<unknown>>(elementGuard: F): Predicate<readonly GuardedOf<F>[]>;
327
+ /**
328
+ * Validates a non-empty array where every element satisfies the provided guard.
329
+ *
330
+ * @param elementGuard Guard applied to each array element.
331
+ * @returns Predicate narrowing to a readonly non-empty array of the guarded element type.
332
+ */
333
+ declare function nonEmptyArrayOf<F extends Predicate<unknown>>(elementGuard: F): Predicate<readonly [GuardedOf<F>, ...GuardedOf<F>[]]>;
327
334
 
328
335
  /**
329
336
  * Validates a set where every value satisfies the provided guard.
@@ -606,4 +613,4 @@ declare const everyOwnEnumerableEntry: (values: Record<string, unknown>, keyPred
606
613
  */
607
614
  declare const toBooleanPredicates: <A>(predicates: readonly ((value: A) => boolean)[]) => ReadonlyArray<(value: A) => boolean>;
608
615
 
609
- export { type ChainResult, type Guard, type GuardedOf, type GuardedWithin, type InferSchema, type OptionalSchemaField, type OutOfGuards, type ParseResult, type Predicate, type Primitive, type Refine, type RefineChain, type Refinement, type Schema, type SchemaField, and, andAll, arrayOf, assert, define, equals, equalsBy, equalsKey, everyArrayValue, everyMapEntry, everyOwnEnumerableEntry, everySetValue, everyTupleValue, guardIn, hasKey, hasKeys, isArray, isArrayBuffer, isAsyncIterable, isBigInt, isBlob, isBoolean, isDataView, isDate, isError, isFiniteNumber, isFunction, isInfiniteNumber, isInstanceOf, isInteger, isIterable, isMap, isNaN, isNegative, isNull, isNumber, isNumberPrimitive, isObject, isPlainObject, isPositive, isPrimitive, isPromiseLike, isRegExp, isSafeInteger, isSet, isString, isSymbol, isTypedArray, isURL, isUndefined, isWeakMap, isWeakSet, isZero, mapOf, narrowKeyTo, nonNull, not, nullable, nullish, oneOf, oneOfValues, optional, optionalKey, or, predicateToRefine, recordOf, required, safeParse, safeParseWith, setOf, struct, toBooleanPredicates, tupleOf };
616
+ export { type ChainResult, type Guard, type GuardedOf, type GuardedWithin, type InferSchema, type OptionalSchemaField, type OutOfGuards, type ParseResult, type Predicate, type Primitive, type Refine, type RefineChain, type Refinement, type Schema, type SchemaField, and, andAll, arrayOf, assert, define, equals, equalsBy, equalsKey, everyArrayValue, everyMapEntry, everyOwnEnumerableEntry, everySetValue, everyTupleValue, guardIn, hasKey, hasKeys, isArray, isArrayBuffer, isAsyncIterable, isBigInt, isBlob, isBoolean, isDataView, isDate, isError, isFiniteNumber, isFunction, isInfiniteNumber, isInstanceOf, isInteger, isIterable, isMap, isNaN, isNegative, isNull, isNumber, isNumberPrimitive, isObject, isPlainObject, isPositive, isPrimitive, isPromiseLike, isRegExp, isSafeInteger, isSet, isString, isSymbol, isTypedArray, isURL, isUndefined, isWeakMap, isWeakSet, isZero, mapOf, narrowKeyTo, nonEmptyArrayOf, nonNull, not, nullable, nullish, oneOf, oneOfValues, optional, optionalKey, or, predicateToRefine, recordOf, required, safeParse, safeParseWith, setOf, struct, toBooleanPredicates, tupleOf };
package/dist/index.js CHANGED
@@ -75,6 +75,7 @@ __export(index_exports, {
75
75
  isZero: () => isZero,
76
76
  mapOf: () => mapOf,
77
77
  narrowKeyTo: () => narrowKeyTo,
78
+ nonEmptyArrayOf: () => nonEmptyArrayOf,
78
79
  nonNull: () => nonNull,
79
80
  not: () => not,
80
81
  nullable: () => nullable,
@@ -352,6 +353,11 @@ function arrayOf(elementGuard) {
352
353
  (input) => Array.isArray(input) && everyArrayValue(input, elementGuard)
353
354
  );
354
355
  }
356
+ function nonEmptyArrayOf(elementGuard) {
357
+ return define(
358
+ (input) => Array.isArray(input) && input.length > 0 && everyArrayValue(input, elementGuard)
359
+ );
360
+ }
355
361
 
356
362
  // src/core/combinators/set.ts
357
363
  function setOf(valueGuard) {
@@ -541,6 +547,7 @@ function narrowKeyTo(guard, key) {
541
547
  isZero,
542
548
  mapOf,
543
549
  narrowKeyTo,
550
+ nonEmptyArrayOf,
544
551
  nonNull,
545
552
  not,
546
553
  nullable,
package/dist/index.mjs CHANGED
@@ -254,6 +254,11 @@ function arrayOf(elementGuard) {
254
254
  (input) => Array.isArray(input) && everyArrayValue(input, elementGuard)
255
255
  );
256
256
  }
257
+ function nonEmptyArrayOf(elementGuard) {
258
+ return define(
259
+ (input) => Array.isArray(input) && input.length > 0 && everyArrayValue(input, elementGuard)
260
+ );
261
+ }
257
262
 
258
263
  // src/core/combinators/set.ts
259
264
  function setOf(valueGuard) {
@@ -442,6 +447,7 @@ export {
442
447
  isZero,
443
448
  mapOf,
444
449
  narrowKeyTo,
450
+ nonEmptyArrayOf,
445
451
  nonNull,
446
452
  not,
447
453
  nullable,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "is-kit",
3
- "version": "1.6.4",
3
+ "version": "1.7.0",
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",