@zebec-fintech/silver-card-sdk
Version:
An sdk for purchasing silver card in zebec
49 lines (48 loc) • 1.53 kB
JavaScript
;
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.hashSHA256 = hashSHA256;
exports.isEmailValid = isEmailValid;
exports.isAlphaNumeric = isAlphaNumeric;
exports.areDatesOfSameDay = areDatesOfSameDay;
exports.hasMinLen = hasMinLen;
exports.hasMaxLen = hasMaxLen;
exports.hasLen = hasLen;
exports.formatAmount = formatAmount;
const crypto_1 = __importDefault(require("crypto"));
function hashSHA256(input) {
const hash = crypto_1.default.createHash("sha256");
hash.update(input);
const hex = hash.digest("hex");
return hex;
}
function isEmailValid(value) {
return /^[a-zA-Z0-9._+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,10}$/.test(value);
}
function isAlphaNumeric(value) {
return /^[a-zA-Z0-9]+$/.test(value);
}
function areDatesOfSameDay(date1, date2) {
return (date1.getUTCDay() === date2.getUTCDay() &&
date1.getUTCMonth() === date2.getUTCMonth() &&
date1.getUTCFullYear() === date2.getUTCFullYear());
}
function hasMinLen(value, len) {
return value.length >= len;
}
function hasMaxLen(value, len) {
return value.length <= len;
}
function hasLen(value, min, max) {
if (max) {
return hasMinLen(value, min) && hasMaxLen(value, max);
}
else {
return hasMinLen(value, min);
}
}
function formatAmount(amount, decimalPlaces = 2) {
return Number(Number(amount).toFixed(decimalPlaces));
}