mirror of
https://github.com/BorysLevytskyi/BitwiseCmd.git
synced 2026-01-04 11:02:36 +01:00
Improve hash functionality
This commit is contained in:
19
src/core/hash.test.ts
Normal file
19
src/core/hash.test.ts
Normal file
@@ -0,0 +1,19 @@
|
||||
import hash from './hash';
|
||||
|
||||
describe('hash tests', () => {
|
||||
|
||||
it('can decode URL', () => {
|
||||
const actual = hash.decodeHash('#4.3.2.1%2F8');
|
||||
expect(actual).toBe('4.3.2.1/8');
|
||||
});
|
||||
|
||||
it('can get hash from encoded url', () => {
|
||||
const actual = hash.getArgs('#-notrack%7C%7C17%2015%7C%7C16&15');
|
||||
expect(actual).toMatchObject(["-notrack", "17 15", "16&15"]);
|
||||
});
|
||||
|
||||
it('can get hash from unencoded url', () => {
|
||||
const actual = hash.getArgs('#1 2|127.0.0.|1&2|192.168.1.1');
|
||||
expect(actual).toMatchObject(["1 2|127.0.0.|1&2|192.168.1.1"]);
|
||||
});
|
||||
});
|
||||
@@ -1,9 +1,9 @@
|
||||
export default {
|
||||
encodeHash: function(input:string):string {
|
||||
return encodeURI(input.trim().replace(/\s/g,','));
|
||||
return encodeURIComponent(input.trim().replace(/\s/g,','));
|
||||
},
|
||||
decodeHash: function(hashValue:string):string {
|
||||
return decodeURI(hashValue).replace(/^\#/, '').replace(/,/g,' ');
|
||||
return decodeURIComponent(hashValue.replace(/^\#/, '')).replace(/,/g,' ');
|
||||
},
|
||||
getArgs: function (hashValue:string) : string[] {
|
||||
|
||||
@@ -19,17 +19,6 @@ export default {
|
||||
};
|
||||
|
||||
function splitHashList(str: string) : string[] {
|
||||
var values = [];
|
||||
|
||||
if(str.indexOf('||')) {
|
||||
str.split('||').forEach(function (v) {
|
||||
if (v.length > 0) {
|
||||
values.push(v);
|
||||
}
|
||||
});
|
||||
} else {
|
||||
values.push(str);
|
||||
}
|
||||
|
||||
return values;
|
||||
return str.split('||').filter(s => s.length > 0);
|
||||
}
|
||||
@@ -53,6 +53,8 @@ function executeStartupCommands() {
|
||||
startupCommands = hashArgs;
|
||||
}
|
||||
|
||||
log.debug('Executing startup commands', startupCommands);
|
||||
|
||||
startupCommands.forEach(cmd.execute.bind(cmd));
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user