parent
1be17216b3
commit
ecaa088e43
|
@ -1,6 +1,6 @@
|
||||||
{
|
{
|
||||||
"name": "converter",
|
"name": "converter",
|
||||||
"version": "1.5.0",
|
"version": "1.5.1",
|
||||||
"description": "Convert numbers to and from various bases.",
|
"description": "Convert numbers to and from various bases.",
|
||||||
"author": "Florine W. Dekker",
|
"author": "Florine W. Dekker",
|
||||||
"browser": "dist/bundle.js",
|
"browser": "dist/bundle.js",
|
||||||
|
|
|
@ -2,9 +2,17 @@
|
||||||
const {$, doAfterLoad, stringToHtml} = window.fwdekker;
|
const {$, doAfterLoad, stringToHtml} = window.fwdekker;
|
||||||
// noinspection JSUnresolvedVariable
|
// noinspection JSUnresolvedVariable
|
||||||
const {clearInputValidity, showInputInvalid} = window.fwdekker.validation;
|
const {clearInputValidity, showInputInvalid} = window.fwdekker.validation;
|
||||||
|
// noinspection JSUnresolvedVariable
|
||||||
|
const {LocalStorage} = window.fwdekker.storage;
|
||||||
import bigInt from "big-integer";
|
import bigInt from "big-integer";
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Interfaces with local storage.
|
||||||
|
*/
|
||||||
|
const storage = new LocalStorage("/tools/converter//config");
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Replaces the character at the given index with the given replacement.
|
* Replaces the character at the given index with the given replacement.
|
||||||
*
|
*
|
||||||
|
@ -370,6 +378,11 @@ class NumeralSystemInputWithToggleableSeparator extends NumeralSystemInput {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @type {NumeralSystem} the decimal number system
|
||||||
|
*/
|
||||||
|
const decimalSystem = new NumeralSystem(10, "0123456789");
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* All the inputs to display.
|
* All the inputs to display.
|
||||||
*
|
*
|
||||||
|
@ -378,7 +391,7 @@ class NumeralSystemInputWithToggleableSeparator extends NumeralSystemInput {
|
||||||
const inputs = [
|
const inputs = [
|
||||||
new NumeralSystemInput("Binary", new NumeralSystem(2, "01")),
|
new NumeralSystemInput("Binary", new NumeralSystem(2, "01")),
|
||||||
new NumeralSystemInput("Octal", new NumeralSystem(8, "01234567")),
|
new NumeralSystemInput("Octal", new NumeralSystem(8, "01234567")),
|
||||||
new NumeralSystemInput("Decimal", new NumeralSystem(10, "0123456789")),
|
new NumeralSystemInput("Decimal", decimalSystem),
|
||||||
new NumeralSystemInput("Duodecimal", new NumeralSystem(12, "0123456789ab")),
|
new NumeralSystemInput("Duodecimal", new NumeralSystem(12, "0123456789ab")),
|
||||||
new NumeralSystemInput("Hexadecimal", new NumeralSystem(16, "0123456789abcdef")),
|
new NumeralSystemInput("Hexadecimal", new NumeralSystem(16, "0123456789abcdef")),
|
||||||
new Base64NumeralSystemInput("Base64"),
|
new Base64NumeralSystemInput("Base64"),
|
||||||
|
@ -399,6 +412,8 @@ const inputs = [
|
||||||
* @param newDecimalValues {bigInt[]} the decimal representation of the new value
|
* @param newDecimalValues {bigInt[]} the decimal representation of the new value
|
||||||
*/
|
*/
|
||||||
function updateAllInputs(source, newDecimalValues) {
|
function updateAllInputs(source, newDecimalValues) {
|
||||||
|
storage.setArray("last-value", decimalSystem.decimalsToBases(newDecimalValues));
|
||||||
|
|
||||||
for (const input of inputs)
|
for (const input of inputs)
|
||||||
if (input !== source)
|
if (input !== source)
|
||||||
input.setValues(newDecimalValues);
|
input.setValues(newDecimalValues);
|
||||||
|
@ -410,6 +425,6 @@ doAfterLoad(() => {
|
||||||
for (const input of inputs)
|
for (const input of inputs)
|
||||||
input.addToParent(form);
|
input.addToParent(form);
|
||||||
|
|
||||||
updateAllInputs(undefined, [bigInt(42), bigInt(17)]);
|
updateAllInputs(undefined, decimalSystem.basesToDecimals(storage.getArray("last-value", [42, 17])));
|
||||||
inputs[0].textarea.focus();
|
inputs[0].textarea.focus();
|
||||||
});
|
});
|
||||||
|
|
Loading…
Reference in New Issue