mirror of
https://github.com/swc-project/swc.git
synced 2024-12-20 20:22:26 +03:00
bbaf619f63
swc_bundler: - [x] Fix wrapped esms. (denoland/deno#9307) - [x] Make test secure.
50 lines
1.0 KiB
TypeScript
50 lines
1.0 KiB
TypeScript
// Loaded from https://deno.land/x/segno@v1.1.0/lib/validations/isMACAddress.ts
|
|
|
|
|
|
// @ts-ignore allowing typedoc to build
|
|
import { assertString } from '../helpers/assertString.ts';
|
|
|
|
/**
|
|
* @ignore
|
|
*/
|
|
const macAddress = /^([0-9a-fA-F][0-9a-fA-F]:){5}([0-9a-fA-F][0-9a-fA-F])$/;
|
|
|
|
/**
|
|
* @ignore
|
|
*/
|
|
const macAddressNoColons = /^([0-9a-fA-F]){12}$/;
|
|
|
|
/**
|
|
* @ignore
|
|
*/
|
|
const macAddressWithHyphen = /^([0-9a-fA-F][0-9a-fA-F]-){5}([0-9a-fA-F][0-9a-fA-F])$/;
|
|
|
|
/**
|
|
* @ignore
|
|
*/
|
|
const macAddressWithSpaces = /^([0-9a-fA-F][0-9a-fA-F]\s){5}([0-9a-fA-F][0-9a-fA-F])$/;
|
|
|
|
/**
|
|
* @ignore
|
|
*/
|
|
const macAddressWithDots = /^([0-9a-fA-F]{4}).([0-9a-fA-F]{4}).([0-9a-fA-F]{4})$/;
|
|
|
|
type MACAddressOptions = {
|
|
noColons?: boolean;
|
|
};
|
|
|
|
export const isMACAddress = (str: string, options?: MACAddressOptions) => {
|
|
assertString(str);
|
|
|
|
if (options && options.noColons) {
|
|
return macAddressNoColons.test(str);
|
|
}
|
|
|
|
return (
|
|
macAddress.test(str) ||
|
|
macAddressWithHyphen.test(str) ||
|
|
macAddressWithSpaces.test(str) ||
|
|
macAddressWithDots.test(str)
|
|
);
|
|
};
|