Allow dash as delimiter in MACs.
This commit is contained in:
parent
533710a2d4
commit
ffc0f13eb8
4 changed files with 9 additions and 8 deletions
server/utils
|
@ -1,12 +1,13 @@
|
|||
import _ from "lodash"
|
||||
import {MAC} from "../types";
|
||||
|
||||
export function normalizeString (str: string): string {
|
||||
export function normalizeString(str: string): string {
|
||||
return _.isString(str) ? str.trim().replace(/\s+/g, ' ') : str;
|
||||
}
|
||||
|
||||
export function normalizeMac (mac: string): string {
|
||||
export function normalizeMac(mac: MAC): MAC {
|
||||
// parts only contains values at odd indexes
|
||||
const parts = mac.toUpperCase().replace(/:/g, '').split(/([A-F0-9]{2})/);
|
||||
const parts = mac.toUpperCase().replace(/[-:]/g, '').split(/([A-F0-9]{2})/);
|
||||
|
||||
const macParts = [];
|
||||
|
||||
|
@ -14,10 +15,10 @@ export function normalizeMac (mac: string): string {
|
|||
macParts.push(parts[i]);
|
||||
}
|
||||
|
||||
return macParts.join(':');
|
||||
return macParts.join(':') as MAC;
|
||||
}
|
||||
|
||||
export function parseInteger (str: string): number {
|
||||
export function parseInteger(str: string): number {
|
||||
const parsed = _.parseInt(str, 10);
|
||||
if (parsed.toString() === str) {
|
||||
return parsed;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue