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

superstruct

Package Overview
Dependencies
Maintainers
2
Versions
90
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

superstruct - npm Package Compare versions

Comparing version 1.0.3 to 1.0.4

2

dist/error.d.ts
/**
* A `StructFailure` represents a single specific failure in validation.
*/
export declare type Failure = {
export type Failure = {
value: any;

@@ -6,0 +6,0 @@ key: any;

@@ -83,3 +83,3 @@ import { StructSchema } from './utils';

*/
export declare type Context = {
export type Context = {
branch: Array<any>;

@@ -91,19 +91,19 @@ path: Array<any>;

*/
export declare type Infer<T extends Struct<any, any>> = T['TYPE'];
export type Infer<T extends Struct<any, any>> = T['TYPE'];
/**
* A type utility to describe that a struct represents a TypeScript type.
*/
export declare type Describe<T> = Struct<T, StructSchema<T>>;
export type Describe<T> = Struct<T, StructSchema<T>>;
/**
* A `Result` is returned from validation functions.
*/
export declare type Result = boolean | string | Partial<Failure> | Iterable<boolean | string | Partial<Failure>>;
export type Result = boolean | string | Partial<Failure> | Iterable<boolean | string | Partial<Failure>>;
/**
* A `Coercer` takes an unknown value and optionally coerces it.
*/
export declare type Coercer<T = unknown> = (value: T, context: Context) => unknown;
export type Coercer<T = unknown> = (value: T, context: Context) => unknown;
/**
* A `Validator` takes an unknown value and validates it.
*/
export declare type Validator = (value: unknown, context: Context) => Result;
export type Validator = (value: unknown, context: Context) => Result;
/**

@@ -113,3 +113,3 @@ * A `Refiner` takes a value of a known type and validates it against a further

*/
export declare type Refiner<T> = (value: T, context: Context) => Result;
export type Refiner<T> = (value: T, context: Context) => Result;
//# sourceMappingURL=struct.d.ts.map

@@ -1,3 +0,3 @@

import { Struct, Context, Validator } from '../struct';
import { ObjectSchema, Assign, ObjectType, PartialObjectSchema } from '../utils';
import { Context, Struct, Validator } from '../struct';
import { Assign, ObjectSchema, ObjectType, PartialObjectSchema } from '../utils';
/**

@@ -4,0 +4,0 @@ * Create a new struct that combines the properties properties from multiple

@@ -44,11 +44,11 @@ import { Struct, Infer, Result, Context, Describe } from './struct';

*/
export declare type UnionToIntersection<U> = (U extends any ? (arg: U) => any : never) extends (arg: infer I) => void ? I : never;
export type UnionToIntersection<U> = (U extends any ? (arg: U) => any : never) extends (arg: infer I) => void ? I : never;
/**
* Assign properties from one type to another, overwriting existing.
*/
export declare type Assign<T, U> = Simplify<U & Omit<T, keyof U>>;
export type Assign<T, U> = Simplify<U & Omit<T, keyof U>>;
/**
* A schema for enum structs.
*/
export declare type EnumSchema<T extends string | number | undefined | null> = {
export type EnumSchema<T extends string | number | undefined | null> = {
[K in NonNullable<T>]: K;

@@ -60,27 +60,27 @@ };

*/
export declare type IsMatch<T, G> = T extends G ? (G extends T ? T : never) : never;
export type IsMatch<T, G> = T extends G ? (G extends T ? T : never) : never;
/**
* Check if a type is an exact match.
*/
export declare type IsExactMatch<T, U> = (<G>() => G extends T ? 1 : 2) extends <G>() => G extends U ? 1 : 2 ? T : never;
export type IsExactMatch<T, U> = (<G>() => G extends T ? 1 : 2) extends <G>() => G extends U ? 1 : 2 ? T : never;
/**
* Check if a type is a record type.
*/
export declare type IsRecord<T> = T extends object ? string extends keyof T ? T : never : never;
export type IsRecord<T> = T extends object ? string extends keyof T ? T : never : never;
/**
* Check if a type is a tuple.
*/
export declare type IsTuple<T> = T extends [any] ? T : T extends [any, any] ? T : T extends [any, any, any] ? T : T extends [any, any, any, any] ? T : T extends [any, any, any, any, any] ? T : never;
export type IsTuple<T> = T extends [any] ? T : T extends [any, any] ? T : T extends [any, any, any] ? T : T extends [any, any, any, any] ? T : T extends [any, any, any, any, any] ? T : never;
/**
* Check if a type is a union.
*/
export declare type IsUnion<T, U extends T = T> = (T extends any ? (U extends T ? false : true) : false) extends false ? never : T;
export type IsUnion<T, U extends T = T> = (T extends any ? (U extends T ? false : true) : false) extends false ? never : T;
/**
* A schema for object structs.
*/
export declare type ObjectSchema = Record<string, Struct<any, any>>;
export type ObjectSchema = Record<string, Struct<any, any>>;
/**
* Infer a type from an object struct schema.
*/
export declare type ObjectType<S extends ObjectSchema> = Simplify<Optionalize<{
export type ObjectType<S extends ObjectSchema> = Simplify<Optionalize<{
[K in keyof S]: Infer<S[K]>;

@@ -91,3 +91,3 @@ }>>;

*/
export declare type OmitBy<T, V> = Omit<T, {
export type OmitBy<T, V> = Omit<T, {
[K in keyof T]: V extends Extract<T[K], V> ? K : never;

@@ -98,7 +98,7 @@ }[keyof T]>;

*/
export declare type Optionalize<S extends object> = OmitBy<S, undefined> & Partial<PickBy<S, undefined>>;
export type Optionalize<S extends object> = OmitBy<S, undefined> & Partial<PickBy<S, undefined>>;
/**
* Transform an object schema type to represent a partial.
*/
export declare type PartialObjectSchema<S extends ObjectSchema> = {
export type PartialObjectSchema<S extends ObjectSchema> = {
[K in keyof S]: Struct<Infer<S[K]> | undefined>;

@@ -109,3 +109,3 @@ };

*/
export declare type PickBy<T, V> = Pick<T, {
export type PickBy<T, V> = Pick<T, {
[K in keyof T]: V extends Extract<T[K], V> ? K : never;

@@ -116,10 +116,10 @@ }[keyof T]>;

*/
export declare type Simplify<T> = T extends any[] | Date ? T : {
export type Simplify<T> = T extends any[] | Date ? T : {
[K in keyof T]: T[K];
} & {};
export declare type If<B extends Boolean, Then, Else> = B extends true ? Then : Else;
export type If<B extends Boolean, Then, Else> = B extends true ? Then : Else;
/**
* A schema for any type of struct.
*/
export declare type StructSchema<T> = [T] extends [string | undefined | null] ? [T] extends [IsMatch<T, string | undefined | null>] ? null : [T] extends [IsUnion<T>] ? EnumSchema<T> : T : [T] extends [number | undefined | null] ? [T] extends [IsMatch<T, number | undefined | null>] ? null : [T] extends [IsUnion<T>] ? EnumSchema<T> : T : [T] extends [boolean] ? [T] extends [IsExactMatch<T, boolean>] ? null : T : T extends bigint | symbol | undefined | null | Function | Date | Error | RegExp | Map<any, any> | WeakMap<any, any> | Set<any> | WeakSet<any> | Promise<any> ? null : T extends Array<infer E> ? T extends IsTuple<T> ? null : Struct<E> : T extends object ? T extends IsRecord<T> ? null : {
export type StructSchema<T> = [T] extends [string | undefined | null] ? [T] extends [IsMatch<T, string | undefined | null>] ? null : [T] extends [IsUnion<T>] ? EnumSchema<T> : T : [T] extends [number | undefined | null] ? [T] extends [IsMatch<T, number | undefined | null>] ? null : [T] extends [IsUnion<T>] ? EnumSchema<T> : T : [T] extends [boolean] ? [T] extends [IsExactMatch<T, boolean>] ? null : T : T extends bigint | symbol | undefined | null | Function | Date | Error | RegExp | Map<any, any> | WeakMap<any, any> | Set<any> | WeakSet<any> | Promise<any> ? null : T extends Array<infer E> ? T extends IsTuple<T> ? null : Struct<E> : T extends object ? T extends IsRecord<T> ? null : {
[K in keyof T]: Describe<T[K]>;

@@ -130,3 +130,3 @@ } : null;

*/
export declare type TupleSchema<T> = {
export type TupleSchema<T> = {
[K in keyof T]: Struct<T[K]>;

@@ -137,3 +137,3 @@ };

*/
export declare type AnyStruct = Struct<any, any>;
export type AnyStruct = Struct<any, any>;
/**

@@ -145,5 +145,5 @@ * Infer a tuple of types from a tuple of `Struct`s.

*/
export declare type InferStructTuple<Tuple extends AnyStruct[], Length extends number = Tuple['length']> = Length extends Length ? number extends Length ? Tuple : _InferTuple<Tuple, Length, []> : never;
declare type _InferTuple<Tuple extends AnyStruct[], Length extends number, Accumulated extends unknown[], Index extends number = Accumulated['length']> = Index extends Length ? Accumulated : _InferTuple<Tuple, Length, [...Accumulated, Infer<Tuple[Index]>]>;
export type InferStructTuple<Tuple extends AnyStruct[], Length extends number = Tuple['length']> = Length extends Length ? number extends Length ? Tuple : _InferTuple<Tuple, Length, []> : never;
type _InferTuple<Tuple extends AnyStruct[], Length extends number, Accumulated extends unknown[], Index extends number = Accumulated['length']> = Index extends Length ? Accumulated : _InferTuple<Tuple, Length, [...Accumulated, Infer<Tuple[Index]>]>;
export {};
//# sourceMappingURL=utils.d.ts.map
{
"name": "superstruct",
"description": "A simple and composable way to validate data in JavaScript (and TypeScript).",
"version": "1.0.3",
"version": "1.0.4",
"license": "MIT",

@@ -6,0 +6,0 @@ "repository": "git://github.com/ianstormtaylor/superstruct.git",

@@ -180,5 +180,5 @@ <p align="center">

Try out the [live demo on JSFiddle](https://jsfiddle.net/85nse1mk/) to get an idea for how the API works, or to quickly verify your use case:
Try out the [live demo on CodeSandbox](https://codesandbox.io/s/bold-water-s2cr8d?file=/index.js) to get an idea for how the API works, or to quickly verify your use case:
[![Demo screenshot.](./docs/images/demo-screenshot.png)](https://jsfiddle.net/85nse1mk/)
[![Demo screenshot.](./docs/images/demo-screenshot.png)](https://codesandbox.io/s/bold-water-s2cr8d?file=/index.js)

@@ -185,0 +185,0 @@ <br/>

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

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