one-schema
Version:
one-schema object validator
34 lines (33 loc) • 1.15 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
function checkIsInt64Digits(x, isNeg) {
var neg = isNeg === true;
if (typeof x === 'string') {
var len = x.length;
var INT64_DIGITS = [
0x39, 0x32, 0x32, 0x33,
0x33, 0x37, 0x32, 0x30,
0x33, 0x36, 0x38, 0x35,
0x34, 0x37, 0x37, 0x35,
0x38, 0x30, neg === true ? 0x38 : 0x37,
];
if (len > 0 && len < 19) {
return !(/[^0-9]/.test(x));
}
if (len === 19 && !(/[^0-9]/.test(x))) {
for (var i = 0; i < 19; i++) {
var c = INT64_DIGITS[i] - x.charCodeAt(i);
if (c > 0) {
return true;
}
if (c < 0) {
return false;
}
}
return true;
}
return false;
}
return false;
}
exports.default = (function (input) { return (typeof input === 'string' && input.length !== 0 && (input.charAt(0) === '-' ? checkIsInt64Digits(input.substring(1), true) : checkIsInt64Digits(input, false))); });