UNPKG

regexp-toolkit

Version:
39 lines (35 loc) 1.29 kB
#!/usr/bin/env node "use strict"; // src/validators/validators.ts var validators = { email: (val) => /^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(val), phone: (val) => /^\+?[0-9]{10,15}$/.test(val), url: (val) => /^(https?|ftp):\/\/[^\s/$.?#].[^\s]*$/i.test(val), ipv4: (val) => /^(25[0-5]|2[0-4]\d|1\d{2}|[1-9]?\d)(\.(?!$)|$){4}$/.test(val), hex: (val) => /^#?([0-9a-fA-F]{3}|[0-9a-fA-F]{6})$/.test(val), username: (val) => /^[a-zA-Z0-9_]+$/.test(val), password: (val) => /^(?=.*[A-Za-z])(?=.*\d)[A-Za-z\d@$!%*#?&]{6,}$/.test(val), slug: (val) => /^[a-z0-9]+(?:-[a-z0-9]+)*$/.test(val), date: (val) => /^\d{4}-\d{2}-\d{2}$/.test(val), time: (val) => /^(2[0-3]|[01]?[0-9]):([0-5]?[0-9])$/.test(val), uuid: (val) => /^[0-9a-f]{8}-[0-9a-f]{4}-[1-5][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/i.test( val ), htmlTag: (val) => /^<\/?[a-z][\s\S]*>$/i.test(val) }; var validators_default = validators; // src/index.ts function validate(type2, value2) { return validators_default[type2](value2); } // bin/cli.ts var [, , type, value] = process.argv; if (!type || !value) { console.error("\u274C Usage: regex-tester <type> <value>"); process.exit(1); } if (!validate(type, value)) { console.log(`\u274C Invalid ${type}`); } else { console.log(`\u2705 Valid ${type}`); }