isMACAddress.js 898 B

123456789101112131415161718192021222324252627282930
  1. "use strict";
  2. Object.defineProperty(exports, "__esModule", {
  3. value: true
  4. });
  5. exports.default = isMACAddress;
  6. var _assertString = _interopRequireDefault(require("./util/assertString"));
  7. function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
  8. var macAddress = /^(?:[0-9a-fA-F]{2}([-:\s]))([0-9a-fA-F]{2}\1){4}([0-9a-fA-F]{2})$/;
  9. var macAddressNoSeparators = /^([0-9a-fA-F]){12}$/;
  10. var macAddressWithDots = /^([0-9a-fA-F]{4}\.){2}([0-9a-fA-F]{4})$/;
  11. function isMACAddress(str, options) {
  12. (0, _assertString.default)(str);
  13. /**
  14. * @deprecated `no_colons` TODO: remove it in the next major
  15. */
  16. if (options && (options.no_colons || options.no_separators)) {
  17. return macAddressNoSeparators.test(str);
  18. }
  19. return macAddress.test(str) || macAddressWithDots.test(str);
  20. }
  21. module.exports = exports.default;
  22. module.exports.default = exports.default;