Socket
Socket
Sign inDemoInstall

mac-regex

Package Overview
Dependencies
0
Maintainers
1
Versions
2
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 0.0.1 to 1.0.0

8

index.js
'use strict';
module.exports = function() {
return new RegExp('^([0-9A-Fa-f]{2}[:-]){5}([0-9A-Fa-f]{2})$');
module.exports = function(options) {
options = options || {};
var regexBase = '([0-9A-Fa-f]{2}[:-]){5}([0-9A-Fa-f]{2})';
return options.exact ? new RegExp('^' + regexBase + '$') :
new RegExp(regexBase, 'g');
}
{
"name": "mac-regex",
"version": "0.0.1",
"version": "1.0.0",
"description": "A regular expression for MAC addresses.",

@@ -5,0 +5,0 @@ "main": "index.js",

@@ -7,4 +7,2 @@ # MAC Regex

In the near future this will be likely moved to <https://github.com/regexps>.
## Installation

@@ -21,5 +19,14 @@

mac().test('aa-bb-cc-dd-ee-ff') // => true
mac().test('aa:bb:cc:dd:ee:ff') // => true
mac().test('kljhsdf') // => false
// Exact string option
mac({ exact: true }).test('aa-bb-cc-dd-ee-ff') // => true
mac({ exact: true }).test('aa:bb:cc:dd:ee:ff') // => true
mac({ exact: true }).test('aa:bb:cc:dd:ee:ff ') // => false
mac({ exact: true }).test('kljhsdf') // => false
// Global option (default)
mac().test('aa:bb:cc:dd:ee:ff ') // => true
mac().test('kljhsdf') // => false
'11:22:aa:44:55:33 11:22:aa:44:55:33'.match(mac())
// => ['11:22:aa:44:55:33', '11:22:aa:44:55:33']
```

@@ -43,2 +50,2 @@

Crafted with <3 by [John Otander](http://johnotander.com).
Crafted with <3 by [John Otander](http://johnotander.com).

@@ -6,17 +6,65 @@ var assert = require('assert');

it('should find a XX-XX-XX-XX-XX-XX mac when it exists', function() {
assert.equal(mac().test('aa-bb-cc-dd-ee-ff'), true);
});
describe('exact: true', function() {
it('should find a XX-XX-XX-XX-XX-XX mac when it exists', function() {
assert.equal(mac({ exact: true }).test('aa-bb-cc-dd-ee-ff'), true);
});
it('should find a XX:XX:XX:XX:XX:XX mac when it exists', function() {
assert.equal(mac().test('aa:bb:cc:dd:ee:ff'), true);
});
it('should find a XX:XX:XX:XX:XX:XX mac when it exists', function() {
assert.equal(mac({ exact: true }).test('aa:bb:cc:dd:ee:ff'), true);
});
it('should find a XX:XX:XX:XX:XX:XX mac when it exists regardless of case', function() {
assert.equal(mac().test('aa:bB:cc:dd:ee:ff'), true);
it('should find a XX:XX:XX:XX:XX:XX mac when it exists regardless of case', function() {
assert.equal(mac({ exact: true }).test('aa:bB:cc:dd:ee:ff'), true);
});
it('should find a XX:XX:XX:XX:XX:XX mac when it exists with all digits', function() {
assert.equal(mac({ exact: true }).test('11-22-33-44-55-66'), true);
});
it('should handle a wide array of macs', function() {
var validMacs = ['11:22:aa:44:55:33', '11-aa-bb-33-55-11'];
validMacs.forEach(function(validMac) {
assert.equal(mac({ exact: true }).test(validMac), true);
});
});
it('should not find a mac when it does not exist', function() {
var invalidMacs = ['', 'aa', 'aabbccddeeff', '1234', '*&^(&^'];
invalidMacs.forEach(function(invalidMac) {
assert.equal(mac({ exact: true }).test(invalidMac), false);
});
});
});
it('should find a XX:XX:XX:XX:XX:XX mac when it exists with all digits', function() {
assert.equal(mac().test('11-22-33-44-55-66'), true);
describe('exact: false', function() {
it('should find a XX-XX-XX-XX-XX-XX mac when it exists', function() {
assert.equal(mac().exec(' aa-bb-cc-dd-ee-ff (*&&')[0], 'aa-bb-cc-dd-ee-ff');
});
it('should find a XX:XX:XX:XX:XX:XX mac when it exists', function() {
assert.equal(mac().exec('other stuff aa:bb:cc:dd:ee:ff ')[0], 'aa:bb:cc:dd:ee:ff');
});
it('should find a XX:XX:XX:XX:XX:XX mac when it exists regardless of case', function() {
assert.equal(mac().exec('aa:bB:cc:dd:ee:ff filler')[0], 'aa:bB:cc:dd:ee:ff');
});
it('should find a XX:XX:XX:XX:XX:XX mac when it exists with all digits', function() {
assert.equal(mac().exec('11-22-33-44-55-66 more filler')[0], '11-22-33-44-55-66');
});
it('should handle multiple macs', function() {
var validMacs = ['11:22:aa:44:55:33 11:22:aa:44:55:33', '11-aa-bb-33-55-11 11-aa-bb-33-55-11'];
validMacs.forEach(function(validMacStr) {
assert.equal(validMacStr.match(mac()).length, 2);
});
});
it('should not find a mac when it does not exist', function() {
var invalidMacs = ['', 'aa', 'aabbccddeeff', '1234', '*&^(&^'];
invalidMacs.forEach(function(invalidMacStr) {
assert.equal(invalidMacStr.match(mac()), null);
});
});
});
});
});
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc