raccourci
French for “shortcut”.
Fractions, percentages, words, and arithmetic.
A small TypeScript library with no runtime dependencies.
Try it
Install
Install from npm. TypeScript declarations and ESM, CommonJS, and browser builds are included.
npm install raccourciUse the same function in vanilla TypeScript, React, or Node.js:
import { resolveAmount } from 'raccourci';
resolveAmount('half + 10', 200); // 110
resolveAmount('100 - (5*3)'); // 85Download the package archive ↓
For offline installation: npm install ./raccourci-0.1.0.tgz
Use a CDN
Load raccourci directly from unpkg or jsDelivr. Both examples are pinned to version 0.1.0.
Automatic inputs
No build step. Mark a text input to convert its value on blur or Enter.
<script src="https://unpkg.com/raccourci@0.1.0/dist/umd/index.cjs"></script>
<input type="text" data-resolve-amount="200">Typing 2/3 becomes 133.3333. Optional attributes: data-resolve-locale, data-resolve-precision, and data-resolve-rounding.
ES modules
Import the parser for vanilla modules, React, or other framework-controlled inputs.
<script type="module">
import { resolveAmount } from 'https://unpkg.com/raccourci@0.1.0/dist/esm/index.js';
console.log(resolveAmount('half + 10', 200)); // 110
</script>You can also download the browser build to host it yourself.
A few shortcuts
| Input | With 200 |
|---|---|
all, full, max | 200 |
half, 1/2, 50% | 100 |
quarter, ¼ | 50 |
max - 10 | 190 |
2.5k | 2500 |
Invalid expressions return null. A standalone fraction is a share of the reference; division inside a larger expression follows normal arithmetic. Results use JavaScript numbers and are not clamped.