container.ts
Version:
Modular application framework
46 lines • 1.74 kB
JavaScript
;
var __extends = (this && this.__extends) || (function () {
var extendStatics = function (d, b) {
extendStatics = Object.setPrototypeOf ||
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
return extendStatics(d, b);
};
return function (d, b) {
extendStatics(d, b);
function __() { this.constructor = d; }
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
};
})();
Object.defineProperty(exports, "__esModule", { value: true });
var fs_1 = require("fs");
var path_1 = require("path");
var validate_1 = require("../../validate");
var validate_2 = require("../validate");
/** Validate that value is a valid path to a file. */
function isFile(value) {
if (value === void 0) { value = ""; }
try {
var resolveValue = path_1.resolve(value);
if (fs_1.lstatSync(resolveValue).isFile() !== true) {
throw new validate_2.NodeValidateError(validate_2.ENodeValidateError.IsFileError, value);
}
return resolveValue;
}
catch (error) {
throw new validate_2.NodeValidateError(validate_2.ENodeValidateError.IsFileError, value, error);
}
}
exports.isFile = isFile;
var FileField = /** @class */ (function (_super) {
__extends(FileField, _super);
function FileField() {
return _super !== null && _super.apply(this, arguments) || this;
}
FileField.prototype.validate = function (value) {
return isFile(value);
};
return FileField;
}(validate_1.Field));
exports.FileField = FileField;
//# sourceMappingURL=is-file.js.map