enonic-wizardry
Advanced tools
Comparing version 0.3.3 to 0.3.4
{ | ||
"name": "enonic-wizardry", | ||
"sideEffects": false, | ||
"version": "0.3.3", | ||
"version": "0.3.4", | ||
"description": "Functional utility library for Enonic XP", | ||
@@ -6,0 +6,0 @@ "main": "lib/index.js", |
@@ -42,2 +42,5 @@ "use strict"; | ||
} | ||
/** | ||
* Used for i18n to differenciate empty value | ||
*/ | ||
function isLastEmpty(context) { | ||
@@ -44,0 +47,0 @@ var _a; |
@@ -5,4 +5,24 @@ import { Type } from 'io-ts'; | ||
import { IOEither } from "fp-ts/IOEither"; | ||
export declare function validate<A, O = A, I = unknown>(a: Type<A, O, I>, i18nPrefix?: string): (i: I) => IOEither<EnonicError, A>; | ||
export declare const RegexpValidatedString: (regexp: RegExp) => t.Type<string, string, unknown>; | ||
export declare const MaxLengthValidatedString: (maxLength: number) => t.Type<string, string, unknown>; | ||
export declare function validate<A, O = A, I = unknown>(a: Type<A, O, I>, params?: ValidateParams): (i: I) => IOEither<EnonicError, A>; | ||
export interface ValidateParams { | ||
readonly i18nPrefix?: string; | ||
} | ||
export interface RegexpValidatedStringProps<A extends boolean = false> { | ||
readonly regexp: RegExp; | ||
readonly isNullable?: A; | ||
} | ||
export declare function RegexpValidatedString<A extends string>(props: RegexpValidatedStringProps): t.Type<A, A, unknown>; | ||
export declare function RegexpValidatedString<A extends string | undefined>(props: RegexpValidatedStringProps<true>): t.Type<A, A, unknown>; | ||
export interface MaxLengthValidatedStringProps<A extends boolean = false> { | ||
readonly maxLength: number; | ||
readonly isNullable?: A; | ||
} | ||
export declare function MaxLengthValidatedString<A extends string>(props: MaxLengthValidatedStringProps): t.Type<A, A, unknown>; | ||
export declare function MaxLengthValidatedString<A extends string | undefined>(props: MaxLengthValidatedStringProps<true>): t.Type<A, A, unknown>; | ||
export interface MinMaxValidatedNumberProps<A extends boolean = false> { | ||
readonly min?: number; | ||
readonly max?: number; | ||
readonly isNullable?: A; | ||
} | ||
export declare function MinMaxValidatedNumber<A extends number>(props: MinMaxValidatedNumberProps): t.Type<A, A, unknown>; | ||
export declare function MinMaxValidatedNumber<A extends number | undefined>(props: MinMaxValidatedNumberProps<true>): t.Type<A, A, unknown>; |
@@ -14,5 +14,4 @@ "use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.MaxLengthValidatedString = exports.RegexpValidatedString = exports.validate = void 0; | ||
exports.MinMaxValidatedNumber = exports.MaxLengthValidatedString = exports.RegexpValidatedString = exports.validate = void 0; | ||
var t = require("io-ts"); | ||
var Either_1 = require("fp-ts/Either"); | ||
var ErrorDetailReporter_1 = require("./reporters/ErrorDetailReporter"); | ||
@@ -22,18 +21,35 @@ var errors_1 = require("enonic-fp/errors"); | ||
var pipeable_1 = require("fp-ts/pipeable"); | ||
function validate(a, i18nPrefix) { | ||
function validate(a, params) { | ||
return function (i) { | ||
var decoded = a.decode(i); | ||
return pipeable_1.pipe(decoded, IOEither_1.fromEither, IOEither_1.mapLeft(function () { return (__assign(__assign({}, errors_1.badRequestError), { errors: ErrorDetailReporter_1.getErrorDetailReporter(i18nPrefix).report(decoded) })); })); | ||
return pipeable_1.pipe(decoded, IOEither_1.fromEither, IOEither_1.mapLeft(function () { return (__assign(__assign({}, errors_1.badRequestError), { errors: ErrorDetailReporter_1.getErrorDetailReporter(params === null || params === void 0 ? void 0 : params.i18nPrefix).report(decoded) })); })); | ||
}; | ||
} | ||
exports.validate = validate; | ||
exports.RegexpValidatedString = function (regexp) { return new t.Type('RegexpValidatedString', function (u) { return t.string.is(u) && regexp.test(String(u)); }, function (u, c) { | ||
return Either_1.either.chain(t.string.validate(u, c), function (s) { | ||
return regexp.test(s) ? t.success(s) : t.failure(u, c); | ||
}); | ||
}, t.identity); }; | ||
exports.MaxLengthValidatedString = function (maxLength) { return new t.Type('MaxLengthValidatedString', function (u) { return t.string.is(u) && u.length <= maxLength; }, function (u, c) { | ||
return Either_1.either.chain(t.string.validate(u, c), function (s) { | ||
return s.length <= maxLength ? t.success(s) : t.failure(u, c); | ||
}); | ||
}, t.identity); }; | ||
function RegexpValidatedString(_a) { | ||
var regexp = _a.regexp, _b = _a.isNullable, isNullable = _b === void 0 ? false : _b; | ||
return new t.Type('RegexpValidatedString', function (u) { return (typeof u === "string" && regexp.test(u)) || (isNullable && u === undefined); }, function (u, c) { | ||
return (typeof u === "string" && regexp.test(u)) || (isNullable && u === undefined) | ||
? t.success(u) | ||
: t.failure(u, c); | ||
}, t.identity); | ||
} | ||
exports.RegexpValidatedString = RegexpValidatedString; | ||
function MaxLengthValidatedString(_a) { | ||
var maxLength = _a.maxLength, _b = _a.isNullable, isNullable = _b === void 0 ? false : _b; | ||
return new t.Type('MaxLengthValidatedString', function (u) { return (typeof u === "string" && u.length <= maxLength) || (isNullable && u === undefined); }, function (u, c) { | ||
return (typeof u === "string" && u.length <= maxLength) || (isNullable && u === undefined) | ||
? t.success(u) | ||
: t.failure(u, c); | ||
}, t.identity); | ||
} | ||
exports.MaxLengthValidatedString = MaxLengthValidatedString; | ||
function MinMaxValidatedNumber(_a) { | ||
var _b = _a.min, min = _b === void 0 ? Number.NEGATIVE_INFINITY : _b, _c = _a.max, max = _c === void 0 ? Number.POSITIVE_INFINITY : _c, _d = _a.isNullable, isNullable = _d === void 0 ? false : _d; | ||
return new t.Type('MinMaxValidatedNumber', function (u) { return (t.number.is(u) && (min <= u) && (u <= max)) || (isNullable && u === undefined); }, function (u, c) { | ||
return (t.number.is(u) && (min <= u) && (u <= max)) || (isNullable && u === undefined) | ||
? t.success(u) | ||
: t.failure(u, c); | ||
}, t.identity); | ||
} | ||
exports.MinMaxValidatedNumber = MinMaxValidatedNumber; |
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
22027
17
338