bguard
Version:
**bguard** is a powerful, flexible, and type-safe validation library for TypeScript. It allows developers to define validation schemas for their data structures and ensures that data conforms to the expected types and constraints.
69 lines (53 loc) • 2.37 kB
JavaScript
;Object.defineProperty(exports, "__esModule", {value: true}); var _class;
var _chunkPAV4SQQLjs = require('./chunk-PAV4SQQL.js');
var _chunkTLPVFRWRjs = require('./chunk-TLPVFRWR.js');
var _chunkXDVSL5B6js = require('./chunk-XDVSL5B6.js');
var _chunkVN4GLOENjs = require('./chunk-VN4GLOEN.js');
var _chunkFIDPCCCWjs = require('./chunk-FIDPCCCW.js');
var _chunkAXKX5BGHjs = require('./chunk-AXKX5BGH.js');
// src/asserts/string/index.ts
function string() {
return new StringSchema({ type: ["string"], requiredValidations: [] });
}
var StringSchema = (_class = class extends _chunkVN4GLOENjs.CommonSchema {constructor(...args) { super(...args); _class.prototype.__init.call(this); }
__init() {this._string = 1}
/**
* @method equalTo
* @description Restricts the schema to exactly match the specified value and infers the literal value as the TypeScript type.
* @param expectedValue - The value that the schema must exactly match.
* @returns The schema instance restricted to the specified value, with the literal value inferred as the TypeScript type
* @example
* string().equalTo('hello'); // Infers the type 'hello'
*
* @public
*/
equalTo(expectedValue) {
this.limitCheck();
_chunkXDVSL5B6js._setStrictType.call(void 0, this, `'${expectedValue}'`);
return this.custom(_chunkTLPVFRWRjs.equalTo.call(void 0, expectedValue));
}
/**
* @method oneOfValues
* @description Restricts the schema to match one of the specified values and infers the union of those values as the TypeScript type.
* @param expectedValues - An array of values that the schema can match.
* @returns The schema instance restricted to one of the specified values, with the union of those values inferred as the TypeScript type.
* @example
* string().oneOfValues(['foo', 'bar']); // Infers the type 'foo' | 'bar'
*
* @public
*/
oneOfValues(expectedValue) {
this.limitCheck();
_chunkXDVSL5B6js._setStrictType.call(void 0,
this,
expectedValue.map((el) => `'${el}'`)
);
return this.custom(_chunkPAV4SQQLjs.oneOfValues.call(void 0, expectedValue));
}
limitCheck() {
if (this.limit) throw new (0, _chunkFIDPCCCWjs.BuildSchemaError)(_chunkAXKX5BGHjs.ONLY_ONCE);
this.limit = true;
}
}, _class);
exports.string = string;
//# sourceMappingURL=chunk-D6G32F2K.js.map