@tunnel-cast/tunnel-cast
Version:
<br>
27 lines • 1.43 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.StartsWith = exports.startsWithMessageBuilder = exports.startsWith = exports.STARTS_WITH = void 0;
const decorator_adapter_1 = require("../../../core/factory/decorator-adapter");
const field_constraint_procedure_1 = require("../../../core/field-decorator-procedure/field-constraint.procedure");
exports.STARTS_WITH = "startsWith";
const arrayStartsWithItems = (array, prefixItems) => array.length >= prefixItems.length ? prefixItems.every((item, i) => array[i] === item) : false;
exports.startsWith = ({ fieldValue, args }) => {
if (typeof fieldValue == "string") {
return fieldValue.startsWith(args.value);
}
else if (Array.isArray(fieldValue)) {
return Array.isArray(args.value)
? arrayStartsWithItems(fieldValue, args.value)
: fieldValue.indexOf(args.value) == 0;
}
else {
return false;
}
};
exports.startsWithMessageBuilder = ({ fieldName }) => `The field ${fieldName} dose not start with the provided value.`;
function StartsWith(value, options) {
const adaptee = new field_constraint_procedure_1.FieldConstraintProcedure(exports.STARTS_WITH, options, { value }, exports.startsWith, exports.startsWithMessageBuilder);
return decorator_adapter_1.decoratorAdapter(adaptee);
}
exports.StartsWith = StartsWith;
//# sourceMappingURL=starts-with.decorator.js.map