raccourci

French for “shortcut”.

Fractions, percentages, words, and arithmetic.
A small TypeScript library with no runtime dependencies.

Try it

Result 133.33333333333331 Full numeric precision. Clear the reference amount for arithmetic.

Install

Install from npm. TypeScript declarations and ESM, CommonJS, and browser builds are included.

npm install raccourci

Use the same function in vanilla TypeScript, React, or Node.js:

import { resolveAmount } from 'raccourci';

resolveAmount('half + 10', 200); // 110
resolveAmount('100 - (5*3)');    // 85

Download 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

Example results with a reference amount of 200
InputWith 200
all, full, max200
half, 1/2, 50%100
quarter, ¼50
max - 10190
2.5k2500

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.