Numi is a handy calculator app for macOS. It allows to describe tasks the natural way and instantly get an accurate answer. For example, 20ドル in euro - 5% discount or today + 2 weeks.
You can use JavaScript extensions to add global variables, custom units or functions. Right now only limited set of API is available via JavaScript, but the plan is to open as mach API as possible.
Numi supports JavaScript extensions since
3.16. To start using this app version, you'll need to switch to test update stream first. Execute this in terminal and then check for app updates:
defaults write com.dmitrynikolaev.numi SUUpdaterIsInTestMode 'YES'
Use log function to send output from your extension to log window.
log("Function called!");
Each value in Numi might be represented in JavaScript as an object with a set of properties, describing decimal value, unit type etc. Here is the usual way of creating new values for Numi:
var value = { "double": 5, "unitId" : "USD" }
Use numi.setVariable function to declare global variables.
numi.setVariable("xxx", { "double": 5, "unitId" : "USD" });
You can also use plain JavaScript numbers for cases when you'll need to return value for Numi. This will be treated as a value with decimal number.
numi.setVariable("yyy", 122);
Use numi.addUnit to add new unit. id field required for internal use, and might be any unique literal. phrases contains string with comma-separated phrases that might be used for the unit, format field used for results formatting.
Unit conversion limited to ratio-based conversion ATM. For each unit you can specify base unit identifier baseUnitId and ratio to that unit. Conversion from one unit to another in this case happening through base unit. On first step value will be converted to the base unit. On second step base value will be converted to result unit. baseUnitId might be picked up from list of base units.
numi.addUnit({
"id": "horse",
"phrases": "horse, horses, hrs",
"baseUnitId": "m",
"format" : "hrs",
"ratio" : 2.4,
});
Use numi.addFunction to add new function. Values passed into evaluated function in form of array. To use function with multiple arguments you can use ; in Numi, like myFunction(1;5;4).
numi.addFunction({ "id": "zum", "phrases": "zum" }, function(values) {
return { "double": values[0].double + values[1].double };
});
| Unit name | Unit ID |
|---|---|
| Meter | m |
| Second | second |
| Percentage | percent |
| Square meter | m2 |
| Cubic meter | m3 |
| Bit | bit |
| Byte | byte |
| Radian | radian |
| Gram | gram |