Typescript migration
* utils/strings.js * utils/urlBuilder.js
This commit is contained in:
parent
2c2c6336db
commit
7325cd4db6
5 changed files with 67 additions and 68 deletions
server/utils
23
server/utils/strings.ts
Normal file
23
server/utils/strings.ts
Normal file
|
@ -0,0 +1,23 @@
|
|||
import _ from "lodash"
|
||||
|
||||
export function normalizeString (str: string): string {
|
||||
return _.isString(str) ? str.trim().replace(/\s+/g, ' ') : str;
|
||||
}
|
||||
|
||||
export function normalizeMac (mac: string): string {
|
||||
// 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(':');
|
||||
}
|
||||
|
||||
export function parseInt (str: string): number | undefined {
|
||||
const parsed = _.parseInt(str, 10);
|
||||
return parsed.toString() === str ? parsed : undefined;
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue