Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

isntnt

Package Overview
Dependencies
Maintainers
1
Versions
33
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

isntnt - npm Package Compare versions

Comparing version 1.2.5 to 1.3.0

dist/lib/predicates/isPlainObject.d.ts

2

dist/lib/generics/at.d.ts
import { Predicate, Static } from '../types';
export declare const at: <K extends string | number | symbol, T extends Predicate<any>>(key: K, predicate: T) => <I>(value: I) => value is I & { [P in K]: Static<T>; };
export declare const at: <K extends string | number | symbol, T extends Predicate<any>>(key: K, predicate: T) => <I>(value: I) => value is I & (Extract<Static<T>, undefined> extends never ? { [P in K]: Static<T>; } : { [P_1 in K]?: Static<T> | undefined; });
import { Constructor } from '../types';
export declare const instance: <T extends Constructor<any>>(constructor: T) => (value: unknown) => value is InstanceType<T>;
export declare const instance: <T extends Constructor<any, any>>(constructor: T) => (value: unknown) => value is InstanceType<T>;
import { Predicate, Static } from '../types';
export declare const shape: <T extends Record<string | number | symbol, Predicate<any>>>(shape: T) => (value: unknown) => value is { [K in keyof T]: Static<T[K]>; };
export declare const shape: <T extends Record<string | number | symbol, Predicate<any>>>(shape: T) => Predicate<{ [P in { [K in keyof T]: Extract<Static<T[K]>, undefined> extends never ? K : never; }[keyof T]]: Static<T[P]>; } & { [P_1 in { [K_1 in keyof T]: Extract<Static<T[K_1]>, undefined> extends never ? never : K_1; }[keyof T]]?: Static<T[P_1]> | undefined; }>;

@@ -23,2 +23,3 @@ export { isAny } from './predicates/isAny';

export { isObjectLike } from './predicates/isObjectLike';
export { isPlainObject } from './predicates/isPlainObject';
export { isPositive } from './predicates/isPositive';

@@ -25,0 +26,0 @@ export { isPrimitive } from './predicates/isPrimitive';

@@ -47,2 +47,4 @@ "use strict";

exports.isObjectLike = isObjectLike_1.isObjectLike;
var isPlainObject_1 = require("./predicates/isPlainObject");
exports.isPlainObject = isPlainObject_1.isPlainObject;
var isPositive_1 = require("./predicates/isPositive");

@@ -49,0 +51,0 @@ exports.isPositive = isPositive_1.isPositive;

"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const or_1 = require("../generics/or");
const isSerializablePrimitive_1 = require("./isSerializablePrimitive");
const isSerializableArray_1 = require("./isSerializableArray");
const isSerializableObject_1 = require("./isSerializableObject");
exports.isSerializable = or_1.or(isSerializablePrimitive_1.isSerializablePrimitive, isSerializableArray_1.isSerializableArray, isSerializableObject_1.isSerializableObject);
const isSerializablePrimitive_1 = require("./isSerializablePrimitive");
exports.isSerializable = or_1.or(isSerializableArray_1.isSerializableArray, isSerializableObject_1.isSerializableObject, isSerializablePrimitive_1.isSerializablePrimitive);
//# sourceMappingURL=isSerializable.js.map

@@ -1,2 +0,2 @@

import { Predicate, Serializable } from '../types';
export declare const isSerializableArray: Predicate<Array<Serializable>>;
import { Predicate, SerializableArray } from '../types';
export declare const isSerializableArray: Predicate<SerializableArray>;
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const isArray_1 = require("./isArray");
const isSerializable_1 = require("./isSerializable");
const array_1 = require("../generics/array");
exports.isSerializableArray = array_1.array(isSerializable_1.isSerializable);
exports.isSerializableArray = (value) => isArray_1.isArray(value) && value.every(isSerializable_1.isSerializable);
//# sourceMappingURL=isSerializableArray.js.map
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const isSerializable_1 = require("./isSerializable");
const object_1 = require("../generics/object");
exports.isSerializableObject = object_1.object(isSerializable_1.isSerializable);
const isPlainObject_1 = require("./isPlainObject");
exports.isSerializableObject = (value) => {
const isObjectValue = isPlainObject_1.isPlainObject(value);
if (isObjectValue) {
for (const key in value) {
if (Object.hasOwnProperty.call(value, key)) {
if (!isSerializable_1.isSerializable(value[key])) {
return false;
}
}
}
}
return isObjectValue;
};
//# sourceMappingURL=isSerializableObject.js.map
declare type ObjectWith<K extends PropertyKey> = {
[P in K]: unknown;
};
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: Array<unknown>) => value is T;
export declare type Static<T extends Predicate<any>> = T extends Predicate<infer R> ? R : never;
export declare type Constructor<T> = {
new (...rest: Array<any>): T;
export declare type Constructor<T extends object, U extends Array<any> = []> = {
new (...rest: U): T;
};

@@ -9,0 +18,0 @@ export declare type Intersect<T> = (T extends any ? (k: T) => void : never) extends (k: infer I) => void ? I : never;

{
"name": "isntnt",
"version": "1.2.5",
"version": "1.3.0",
"description": "A collection of composable JavaScript runtime type predicates with TypeScript type guard declarations",

@@ -5,0 +5,0 @@ "main": "dist/index.js",

@@ -6,2 +6,5 @@ import { Predicate, Static } from '../types'

value: I,
): value is I & { [P in K]: Static<T> } => isObjectLike(value) && predicate(value[key])
): value is I &
(Extract<Static<T>, undefined> extends never
? { [P in K]: Static<T> }
: { [P in K]?: Static<T> }) => isObjectLike(value) && predicate(value[key])
import { Constructor } from '../types'
export const instance = <T extends Constructor<any>>(constructor: T) => {
export const instance = <T extends Constructor<any, any>>(constructor: T) => {
;({} instanceof constructor)
return (value: unknown): value is InstanceType<T> => value instanceof constructor
}

@@ -5,5 +5,29 @@ import { Predicate, Static } from '../types'

export const shape = <T extends Record<PropertyKey, Predicate<any>>>(shape: T) => {
export const shape = <T extends Record<PropertyKey, Predicate<any>>>(
shape: T,
): Predicate<
{
[P in {
[K in keyof T]: Extract<Static<T[K]>, undefined> extends never ? K : never
}[keyof T]]: Static<T[P]>
} &
{
[P in {
[K in keyof T]: Extract<Static<T[K]>, undefined> extends never ? never : K
}[keyof T]]?: Static<T[P]>
}
> => {
const predicates = Object.keys(shape).map((key) => at(key, shape[key]))
return (value: unknown): value is { [K in keyof T]: Static<T[K]> } => {
return (
value: unknown,
): value is {
[P in {
[K in keyof T]: Extract<Static<T[K]>, undefined> extends never ? K : never
}[keyof T]]: Static<T[P]>
} &
{
[P in {
[K in keyof T]: Extract<Static<T[K]>, undefined> extends never ? never : K
}[keyof T]]?: Static<T[P]>
} => {
const isObjectValue = isObject(value)

@@ -10,0 +34,0 @@ if (isObjectValue) {

@@ -23,2 +23,3 @@ export { isAny } from './predicates/isAny'

export { isObjectLike } from './predicates/isObjectLike'
export { isPlainObject } from './predicates/isPlainObject'
export { isPositive } from './predicates/isPositive'

@@ -25,0 +26,0 @@ export { isPrimitive } from './predicates/isPrimitive'

import { Predicate, Serializable } from '../types'
import { or } from '../generics/or'
import { isSerializablePrimitive } from './isSerializablePrimitive'
import { isSerializableArray } from './isSerializableArray'
import { isSerializableObject } from './isSerializableObject'
import { isSerializablePrimitive } from './isSerializablePrimitive'
export const isSerializable: Predicate<Serializable> = or(
isSerializablePrimitive,
isSerializableArray,
isSerializableObject,
isSerializablePrimitive,
)

@@ -1,5 +0,7 @@

import { Predicate, Serializable } from '../types'
import { Predicate, SerializableArray } from '../types'
import { isArray } from './isArray'
import { isSerializable } from './isSerializable'
import { array } from '../generics/array'
export const isSerializableArray: Predicate<Array<Serializable>> = array(isSerializable)
export const isSerializableArray: Predicate<SerializableArray> = (
value: unknown,
): value is SerializableArray => isArray(value) && value.every(isSerializable)
import { SerializableObject, Predicate } from '../types'
import { isSerializable } from './isSerializable'
import { object } from '../generics/object'
import { isPlainObject } from './isPlainObject'
export const isSerializableObject: Predicate<SerializableObject> = object(isSerializable)
export const isSerializableObject: Predicate<SerializableObject> = (
value: unknown,
): value is SerializableObject => {
const isObjectValue = isPlainObject(value)
if (isObjectValue) {
for (const key in value as SerializableObject) {
if (Object.hasOwnProperty.call(value, key)) {
if (!isSerializable((value as SerializableObject)[key])) {
return false
}
}
}
}
return isObjectValue
}
type ObjectWith<K extends PropertyKey> = { [P in K]: unknown }
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: Array<unknown>) => value is T
export type Static<T extends Predicate<any>> = T extends Predicate<infer R> ? R : never
export type Constructor<T> = {
new (...rest: Array<any>): T
export type Constructor<T extends object, U extends Array<any> = []> = {
new (...rest: U): T
}
// see https://github.com/Microsoft/TypeScript/issues/29594#issuecomment-507673155
export type Intersect<T> = (T extends any
? (k: T) => void
: never) extends (k: infer I) => void
export type Intersect<T> = (T extends any ? (k: T) => void : never) extends (k: infer I) => void
? I

@@ -15,0 +27,0 @@ : never

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

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc