Procházet zdrojové kódy

'From Base' operation now supports numbers with fractional parts.

n1474335 před 8 roky
rodič
revize
706423462d
2 změnil soubory, kde provedl 20 přidání a 2 odebrání
  1. 13 1
      src/core/operations/Base.js
  2. 7 1
      src/node/index.js

+ 13 - 1
src/core/operations/Base.js

@@ -46,7 +46,19 @@ const Base = {
         if (radix < 2 || radix > 36) {
             throw "Error: Radix argument must be between 2 and 36";
         }
-        return parseInt(input.replace(/\s/g, ""), radix);
+
+        var number = input.replace(/\s/g, "").split("."),
+            result = parseInt(number[0], radix) || 0;
+
+        if (number.length === 1) return result;
+
+        // Fractional part
+        for (var i = 0; i < number[1].length; i++) {
+            var digit = parseInt(number[1][i], radix);
+            result += digit / Math.pow(radix, i+1);
+        }
+
+        return result;
     },
 
 };

+ 7 - 1
src/node/index.js

@@ -13,7 +13,13 @@ const CyberChef = module.exports = {
 
     bake: function(input, recipeConfig) {
         this.chef = new Chef();
-        return this.chef.bake(input, recipeConfig, {}, 0, false);
+        return this.chef.bake(
+		input,
+		recipeConfig,
+		{},
+		0,
+		false
+	);
     }
 
 };