habits-cli
Version:
The habits application seeks to help individuals build up healthy habits.
69 lines (68 loc) • 2.48 kB
JavaScript
;
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
}) : (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
o[k2] = m[k];
}));
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
Object.defineProperty(o, "default", { enumerable: true, value: v });
}) : function(o, v) {
o["default"] = v;
});
var __importStar = (this && this.__importStar) || function (mod) {
if (mod && mod.__esModule) return mod;
var result = {};
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
__setModuleDefault(result, mod);
return result;
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.schema = void 0;
var yup = __importStar(require("yup"));
exports.schema = yup;
var bson_1 = require("bson");
yup.setLocale({
mixed: {
required: "This field is required.",
},
string: {
email: "'${value}' is not a valid email address.",
},
});
function objectId() {
return this.transform(function (value) {
if (!value || bson_1.ObjectId.isValid(value)) {
return value;
}
throw new yup.ValidationError("Please enter a valid object ID.", value);
});
}
function httpUrl() {
return this.transform(function (value) {
if (!value) {
return value;
}
var match = value.match(/https?:\/\/[\w.]+(\/[.])+/);
if (!match) {
throw new yup.ValidationError("'" + value + "' is not a valid URL with HTTP/HTTPS. " +
"A valid HTTP/HTTPS URL should begin with 'http://' or 'https://'", value);
}
});
}
function propertyChange() {
return this.notOneOf([0], "Change in property amount cannot be 0. Enter a positive " +
"number to add amount, and a negative number to reduce amount.");
}
function pageLimit() {
return this.label("limit").integer().min(1);
}
function pageSkip() {
return this.label("skip").integer().min(1);
}
yup.addMethod(yup.string, "objectId", objectId);
yup.addMethod(yup.string, "httpUrl", httpUrl);
yup.addMethod(yup.number, "propertyChange", propertyChange);
yup.addMethod(yup.number, "pageLimit", pageLimit);
yup.addMethod(yup.number, "pageSkip", pageSkip);