Moved validator to shared code directory.
This commit is contained in:
parent
dda66c67bd
commit
ac0642d8eb
9 changed files with 13 additions and 17 deletions
server/utils
|
@ -3,7 +3,7 @@ import _ from "lodash";
|
|||
import CONSTRAINTS from "../shared/validation/constraints";
|
||||
import ErrorTypes from "../utils/errorTypes";
|
||||
import Logger from "../logger";
|
||||
import {Constraints, forConstraints, isConstraints} from "../validation/validator";
|
||||
import {Constraints, forConstraints, isConstraints} from "../shared/validation/validator";
|
||||
import {Request, Response} from "express";
|
||||
import {
|
||||
EnumTypeGuard,
|
||||
|
|
|
@ -1,28 +0,0 @@
|
|||
import _ from "lodash"
|
||||
import {isString, MAC} from "../types";
|
||||
|
||||
export function normalizeString(str: string): string {
|
||||
return isString(str) ? str.trim().replace(/\s+/g, ' ') : str;
|
||||
}
|
||||
|
||||
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 macParts = [];
|
||||
|
||||
for (let i = 1; i < parts.length; i += 2) {
|
||||
macParts.push(parts[i]);
|
||||
}
|
||||
|
||||
return macParts.join(':') as MAC;
|
||||
}
|
||||
|
||||
export function parseInteger(str: string): number {
|
||||
const parsed = _.parseInt(str, 10);
|
||||
if (parsed.toString() === str) {
|
||||
return parsed;
|
||||
} else {
|
||||
throw new SyntaxError(`String does not represent a valid integer: "${str}"`);
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue