UNPKG

jaywalk

Version:
41 lines 1.53 kB
"use strict"; var __extends = (this && this.__extends) || function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; function __() { this.constructor = d; } d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); }; var any_1 = require('./any'); var utils_1 = require('../utils'); var _toString = Object.prototype.toString; var DateTime = (function (_super) { __extends(DateTime, _super); function DateTime(options) { if (options === void 0) { options = {}; } _super.call(this, options); this.type = 'DateTime'; this._tests.push(isDate); } DateTime.prototype._isType = function (value, path, context) { return utils_1.wrapIsType(this, value, path, context, _super.prototype._isType, function (value) { if (_toString.call(value) === '[object Date]') { return 1; } throw context.error(path, 'Date', 'type', 'Date', value); }); }; DateTime.prototype._extend = function (options) { return _super.prototype._extend.call(this, options); }; return DateTime; }(any_1.Any)); exports.DateTime = DateTime; function isDate(value, path, context, next) { if (_toString.call(value) !== '[object Date]') { throw context.error(path, 'Date', 'type', 'Date', value); } if (isNaN(value.getTime())) { throw context.error(path, 'Date', 'type', 'Date', value); } return next(value); } //# sourceMappingURL=date-time.js.map