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

@sapphire/shapeshift

Package Overview
Dependencies
Maintainers
3
Versions
464
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@sapphire/shapeshift - npm Package Compare versions

Comparing version 2.1.1-next.f7e3d67.0 to 2.2.0-next.ca5ea5f.0

154

dist/index.d.ts
/// <reference types="node" />
import { InspectOptionsStylized } from 'node:util';
declare type TypedArray = Int8Array | Uint8Array | Uint8ClampedArray | Int16Array | Uint16Array | Int32Array | Uint32Array | Float32Array | Float64Array | BigInt64Array | BigUint64Array;
declare const TypedArrays: {
readonly Int8Array: (x: unknown) => x is Int8Array;
readonly Uint8Array: (x: unknown) => x is Uint8Array;
readonly Uint8ClampedArray: (x: unknown) => x is Uint8ClampedArray;
readonly Int16Array: (x: unknown) => x is Int16Array;
readonly Uint16Array: (x: unknown) => x is Uint16Array;
readonly Int32Array: (x: unknown) => x is Int32Array;
readonly Uint32Array: (x: unknown) => x is Uint32Array;
readonly Float32Array: (x: unknown) => x is Float32Array;
readonly Float64Array: (x: unknown) => x is Float64Array;
readonly BigInt64Array: (x: unknown) => x is BigInt64Array;
readonly BigUint64Array: (x: unknown) => x is BigUint64Array;
readonly TypedArray: (x: unknown) => x is TypedArray;
};
declare type TypedArrayName = keyof typeof TypedArrays;
declare type ArrayConstraintName = `s.array(T).length${'Lt' | 'Le' | 'Gt' | 'Ge' | 'Eq' | 'Ne' | 'Range' | 'RangeInclusive' | 'RangeExclusive'}`;

@@ -15,2 +32,61 @@ declare function arrayLengthLt<T>(value: number): IConstraint<T[]>;

declare const customInspectSymbol: unique symbol;
declare const customInspectSymbolStackLess: unique symbol;
declare abstract class BaseError extends Error {
protected [customInspectSymbol](depth: number, options: InspectOptionsStylized): string;
protected abstract [customInspectSymbolStackLess](depth: number, options: InspectOptionsStylized): string;
}
declare class ExpectedConstraintError<T = unknown> extends BaseConstraintError<T> {
readonly expected: string;
constructor(constraint: ConstraintErrorNames, message: string, given: T, expected: string);
toJSON(): {
name: string;
constraint: ConstraintErrorNames;
given: T;
expected: string;
};
protected [customInspectSymbolStackLess](depth: number, options: InspectOptionsStylized): string;
}
declare class Result<T, E extends Error = Error> {
readonly success: boolean;
readonly value?: T;
readonly error?: E;
private constructor();
isOk(): this is {
success: true;
value: T;
};
isErr(): this is {
success: false;
error: E;
};
unwrap(): T;
static ok<T, E extends Error = Error>(value: T): Result<T, E>;
static err<T, E extends Error = Error>(error: E): Result<T, E>;
}
declare type TypedArrayConstraintName = `s.typedArray(T).${'byteLength' | 'length'}${'Lt' | 'Le' | 'Gt' | 'Ge' | 'Eq' | 'Ne' | 'Range' | 'RangeInclusive' | 'RangeExclusive'}`;
declare function typedArrayByteLengthLt<T extends TypedArray>(value: number): IConstraint<T>;
declare function typedArrayByteLengthLe<T extends TypedArray>(value: number): IConstraint<T>;
declare function typedArrayByteLengthGt<T extends TypedArray>(value: number): IConstraint<T>;
declare function typedArrayByteLengthGe<T extends TypedArray>(value: number): IConstraint<T>;
declare function typedArrayByteLengthEq<T extends TypedArray>(value: number): IConstraint<T>;
declare function typedArrayByteLengthNe<T extends TypedArray>(value: number): IConstraint<T>;
declare function typedArrayByteLengthRange<T extends TypedArray>(start: number, endBefore: number): IConstraint<T>;
declare function typedArrayByteLengthRangeInclusive<T extends TypedArray>(start: number, end: number): {
run(input: T): Result<T, Error> | Result<unknown, ExpectedConstraintError<T>>;
};
declare function typedArrayByteLengthRangeExclusive<T extends TypedArray>(startAfter: number, endBefore: number): IConstraint<T>;
declare function typedArrayLengthLt<T extends TypedArray>(value: number): IConstraint<T>;
declare function typedArrayLengthLe<T extends TypedArray>(value: number): IConstraint<T>;
declare function typedArrayLengthGt<T extends TypedArray>(value: number): IConstraint<T>;
declare function typedArrayLengthGe<T extends TypedArray>(value: number): IConstraint<T>;
declare function typedArrayLengthEq<T extends TypedArray>(value: number): IConstraint<T>;
declare function typedArrayLengthNe<T extends TypedArray>(value: number): IConstraint<T>;
declare function typedArrayLengthRange<T extends TypedArray>(start: number, endBefore: number): IConstraint<T>;
declare function typedArrayLengthRangeInclusive<T extends TypedArray>(start: number, end: number): IConstraint<T>;
declare function typedArrayLengthRangeExclusive<T extends TypedArray>(startAfter: number, endBefore: number): IConstraint<T>;
declare type BigIntConstraintName = `s.bigint.${'lt' | 'le' | 'gt' | 'ge' | 'eq' | 'ne' | 'divisibleBy'}`;

@@ -77,10 +153,3 @@ declare function bigintLt(value: bigint): IConstraint<bigint>;

declare const customInspectSymbol: unique symbol;
declare const customInspectSymbolStackLess: unique symbol;
declare abstract class BaseError extends Error {
protected [customInspectSymbol](depth: number, options: InspectOptionsStylized): string;
protected abstract [customInspectSymbolStackLess](depth: number, options: InspectOptionsStylized): string;
}
declare type ConstraintErrorNames = ArrayConstraintName | BigIntConstraintName | BooleanConstraintName | DateConstraintName | NumberConstraintName | StringConstraintName;
declare type ConstraintErrorNames = TypedArrayConstraintName | ArrayConstraintName | BigIntConstraintName | BooleanConstraintName | DateConstraintName | NumberConstraintName | StringConstraintName;
declare abstract class BaseConstraintError<T = unknown> extends BaseError {

@@ -92,20 +161,2 @@ readonly constraint: ConstraintErrorNames;

declare class Result<T, E extends Error = Error> {
readonly success: boolean;
readonly value?: T;
readonly error?: E;
private constructor();
isOk(): this is {
success: true;
value: T;
};
isErr(): this is {
success: false;
error: E;
};
unwrap(): T;
static ok<T, E extends Error = Error>(value: T): Result<T, E>;
static err<T, E extends Error = Error>(error: E): Result<T, E>;
}
interface IConstraint<Input, Return extends Input = Input> {

@@ -413,2 +464,27 @@ run(input: Input): Result<Return, BaseConstraintError<Input>>;

declare class TypedArrayValidator<T extends TypedArray> extends BaseValidator<T> {
private readonly type;
constructor(type: TypedArrayName, constraints?: readonly IConstraint<T>[]);
byteLengthLt(length: number): this;
byteLengthLe(length: number): this;
byteLengthGt(length: number): this;
byteLengthGe(length: number): this;
byteLengthEq(length: number): this;
byteLengthNe(length: number): this;
byteLengthRange(start: number, endBefore: number): this;
byteLengthRangeInclusive(startAt: number, endAt: number): this;
byteLengthRangeExclusive(startAfter: number, endBefore: number): this;
lengthLt(length: number): this;
lengthLe(length: number): this;
lengthGt(length: number): this;
lengthGe(length: number): this;
lengthEq(length: number): this;
lengthNe(length: number): this;
lengthRange(start: number, endBefore: number): this;
lengthRangeInclusive(startAt: number, endAt: number): this;
lengthRangeExclusive(startAfter: number, endBefore: number): this;
protected clone(): this;
protected handle(value: unknown): Result<T, ValidationError>;
}
declare class Shapes {

@@ -433,2 +509,14 @@ get string(): StringValidator<string>;

array<T>(validator: BaseValidator<T>): ArrayValidator<T>;
typedArray<T extends TypedArray>(type?: TypedArrayName): TypedArrayValidator<T>;
get int8Array(): TypedArrayValidator<Int8Array>;
get uint8Array(): TypedArrayValidator<Uint8Array>;
get uint8ClampedArray(): TypedArrayValidator<Uint8ClampedArray>;
get int16Array(): TypedArrayValidator<Int16Array>;
get uint16Array(): TypedArrayValidator<Uint16Array>;
get int32Array(): TypedArrayValidator<Int32Array>;
get uint32Array(): TypedArrayValidator<Uint32Array>;
get float32Array(): TypedArrayValidator<Float32Array>;
get float64Array(): TypedArrayValidator<Float64Array>;
get bigInt64Array(): TypedArrayValidator<BigInt64Array>;
get bigUint64Array(): TypedArrayValidator<BigUint64Array>;
tuple<T extends [...BaseValidator<any>[]]>(validators: [...T]): TupleValidator<UnwrapTuple<T>>;

@@ -442,14 +530,2 @@ set<T>(validator: BaseValidator<T>): SetValidator<T>;

declare class ExpectedConstraintError<T = unknown> extends BaseConstraintError<T> {
readonly expected: string;
constructor(constraint: ConstraintErrorNames, message: string, given: T, expected: string);
toJSON(): {
name: string;
constraint: ConstraintErrorNames;
given: T;
expected: string;
};
protected [customInspectSymbolStackLess](depth: number, options: InspectOptionsStylized): string;
}
declare class MissingPropertyError extends BaseError {

@@ -491,2 +567,2 @@ readonly property: PropertyKey;

export { ArrayConstraintName, ArrayValidator, BaseConstraintError, BaseError, BaseValidator, BigIntConstraintName, BigIntValidator, BooleanConstraintName, BooleanValidator, CombinedError, CombinedPropertyError, ConstraintErrorNames, Constructor, DateConstraintName, DateValidator, DefaultValidator, ExpandSmallerTuples, ExpectedConstraintError, ExpectedValidationError, GrowExp, GrowExpRev, IConstraint, InstanceValidator, LiteralValidator, MapValidator, MappedObjectValidator, MissingPropertyError, MultiplePossibilitiesConstraintError, NativeEnumLike, NativeEnumValidator, NeverValidator, NonNullObject, NullishValidator, NumberConstraintName, NumberValidator, ObjectValidator, ObjectValidatorStrategy, PassthroughValidator, RecordValidator, Result, SetValidator, Shapes, Shift, StringConstraintName, StringDomain, StringProtocol, StringUuidOptions, StringValidator, Tuple, TupleValidator, Type, UUIDVersion, UnionValidator, UnknownEnumValueError, UnknownPropertyError, UnshiftTuple, Unwrap, UnwrapTuple, UrlOptions, ValidationError, ValidatorError, arrayLengthEq, arrayLengthGe, arrayLengthGt, arrayLengthLe, arrayLengthLt, arrayLengthNe, arrayLengthRange, arrayLengthRangeExclusive, arrayLengthRangeInclusive, bigintDivisibleBy, bigintEq, bigintGe, bigintGt, bigintLe, bigintLt, bigintNe, booleanFalse, booleanTrue, customInspectSymbol, customInspectSymbolStackLess, dateEq, dateGe, dateGt, dateInvalid, dateLe, dateLt, dateNe, dateValid, numberDivisibleBy, numberEq, numberFinite, numberGe, numberGt, numberInt, numberLe, numberLt, numberNaN, numberNe, numberNeNaN, numberSafeInt, s, stringEmail, stringIp, stringLengthEq, stringLengthGe, stringLengthGt, stringLengthLe, stringLengthLt, stringLengthNe, stringRegex, stringUrl, stringUuid };
export { ArrayConstraintName, ArrayValidator, BaseConstraintError, BaseError, BaseValidator, BigIntConstraintName, BigIntValidator, BooleanConstraintName, BooleanValidator, CombinedError, CombinedPropertyError, ConstraintErrorNames, Constructor, DateConstraintName, DateValidator, DefaultValidator, ExpandSmallerTuples, ExpectedConstraintError, ExpectedValidationError, GrowExp, GrowExpRev, IConstraint, InstanceValidator, LiteralValidator, MapValidator, MappedObjectValidator, MissingPropertyError, MultiplePossibilitiesConstraintError, NativeEnumLike, NativeEnumValidator, NeverValidator, NonNullObject, NullishValidator, NumberConstraintName, NumberValidator, ObjectValidator, ObjectValidatorStrategy, PassthroughValidator, RecordValidator, Result, SetValidator, Shapes, Shift, StringConstraintName, StringDomain, StringProtocol, StringUuidOptions, StringValidator, Tuple, TupleValidator, Type, TypedArrayConstraintName, TypedArrayValidator, UUIDVersion, UnionValidator, UnknownEnumValueError, UnknownPropertyError, UnshiftTuple, Unwrap, UnwrapTuple, UrlOptions, ValidationError, ValidatorError, arrayLengthEq, arrayLengthGe, arrayLengthGt, arrayLengthLe, arrayLengthLt, arrayLengthNe, arrayLengthRange, arrayLengthRangeExclusive, arrayLengthRangeInclusive, bigintDivisibleBy, bigintEq, bigintGe, bigintGt, bigintLe, bigintLt, bigintNe, booleanFalse, booleanTrue, customInspectSymbol, customInspectSymbolStackLess, dateEq, dateGe, dateGt, dateInvalid, dateLe, dateLt, dateNe, dateValid, numberDivisibleBy, numberEq, numberFinite, numberGe, numberGt, numberInt, numberLe, numberLt, numberNaN, numberNe, numberNeNaN, numberSafeInt, s, stringEmail, stringIp, stringLengthEq, stringLengthGe, stringLengthGt, stringLengthLe, stringLengthLt, stringLengthNe, stringRegex, stringUrl, stringUuid, typedArrayByteLengthEq, typedArrayByteLengthGe, typedArrayByteLengthGt, typedArrayByteLengthLe, typedArrayByteLengthLt, typedArrayByteLengthNe, typedArrayByteLengthRange, typedArrayByteLengthRangeExclusive, typedArrayByteLengthRangeInclusive, typedArrayLengthEq, typedArrayLengthGe, typedArrayLengthGt, typedArrayLengthLe, typedArrayLengthLt, typedArrayLengthNe, typedArrayLengthRange, typedArrayLengthRangeExclusive, typedArrayLengthRangeInclusive };
{
"name": "@sapphire/shapeshift",
"version": "2.1.1-next.f7e3d67.0",
"version": "2.2.0-next.ca5ea5f.0",
"description": "Blazing fast input validation and transformation ⚡",

@@ -5,0 +5,0 @@ "author": "@sapphire",

@@ -285,8 +285,6 @@ <div align="center">

```typescript
const user = s
.object({
username: s.string,
password: s.string
})
.partial;
const user = s.object({
username: s.string,
password: s.string
}).partial;
```

@@ -427,2 +425,35 @@

#### TypedArray
```ts
const typedArray = s.typedArray();
const int16Array = s.int16Array;
const uint16Array = s.uint16Array;
const uint8ClampedArray = s.uint8ClampedArray;
const int16Array = s.int16Array;
const uint16Array = s.uint16Array;
const int32Array = s.int32Array;
const uint32Array = s.uint32Array;
const float32Array = s.float32Array;
const float64Array = s.float64Array;
const bigInt64Array = s.bigInt64Array;
const bigUint64Array = s.bigUint64Array;
```
ShapeShift includes a handful of validations specific to typed arrays.
```typescript
s.typedArray().lengthLt(5); // Length must be less than 5
s.typedArray().lengthLe(5); // Length must be 5 or less
s.typedArray().lengthGt(5); // Length must be more than 5
s.typedArray().lengthGe(5); // Length must be 5 or more
s.typedArray().lengthEq(5); // Length must be exactly 5
s.typedArray().lengthNe(5); // Length must not be 5
s.typedArray().lengthRange(0, 4); // Length L must satisfy 0 <= L < 4
s.typedArray().lengthRangeInclusive(0, 4); // Length L must satisfy 0 <= L <= 4
s.typedArray().lengthRangeExclusive(0, 4); // Length L must satisfy 0 < L < 4
```
Note that all of these methods have analogous methods for working with the typed array's byte length, `s.typedArray().byteLengthX()` - for instance, `s.typedArray().byteLengthLt(5)` is the same as `s.typedArray().lengthLt(5)` but for the array's byte length.
### BaseValidator: methods and properties

@@ -429,0 +460,0 @@

Sorry, the diff of this file is too big to display

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is too big to display

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