UNPKG

stringman

Version:

Stringman does string manipulation and other string operations. Do anything from lightening color codes to swapping email address in a string!

73 lines (72 loc) 2.02 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.numbers = void 0; const common_1 = require("./utility/common"); function containsNum(num) { if (typeof num === 'number') { return true; } if (typeof num === 'string') { return common_1.common.isValid(num, /-?\d/g); } return false; } function whole(num) { if (typeof num !== 'string' && typeof num !== 'number') { return false; } return common_1.common.isValid(num.toString(), /^-?\d+$/g); } function decimal(num) { if (typeof num !== 'string' && typeof num !== 'number') { return false; } return common_1.common.isValid(num.toString(), /^-?\d*\.\d+$/g); } function containsDecimal(num) { if (typeof num === 'string') { return common_1.common.isValid(num.toString(), /-?\d*\.\d+/g); } if (typeof num === 'number') { return decimal(num); } return false; } function fraction(num) { if (typeof num !== 'string') { return false; } return common_1.common.isValid(num, /^-?\d*\/\d+$/g); } function containsFraction(num) { if (typeof num !== 'string') { return false; } return common_1.common.isValid(num, /-?\d*\/\d+/g); } function convertToHex(num) { if (typeof num !== 'string' && typeof num !== 'number') { return null; } const value = typeof num === 'string' ? parseFloat(num) : num; const hex = value.toString(16); return hex.length === 1 ? '0' + hex.toUpperCase() : hex.toUpperCase(); } function isPhoneNumber(str) { if (typeof str !== 'string' && typeof str !== 'number') { return false; } const test = typeof str === 'number' ? str.toString() : str; return common_1.common.isValid(test, /^[\+]?[(]?[0-9]{3}[)]?[-\s\.]?[0-9]{3}[-\s\.]?[0-9]{4,6}$/im); } const numbers = { containsDecimal, containsFraction, containsNum, convertToHex, decimal, fraction, isPhoneNumber, whole }; exports.numbers = numbers;