mirror of
https://github.com/BorysLevytskyi/BitwiseCmd.git
synced 2025-12-10 06:52:05 +01:00
got rid of mode in config
This commit is contained in:
@@ -7,8 +7,7 @@
|
||||
|
||||
app.set('cmdConfig', core.ObservableObject.create({
|
||||
emphasizeBytes: true,
|
||||
theme: 'dark',
|
||||
mode: 'dec'
|
||||
theme: 'dark'
|
||||
}));
|
||||
|
||||
app.debugMode = false;
|
||||
|
||||
@@ -5,23 +5,21 @@ app.set('expression', function() {
|
||||
var listRegex = /^((\d+|0x[\d,a-f]+)\s?)+$/
|
||||
|
||||
return {
|
||||
canParse: function(string, mode) {
|
||||
canParse: function(string) {
|
||||
return exprRegex.test(string) || listRegex.test(string);
|
||||
},
|
||||
parse: function(string, mode) {
|
||||
mode = (mode || 'dec');
|
||||
|
||||
parse: function(string) {
|
||||
var trimmed = string.replace(/^\s+|\s+$/, '');
|
||||
var base = getBase(mode);
|
||||
|
||||
var matches = exprRegex.exec(trimmed);
|
||||
|
||||
if(matches != null) {
|
||||
return createCalculableExpression(matches, base);
|
||||
return createCalculableExpression(matches);
|
||||
}
|
||||
|
||||
matches = listRegex.exec(string);
|
||||
if(matches != null) {
|
||||
return createListOfNumbersExpression(string, base)
|
||||
return createListOfNumbersExpression(string)
|
||||
}
|
||||
},
|
||||
parseOperand: function(input) {
|
||||
@@ -38,7 +36,7 @@ app.set('expression', function() {
|
||||
|
||||
};
|
||||
|
||||
function createCalculableExpression(matches, base) {
|
||||
function createCalculableExpression(matches) {
|
||||
|
||||
var m = new app.models.BitwiseOperation();
|
||||
m.operand1 = new Operand(matches[1]);
|
||||
@@ -50,7 +48,7 @@ app.set('expression', function() {
|
||||
return m;
|
||||
}
|
||||
|
||||
function createListOfNumbersExpression(input, base) {
|
||||
function createListOfNumbersExpression(input) {
|
||||
var operands = [];
|
||||
input.split(' ').forEach(function(n){
|
||||
if(n.trim().length > 0) {
|
||||
@@ -62,8 +60,8 @@ app.set('expression', function() {
|
||||
return new app.models.BitwiseNumbers(operands);
|
||||
}
|
||||
|
||||
function getBase(mode) {
|
||||
switch (mode){
|
||||
function getBase(kind) {
|
||||
switch (kind){
|
||||
case 'bin': return 2;
|
||||
case 'hex': return 16;
|
||||
case 'dec': return 10;
|
||||
|
||||
@@ -5,10 +5,10 @@ app.set("formatter", function() {
|
||||
var is = app.get('is');
|
||||
|
||||
return {
|
||||
formatString: function(num, mode) {
|
||||
mode = mode || "bin";
|
||||
formatString: function(num, kind) {
|
||||
kind = kind || "bin";
|
||||
|
||||
var convertedString = num.toString(getBase(mode));
|
||||
var convertedString = num.toString(getBase(kind));
|
||||
return convertedString;
|
||||
|
||||
},
|
||||
@@ -27,8 +27,8 @@ app.set("formatter", function() {
|
||||
}
|
||||
};
|
||||
|
||||
function getBase(mode) {
|
||||
switch (mode){
|
||||
function getBase(kind) {
|
||||
switch (kind){
|
||||
case 'bin': return 2;
|
||||
case 'hex': return 16;
|
||||
case 'dec': return 10;
|
||||
|
||||
@@ -26,12 +26,6 @@ app.run(function() {
|
||||
light: function () {
|
||||
cmdConfig.theme = 'light';
|
||||
},
|
||||
dec: function () {
|
||||
cmdConfig.mode = 'dec';
|
||||
},
|
||||
hex: function() {
|
||||
cmdConfig.mode = 'hex';
|
||||
},
|
||||
about: function() {
|
||||
var aboutResult = document.querySelector('.result .aboutTpl');
|
||||
if(aboutResult != null) {
|
||||
@@ -47,9 +41,9 @@ app.run(function() {
|
||||
|
||||
// TODO: Make as function
|
||||
cmd.command({
|
||||
canHandle: function(input) { return app.get('expression').canParse(input, cmdConfig.mode); },
|
||||
canHandle: function(input) { return app.get('expression').canParse(input); },
|
||||
handle: function(input) {
|
||||
return app.get('expression').parse(input, cmdConfig.mode);
|
||||
return app.get('expression').parse(input);
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
@@ -31,8 +31,7 @@ app.compose(function () {
|
||||
app.modelView(app.models.BitwiseNumbers, {
|
||||
renderView: function(model) {
|
||||
var maxLen = getBinaryLength(model.numbers);
|
||||
var table = html.element('<table class="expression {mode}"></table>');
|
||||
var otherMode = cmdConfig.mode == 'dec' ? 'hex' : 'dec';
|
||||
var table = html.element('<table class="expression"></table>');
|
||||
|
||||
model.operands.forEach(function(n){
|
||||
|
||||
@@ -40,7 +39,6 @@ app.compose(function () {
|
||||
var decCell = row.insertCell();
|
||||
|
||||
decCell.classList.add('label');
|
||||
decCell.classList.add(cmdConfig.mode);
|
||||
|
||||
var binCell = row.insertCell();
|
||||
binCell.className = 'bin';
|
||||
|
||||
@@ -75,12 +75,12 @@ describe('operands', function() {
|
||||
expect(hexOperand.kind).toBe('hex');
|
||||
expect(hexOperand.dec).toBe('16');
|
||||
expect(hexOperand.bin).toBe('10000');
|
||||
expect(hexOperand.hex).toBe('10');
|
||||
expect(hexOperand.hex).toBe('0x10');
|
||||
|
||||
expect(decOperand.kind).toBe('dec');
|
||||
expect(decOperand.dec).toBe('10');
|
||||
expect(decOperand.bin).toBe('1010');
|
||||
expect(decOperand.hex).toBe('a');
|
||||
expect(decOperand.hex).toBe('0xa');
|
||||
});
|
||||
|
||||
});
|
||||
Reference in New Issue
Block a user