isAlphanumeric.js 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  1. "use strict";
  2. Object.defineProperty(exports, "__esModule", {
  3. value: true
  4. });
  5. exports.default = isAlphanumeric;
  6. exports.locales = void 0;
  7. var _assertString = _interopRequireDefault(require("./util/assertString"));
  8. var _alpha = require("./alpha");
  9. function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
  10. function isAlphanumeric(_str) {
  11. var locale = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 'en-US';
  12. var options = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
  13. (0, _assertString.default)(_str);
  14. var str = _str;
  15. var ignore = options.ignore;
  16. if (ignore) {
  17. if (ignore instanceof RegExp) {
  18. str = str.replace(ignore, '');
  19. } else if (typeof ignore === 'string') {
  20. str = str.replace(new RegExp("[".concat(ignore.replace(/[-[\]{}()*+?.,\\^$|#\\s]/g, '\\$&'), "]"), 'g'), ''); // escape regex for ignore
  21. } else {
  22. throw new Error('ignore should be instance of a String or RegExp');
  23. }
  24. }
  25. if (locale in _alpha.alphanumeric) {
  26. return _alpha.alphanumeric[locale].test(str);
  27. }
  28. throw new Error("Invalid locale '".concat(locale, "'"));
  29. }
  30. var locales = Object.keys(_alpha.alphanumeric);
  31. exports.locales = locales;