32 lines
1.0 KiB
JavaScript
32 lines
1.0 KiB
JavaScript
"use strict";
|
|
(function () {
|
|
"use strict";
|
|
angular.module('myitsmApp')
|
|
.constant('queryStringParser', {
|
|
parse: function (qs) {
|
|
if (typeof qs === 'string' || typeof qs === 'undefined') {
|
|
var parser = /([^=?&]+)=([^&]*)/g;
|
|
var result = {};
|
|
var part;
|
|
while ((part = parser.exec(qs)) !== null) {
|
|
result[decodeURIComponent(part[1])] = decodeURIComponent(part[2]);
|
|
}
|
|
return result;
|
|
}
|
|
else {
|
|
throw new Error('Not a string');
|
|
}
|
|
},
|
|
build: function (data) {
|
|
if (data !== null && typeof data === 'object') {
|
|
return Object.keys(data).reduce(function (a, b, idx) {
|
|
return a + (idx ? '&' : '') + b + '=' + data[b].toString();
|
|
}, '');
|
|
}
|
|
else {
|
|
throw new Error('Not object value');
|
|
}
|
|
}
|
|
});
|
|
})();
|