2014-05-12 20:08:19 +02:00
|
|
|
'use strict';
|
|
|
|
|
|
|
|
angular.module('ffffng').factory('Strings', function (_) {
|
|
|
|
return {
|
|
|
|
normalizeString: function (str) {
|
|
|
|
return _.isString(str) ? str.trim().replace(/\s+/g, ' ') : str;
|
|
|
|
},
|
|
|
|
|
|
|
|
normalizeMac: function (mac) {
|
|
|
|
// parts only contains values at odd indexes
|
|
|
|
var parts = mac.toUpperCase().replace(/:/g, '').split(/([A-F0-9]{2})/);
|
|
|
|
|
|
|
|
var macParts = [];
|
|
|
|
|
|
|
|
for (var i = 1; i < parts.length; i += 2) {
|
|
|
|
macParts.push(parts[i]);
|
|
|
|
}
|
|
|
|
|
|
|
|
return macParts.join(':');
|
2016-06-07 10:50:15 +02:00
|
|
|
},
|
|
|
|
|
|
|
|
parseInt: function (str) {
|
|
|
|
var parsed = _.parseInt(str, 10);
|
|
|
|
return parsed.toString() === str ? parsed : undefined;
|
2014-05-12 20:08:19 +02:00
|
|
|
}
|
|
|
|
};
|
|
|
|
});
|