Comparing version 1.5.2 to 1.6.0
@@ -1,2 +0,2 @@ | ||
import { Predicate, Static } from '../types'; | ||
import type { Predicate, Static } from '../types'; | ||
export declare const at: <K extends PropertyKey, T extends Predicate<any>>(key: K, predicate: T) => (value: unknown) => value is StaticAt<K, T>; | ||
@@ -3,0 +3,0 @@ declare type StaticAt<K extends PropertyKey, T extends Predicate<any>> = Extract<Static<T>, undefined> extends never ? { |
@@ -1,5 +0,5 @@ | ||
import { ArrayLike, Predicate } from '../types'; | ||
import type { Predicate } from '../types'; | ||
/** | ||
* Checks if a value is an Array-like object. | ||
*/ | ||
export declare const isArrayLike: Predicate<ArrayLike>; | ||
export declare const isArrayLike: Predicate<ArrayLike<unknown>>; |
@@ -1,5 +0,5 @@ | ||
import { ObjectLike } from '../types'; | ||
import type { UnknownObject } from '../types'; | ||
/** | ||
* Checks if a value has object-like properties (not `null`, `undefined`, or a boolean). | ||
*/ | ||
export declare const isObjectLike: (value: unknown) => value is ObjectLike; | ||
export declare const isObjectLike: (value: unknown) => value is UnknownObject; |
@@ -1,13 +0,4 @@ | ||
export declare type InferredPartial<T extends {}> = { | ||
[P in { | ||
[K in keyof T]: Extract<T[K], undefined> extends never ? K : never; | ||
}[keyof T]]: InferredPartial<T[P]>; | ||
} & Partial<{ | ||
[P in { | ||
[K in keyof T]: Extract<T[K], undefined> extends never ? never : K; | ||
}[keyof T]]: InferredPartial<T[P]>; | ||
}>; | ||
export declare type Predicate<T> = (value: unknown, ...rest: ReadonlyArray<unknown>) => value is T; | ||
export declare type Static<T extends Predicate<any>> = T extends Predicate<infer R> ? R : never; | ||
export declare type Constructor<T extends object, U extends ReadonlyArray<any> = []> = { | ||
export declare type Constructor<T extends object, U extends ReadonlyArray<unknown> = ReadonlyArray<unknown>> = { | ||
new (...rest: U): T; | ||
@@ -17,9 +8,11 @@ }; | ||
export declare type None = null | undefined; | ||
export declare type Some<T = Function | boolean | bigint | number | string | symbol | object> = Exclude<T, None>; | ||
export declare type Unknown = Function | Primitive | object; | ||
export declare type Some<T = Unknown> = Exclude<T, None>; | ||
export declare type Maybe<T> = T | None; | ||
export declare type Optional<T> = T | undefined; | ||
export declare type Nullable<T> = T | null; | ||
export declare type ObjectLike = {}; | ||
export declare type ArrayLike = Record<number, unknown>; | ||
export declare type PlainObject = Record<PropertyKey, unknown>; | ||
export declare type PlainObjectKey = string | symbol; | ||
export declare type PlainObject = Record<PlainObjectKey, unknown>; | ||
export declare type UnknownObject = Record<PropertyKey, unknown>; | ||
export declare type EmptyObject = Record<PropertyKey, never>; | ||
export declare type Dictionary = Record<string, string>; | ||
@@ -26,0 +19,0 @@ export declare type Primitive = SerializablePrimitive | undefined | symbol | bigint; |
"use strict"; | ||
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { | ||
if (k2 === undefined) k2 = k; | ||
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } }); | ||
var desc = Object.getOwnPropertyDescriptor(m, k); | ||
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) { | ||
desc = { enumerable: true, get: function() { return m[k]; } }; | ||
} | ||
Object.defineProperty(o, k2, desc); | ||
}) : (function(o, m, k, k2) { | ||
@@ -6,0 +10,0 @@ if (k2 === undefined) k2 = k; |
@@ -1,2 +0,2 @@ | ||
import { Predicate, Static } from '../types'; | ||
import type { Predicate, Static } from '../types'; | ||
export declare const at: <K extends PropertyKey, T extends Predicate<any>>(key: K, predicate: T) => (value: unknown) => value is StaticAt<K, T>; | ||
@@ -3,0 +3,0 @@ declare type StaticAt<K extends PropertyKey, T extends Predicate<any>> = Extract<Static<T>, undefined> extends never ? { |
@@ -1,5 +0,5 @@ | ||
import { ArrayLike, Predicate } from '../types'; | ||
import type { Predicate } from '../types'; | ||
/** | ||
* Checks if a value is an Array-like object. | ||
*/ | ||
export declare const isArrayLike: Predicate<ArrayLike>; | ||
export declare const isArrayLike: Predicate<ArrayLike<unknown>>; |
@@ -1,5 +0,5 @@ | ||
import { ObjectLike } from '../types'; | ||
import type { UnknownObject } from '../types'; | ||
/** | ||
* Checks if a value has object-like properties (not `null`, `undefined`, or a boolean). | ||
*/ | ||
export declare const isObjectLike: (value: unknown) => value is ObjectLike; | ||
export declare const isObjectLike: (value: unknown) => value is UnknownObject; |
@@ -1,13 +0,4 @@ | ||
export declare type InferredPartial<T extends {}> = { | ||
[P in { | ||
[K in keyof T]: Extract<T[K], undefined> extends never ? K : never; | ||
}[keyof T]]: InferredPartial<T[P]>; | ||
} & Partial<{ | ||
[P in { | ||
[K in keyof T]: Extract<T[K], undefined> extends never ? never : K; | ||
}[keyof T]]: InferredPartial<T[P]>; | ||
}>; | ||
export declare type Predicate<T> = (value: unknown, ...rest: ReadonlyArray<unknown>) => value is T; | ||
export declare type Static<T extends Predicate<any>> = T extends Predicate<infer R> ? R : never; | ||
export declare type Constructor<T extends object, U extends ReadonlyArray<any> = []> = { | ||
export declare type Constructor<T extends object, U extends ReadonlyArray<unknown> = ReadonlyArray<unknown>> = { | ||
new (...rest: U): T; | ||
@@ -17,9 +8,11 @@ }; | ||
export declare type None = null | undefined; | ||
export declare type Some<T = Function | boolean | bigint | number | string | symbol | object> = Exclude<T, None>; | ||
export declare type Unknown = Function | Primitive | object; | ||
export declare type Some<T = Unknown> = Exclude<T, None>; | ||
export declare type Maybe<T> = T | None; | ||
export declare type Optional<T> = T | undefined; | ||
export declare type Nullable<T> = T | null; | ||
export declare type ObjectLike = {}; | ||
export declare type ArrayLike = Record<number, unknown>; | ||
export declare type PlainObject = Record<PropertyKey, unknown>; | ||
export declare type PlainObjectKey = string | symbol; | ||
export declare type PlainObject = Record<PlainObjectKey, unknown>; | ||
export declare type UnknownObject = Record<PropertyKey, unknown>; | ||
export declare type EmptyObject = Record<PropertyKey, never>; | ||
export declare type Dictionary = Record<string, string>; | ||
@@ -26,0 +19,0 @@ export declare type Primitive = SerializablePrimitive | undefined | symbol | bigint; |
{ | ||
"name": "isntnt", | ||
"version": "1.5.2", | ||
"version": "1.6.0", | ||
"description": "A collection of composable JavaScript runtime type predicates with TypeScript type guard declarations", | ||
@@ -33,4 +33,4 @@ "main": "dist/index.js", | ||
"ts-jest": "^24.0.2", | ||
"typescript": "^4.4.2" | ||
"typescript": "^4.8.2" | ||
} | ||
} |
@@ -1,11 +0,14 @@ | ||
import { PlainObject, Predicate, Static } from '../types' | ||
import type { Predicate, Static } from '../types' | ||
import { isObjectLike } from '../predicates/isObjectLike' | ||
export const at = <K extends PropertyKey, T extends Predicate<any>>(key: K, predicate: T) => ( | ||
value: unknown | ||
): value is StaticAt<K, T> => isObjectLike(value) && predicate((value as PlainObject)[key]) | ||
export const at = | ||
<K extends PropertyKey, T extends Predicate<any>>(key: K, predicate: T) => | ||
(value: unknown): value is StaticAt<K, T> => | ||
isObjectLike(value) && predicate(value[key]) | ||
type StaticAt<K extends PropertyKey, T extends Predicate<any>> = | ||
Extract<Static<T>, undefined> extends never | ||
? { [P in K]: Static<T> } | ||
: { [P in K]?: Static<T> } | ||
type StaticAt<K extends PropertyKey, T extends Predicate<any>> = Extract< | ||
Static<T>, | ||
undefined | ||
> extends never | ||
? { [P in K]: Static<T> } | ||
: { [P in K]?: Static<T> } |
@@ -1,2 +0,2 @@ | ||
import { ArrayLike, Predicate } from '../types' | ||
import type { Predicate } from '../types' | ||
import { isFunction } from './isFunction' | ||
@@ -8,3 +8,4 @@ import { isWithLength } from './isWithLength' | ||
*/ | ||
export const isArrayLike: Predicate<ArrayLike> = (value: unknown): value is ArrayLike => | ||
isWithLength(value) && !isFunction(value) | ||
export const isArrayLike: Predicate<ArrayLike<unknown>> = ( | ||
value: unknown, | ||
): value is ArrayLike<unknown> => isWithLength(value) && !isFunction(value) |
@@ -1,2 +0,2 @@ | ||
import { ObjectLike } from '../types' | ||
import type { UnknownObject } from '../types' | ||
import { isBoolean } from './isBoolean' | ||
@@ -8,3 +8,3 @@ import { isSome } from './isSome' | ||
*/ | ||
export const isObjectLike = (value: unknown): value is ObjectLike => | ||
export const isObjectLike = (value: unknown): value is UnknownObject => | ||
isSome(value) && !isBoolean(value) |
@@ -1,14 +0,1 @@ | ||
export type InferredPartial<T extends {}> = { | ||
[P in { | ||
[K in keyof T]: Extract<T[K], undefined> extends never ? K : never | ||
}[keyof T]]: InferredPartial<T[P]> | ||
} & | ||
Partial< | ||
{ | ||
[P in { | ||
[K in keyof T]: Extract<T[K], undefined> extends never ? never : K | ||
}[keyof T]]: InferredPartial<T[P]> | ||
} | ||
> | ||
export type Predicate<T> = (value: unknown, ...rest: ReadonlyArray<unknown>) => value is T | ||
@@ -18,3 +5,6 @@ | ||
export type Constructor<T extends object, U extends ReadonlyArray<any> = []> = { | ||
export type Constructor< | ||
T extends object, | ||
U extends ReadonlyArray<unknown> = ReadonlyArray<unknown>, | ||
> = { | ||
new (...rest: U): T | ||
@@ -29,6 +19,7 @@ } | ||
export type None = null | undefined | ||
export type Some<T = Function | boolean | bigint | number | string | symbol | object> = Exclude< | ||
T, | ||
None | ||
> | ||
export type Unknown = Function | Primitive | object | ||
export type Some<T = Unknown> = Exclude<T, None> | ||
export type Maybe<T> = T | None | ||
@@ -38,5 +29,10 @@ export type Optional<T> = T | undefined | ||
export type ObjectLike = {} | ||
export type ArrayLike = Record<number, unknown> | ||
export type PlainObject = Record<PropertyKey, unknown> | ||
export type PlainObjectKey = string | symbol | ||
export type PlainObject = Record<PlainObjectKey, unknown> | ||
export type UnknownObject = Record<PropertyKey, unknown> | ||
export type EmptyObject = Record<PropertyKey, never> | ||
export type Dictionary = Record<string, string> | ||
@@ -43,0 +39,0 @@ |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
277613
4849