tweak: output an object instead of an array
This commit is contained in:
parent
f412a7a183
commit
545d896f18
|
@ -2,5 +2,5 @@ import { transformer } from "./index.js";
|
|||
|
||||
let printer = (_) => null;
|
||||
let getSimpleSquiggleOutput = (string) => transformer(string, printer);
|
||||
let result = getSimpleSquiggleOutput("(1 to 10)/(1 to 20)");
|
||||
let result = getSimpleSquiggleOutput("(1 to 10)/(1 to 20)").squiggleString;
|
||||
console.log(result);
|
||||
|
|
43
src/index.js
43
src/index.js
|
@ -229,7 +229,7 @@ let preprocessor = (string, print = console.log) => {
|
|||
};
|
||||
// preprocessor("1.2 to 10.5 * 1.1 to 20 * 1 to 2.5 * 1 to 5");
|
||||
|
||||
let customToStringHandlerLognormals = (node, options) => {
|
||||
let customToStringHandlerToGuesstimateSyntax = (node, options) => {
|
||||
if (isArgLognormal(node)) {
|
||||
let factors = getFactors(node);
|
||||
// print(node);
|
||||
|
@ -239,6 +239,33 @@ let customToStringHandlerLognormals = (node, options) => {
|
|||
}
|
||||
};
|
||||
|
||||
let toPrecision2 = (f) => f.toPrecision(2);
|
||||
let toShortGuesstimateString = (node) => {
|
||||
if (isArgLognormal(node)) {
|
||||
let factors = getFactors(node);
|
||||
// print(node);
|
||||
// print(factors);
|
||||
let ninetyPercentCI = to90PercentCI(factors[0], factors[1]);
|
||||
return `${toPrecision2(ninetyPercentCI[0])} to ${toPrecision2(
|
||||
ninetyPercentCI[1]
|
||||
)}`;
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
};
|
||||
|
||||
let to90CIArray = (node) => {
|
||||
if (isArgLognormal(node)) {
|
||||
let factors = getFactors(node);
|
||||
// print(node);
|
||||
// print(factors);
|
||||
let ninetyPercentCI = to90PercentCI(factors[0], factors[1]);
|
||||
return [ninetyPercentCI[0], ninetyPercentCI[1]];
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
};
|
||||
|
||||
export function transformer(string, print = console.log) {
|
||||
string = preprocessor(string, print);
|
||||
let transformerOutput = transformerInner(string);
|
||||
|
@ -253,8 +280,14 @@ export function transformer(string, print = console.log) {
|
|||
transformerOutput = transformerInner(string);
|
||||
stringNew = transformerOutput.toString();
|
||||
}
|
||||
let stringNewAs90PercentCI = transformerOutput.toString({
|
||||
handler: customToStringHandlerLognormals,
|
||||
});
|
||||
return [stringNew, stringNewAs90PercentCI];
|
||||
let squiggleString = stringNew;
|
||||
let shortGuesstimateString = toShortGuesstimateString(transformerOutput);
|
||||
let array90CI = to90CIArray(transformerOutput);
|
||||
// console.log(transformerOutput);
|
||||
let result = {
|
||||
squiggleString: squiggleString,
|
||||
shortGuesstimateString: shortGuesstimateString,
|
||||
array90CI: array90CI,
|
||||
};
|
||||
return result;
|
||||
}
|
||||
|
|
|
@ -14,7 +14,9 @@ let testTransformer = (string) => {
|
|||
let result = transformer(string, print);
|
||||
print("");
|
||||
console.groupEnd();
|
||||
console.log(`=> ${result}`);
|
||||
console.log(`=> ${result.squiggleString}`);
|
||||
print("");
|
||||
print(result);
|
||||
print("-".repeat(52));
|
||||
console.log("");
|
||||
};
|
||||
|
|
Loading…
Reference in New Issue
Block a user