add support of commads from location hash

This commit is contained in:
boryslevytskyi
2017-05-13 18:49:38 +03:00
parent 003d9e180a
commit d0e43cfb8f
8 changed files with 61 additions and 17 deletions

40
src/app/hash.js Normal file
View File

@@ -0,0 +1,40 @@
export default {
encodeHash: function(string) {
return encodeURI(string.trim().replace(/\s/g,','));
},
decodeHash: function(hashValue) {
return decodeURI(hashValue).replace(/^\#/, '').replace(/,/g,' ');
},
getArgs: function (hashValue) {
var decodedHash = this.decodeHash(hashValue),
args = [];
splitHashList(decodedHash).forEach(function(value) {
if(/^\-[a-zA-Z]+$/.test(value)) {
args[value.substr(1)] = true;
return;
}
args.push(value);
});
return Object.freeze(args);
}
};
function splitHashList(str) {
var values = [];
if(str.indexOf('||')) {
str.split('||').forEach(function (v) {
if (v.length > 0) {
values.push(v);
}
});
} else {
values.push(str);
}
return values;
}