2014-05-12 20:08:19 +02:00
|
|
|
'use strict';
|
|
|
|
|
2018-12-17 22:49:54 +01:00
|
|
|
const _ = require('lodash')
|
2014-05-12 20:08:19 +02:00
|
|
|
|
2018-12-17 22:49:54 +01:00
|
|
|
module.exports = {
|
|
|
|
normalizeString (str) {
|
|
|
|
return _.isString(str) ? str.trim().replace(/\s+/g, ' ') : str;
|
|
|
|
},
|
2014-05-12 20:08:19 +02:00
|
|
|
|
2018-12-17 22:49:54 +01:00
|
|
|
normalizeMac (mac) {
|
|
|
|
// parts only contains values at odd indexes
|
|
|
|
const parts = mac.toUpperCase().replace(/:/g, '').split(/([A-F0-9]{2})/);
|
2014-05-12 20:08:19 +02:00
|
|
|
|
2018-12-17 22:49:54 +01:00
|
|
|
const macParts = [];
|
2014-05-12 20:08:19 +02:00
|
|
|
|
2018-12-17 22:49:54 +01:00
|
|
|
for (let i = 1; i < parts.length; i += 2) {
|
|
|
|
macParts.push(parts[i]);
|
2014-05-12 20:08:19 +02:00
|
|
|
}
|
2018-12-17 22:49:54 +01:00
|
|
|
|
|
|
|
return macParts.join(':');
|
|
|
|
},
|
|
|
|
|
|
|
|
parseInt (str) {
|
|
|
|
const parsed = _.parseInt(str, 10);
|
|
|
|
return parsed.toString() === str ? parsed : undefined;
|
|
|
|
}
|
|
|
|
}
|