UNPKG

validify-string

Version:

Ensure accurate and secure input with our reliable string validation library.

39 lines (38 loc) 1.52 kB
"use strict"; // Check isBase32 validation. Object.defineProperty(exports, "__esModule", { value: true }); exports.endsWithSuffix = exports.startsWithPrefix = exports.isStringWithoutSpecialCharacters = exports.isEthereumAddress = exports.isBase64 = exports.isBase32 = void 0; var isBase32 = function (str) { var b32_regex = /^[A-Z2-7]+=*$/; return b32_regex.test(str); }; exports.isBase32 = isBase32; // Check isBase64 validation. var isBase64 = function (str) { var regex = /^[A-Za-z0-9+/]+={0,2}$/; return regex.test(str); }; exports.isBase64 = isBase64; // check isEthereumAddress validation var isEthereumAddress = function (address) { var ethereumAddressRegex = /^(0x)?[0-9a-fA-F]{40}$/; // Ethereum address regex pattern return ethereumAddressRegex.test(address); }; exports.isEthereumAddress = isEthereumAddress; // specialCharactersValidation.ts function isStringWithoutSpecialCharacters(inputString) { var regex = /^[a-zA-Z0-9_]+$/; // Test if the inputString matches the regular expression return regex.test(inputString); } exports.isStringWithoutSpecialCharacters = isStringWithoutSpecialCharacters; // Check if a string starts with a specific prefix or not function startsWithPrefix(input, prefix) { return input.startsWith(prefix); } exports.startsWithPrefix = startsWithPrefix; // Check if a string ends with a specific suffix or not function endsWithSuffix(inputString, suffix) { return inputString.endsWith(suffix); } exports.endsWithSuffix = endsWithSuffix;