@sapphire/shapeshift
Advanced tools
Comparing version 1.1.0-next.2aa3271.0 to 1.1.0-next.34eeb5a.0
@@ -12,3 +12,3 @@ /// <reference types="node" /> | ||
declare type BigIntConstraintName = `s.bigint.${'lt' | 'le' | 'gt' | 'ge' | 'eq' | 'ne'}`; | ||
declare type BigIntConstraintName = `s.bigint.${'lt' | 'le' | 'gt' | 'ge' | 'eq' | 'ne' | 'divisibleBy'}`; | ||
declare function bigintLt(value: bigint): IConstraint<bigint>; | ||
@@ -20,2 +20,3 @@ declare function bigintLe(value: bigint): IConstraint<bigint>; | ||
declare function bigintNe(value: bigint): IConstraint<bigint>; | ||
declare function bigintDivisibleBy(divider: bigint): IConstraint<bigint>; | ||
@@ -155,2 +156,6 @@ declare type BooleanConstraintName = `s.boolean.${boolean}`; | ||
get negative(): this; | ||
divisibleBy(number: bigint): this; | ||
get abs(): this; | ||
intN(bits: number): this; | ||
uintN(bits: number): this; | ||
protected handle(value: unknown): Result<T, ValidationError>; | ||
@@ -373,2 +378,2 @@ } | ||
export { ArrayConstraintName, ArrayValidator, BaseError, BaseValidator, BigIntConstraintName, BigIntValidator, BooleanConstraintName, BooleanValidator, CombinedError, ConstraintError, ConstraintErrorNames, Constructor, DateConstraintName, DateValidator, DefaultValidator, ExpectedValidationError, IConstraint, InstanceValidator, LiteralValidator, MapValidator, MappedObjectValidator, MissingPropertyError, NeverValidator, NonNullObject, NullishValidator, NumberConstraintName, NumberValidator, ObjectValidator, ObjectValidatorStrategy, PassthroughValidator, RecordValidator, Result, SetValidator, Shapes, StringConstraintName, StringValidator, Type, UnionValidator, UnknownPropertyError, ValidationError, arrayLengthEq, arrayLengthGe, arrayLengthGt, arrayLengthLe, arrayLengthLt, arrayLengthNe, bigintEq, bigintGe, bigintGt, bigintLe, bigintLt, bigintNe, booleanFalse, booleanTrue, dateEq, dateGe, dateGt, dateInvalid, dateLe, dateLt, dateNe, dateValid, numberDivisibleBy, numberEq, numberFinite, numberGe, numberGt, numberInt, numberLe, numberLt, numberNaN, numberNe, numberNeNaN, numberSafeInt, s, stringLengthEq, stringLengthGe, stringLengthGt, stringLengthLe, stringLengthLt, stringLengthNe }; | ||
export { ArrayConstraintName, ArrayValidator, BaseError, BaseValidator, BigIntConstraintName, BigIntValidator, BooleanConstraintName, BooleanValidator, CombinedError, ConstraintError, ConstraintErrorNames, Constructor, DateConstraintName, DateValidator, DefaultValidator, ExpectedValidationError, IConstraint, InstanceValidator, LiteralValidator, MapValidator, MappedObjectValidator, MissingPropertyError, NeverValidator, NonNullObject, NullishValidator, NumberConstraintName, NumberValidator, ObjectValidator, ObjectValidatorStrategy, PassthroughValidator, RecordValidator, Result, SetValidator, Shapes, StringConstraintName, StringValidator, Type, UnionValidator, UnknownPropertyError, ValidationError, arrayLengthEq, arrayLengthGe, arrayLengthGt, arrayLengthLe, arrayLengthLt, arrayLengthNe, bigintDivisibleBy, bigintEq, bigintGe, bigintGt, bigintLe, bigintLt, bigintNe, booleanFalse, booleanTrue, dateEq, dateGe, dateGt, dateInvalid, dateLe, dateLt, dateNe, dateValid, numberDivisibleBy, numberEq, numberFinite, numberGe, numberGt, numberInt, numberLe, numberLt, numberNaN, numberNe, numberNeNaN, numberSafeInt, s, stringLengthEq, stringLengthGe, stringLengthGt, stringLengthLe, stringLengthLt, stringLengthNe }; |
@@ -337,2 +337,11 @@ var SapphireShapeshift = (() => { | ||
__name(bigintNe, "bigintNe"); | ||
function bigintDivisibleBy(divider) { | ||
const expected = `expected % ${divider}n === 0n`; | ||
return { | ||
run(input) { | ||
return input % divider === 0n ? Result.ok(input) : Result.err(new ConstraintError("s.bigint.divisibleBy", "BigInt is not divisible", input, expected)); | ||
} | ||
}; | ||
} | ||
__name(bigintDivisibleBy, "bigintDivisibleBy"); | ||
@@ -365,2 +374,14 @@ // src/validators/BigIntValidator.ts | ||
} | ||
divisibleBy(number) { | ||
return this.addConstraint(bigintDivisibleBy(number)); | ||
} | ||
get abs() { | ||
return this.transform((value) => value < 0 ? -value : value); | ||
} | ||
intN(bits) { | ||
return this.transform((value) => BigInt.asIntN(bits, value)); | ||
} | ||
uintN(bits) { | ||
return this.transform((value) => BigInt.asUintN(bits, value)); | ||
} | ||
handle(value) { | ||
@@ -367,0 +388,0 @@ return typeof value === "bigint" ? Result.ok(value) : Result.err(new ValidationError("BigIntValidator", "Expected a bigint primitive", value)); |
@@ -330,2 +330,11 @@ "use strict"; | ||
__name(bigintNe, "bigintNe"); | ||
function bigintDivisibleBy(divider) { | ||
const expected = `expected % ${divider}n === 0n`; | ||
return { | ||
run(input) { | ||
return input % divider === 0n ? Result.ok(input) : Result.err(new ConstraintError("s.bigint.divisibleBy", "BigInt is not divisible", input, expected)); | ||
} | ||
}; | ||
} | ||
__name(bigintDivisibleBy, "bigintDivisibleBy"); | ||
@@ -358,2 +367,14 @@ // src/validators/BigIntValidator.ts | ||
} | ||
divisibleBy(number) { | ||
return this.addConstraint(bigintDivisibleBy(number)); | ||
} | ||
get abs() { | ||
return this.transform((value) => value < 0 ? -value : value); | ||
} | ||
intN(bits) { | ||
return this.transform((value) => BigInt.asIntN(bits, value)); | ||
} | ||
uintN(bits) { | ||
return this.transform((value) => BigInt.asUintN(bits, value)); | ||
} | ||
handle(value) { | ||
@@ -360,0 +381,0 @@ return typeof value === "bigint" ? Result.ok(value) : Result.err(new ValidationError("BigIntValidator", "Expected a bigint primitive", value)); |
{ | ||
"name": "@sapphire/shapeshift", | ||
"version": "1.1.0-next.2aa3271.0", | ||
"version": "1.1.0-next.34eeb5a.0", | ||
"description": "Blazing fast input validation and transformation ⚡", | ||
@@ -33,4 +33,4 @@ "author": "@sapphire", | ||
"devDependencies": { | ||
"@commitlint/cli": "^16.1.0", | ||
"@commitlint/config-conventional": "^16.0.0", | ||
"@commitlint/cli": "^16.2.1", | ||
"@commitlint/config-conventional": "^16.2.1", | ||
"@favware/npm-deprecate": "^1.0.4", | ||
@@ -40,14 +40,14 @@ "@favware/rollup-type-bundler": "^1.0.7", | ||
"@sapphire/prettier-config": "^1.3.0", | ||
"@sapphire/ts-config": "^3.3.0", | ||
"@sapphire/ts-config": "^3.3.1", | ||
"@types/jest": "^27.4.0", | ||
"@types/node": "^17.0.8", | ||
"@typescript-eslint/eslint-plugin": "^5.10.2", | ||
"@typescript-eslint/parser": "^5.10.2", | ||
"@typescript-eslint/eslint-plugin": "^5.11.0", | ||
"@typescript-eslint/parser": "^5.11.0", | ||
"cz-conventional-changelog": "^3.3.0", | ||
"eslint": "~8.8.0", | ||
"eslint": "~8.9.0", | ||
"eslint-config-prettier": "^8.3.0", | ||
"eslint-plugin-prettier": "^4.0.0", | ||
"husky": "^7.0.4", | ||
"jest": "^27.5.0", | ||
"jest-circus": "^27.5.0", | ||
"jest": "^27.5.1", | ||
"jest-circus": "^27.5.1", | ||
"lint-staged": "^12.3.3", | ||
@@ -58,3 +58,3 @@ "prettier": "^2.5.1", | ||
"ts-jest": "^27.1.3", | ||
"ts-node": "^10.4.0", | ||
"ts-node": "^10.5.0", | ||
"tsup": "^5.11.13", | ||
@@ -61,0 +61,0 @@ "typedoc": "^0.22.11", |
@@ -166,3 +166,3 @@ <div align="center"> | ||
s.bigint.divisibleBy(5n); // TODO | Divisible by 5n | ||
s.bigint.divisibleBy(5n); // Divisible by 5n | ||
``` | ||
@@ -173,6 +173,6 @@ | ||
```typescript | ||
s.bigint.abs; // TODO | Transforms the bigint to an absolute bigint | ||
s.bigint.abs; // Transforms the bigint to an absolute bigint | ||
s.bigint.intN(5); // TODO | Clamps to a bigint to a signed bigint with 5 digits, see BigInt.asIntN | ||
s.bigint.uintN(5); // TODO | Clamps to a bigint to an unsigned bigint with 5 digits, see BigInt.asUintN | ||
s.bigint.intN(5); // Clamps to a bigint to a signed bigint with 5 digits, see BigInt.asIntN | ||
s.bigint.uintN(5); // Clamps to a bigint to an unsigned bigint with 5 digits, see BigInt.asUintN | ||
``` | ||
@@ -179,0 +179,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
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
398167
3825