ember-math-helpers
Handlebars template helpers for basic arithmetic and the full JavaScript Math API in Ember.js.
Repository Health
Technical Analysis
ember-math-helpers is an Ember.js v2 addon that brings JavaScript’s Math object and basic arithmetic operators into Handlebars templates as first-class helpers. Instead of computing values in a component class and passing them down, templates can call {{add a b}}, {{div total count}}, or {{round value}} directly, covering everything from addition, subtraction, and modulo to trigonometric functions, logarithms, and greatest-common-divisor calculations.
The addon ships as a modern v2-format Ember addon built with rollup and @embroider/addon-dev, with per-helper entry points for tree-shaking and full TypeScript signatures plus a Glint template registry for type-checked template arguments. Each of the 41 helpers has a dedicated QUnit test in the companion test-app, and the project has shipped steadily since 2016 across Ember editions up through Octane.
What You Get
- 41 individually importable template helpers covering basic arithmetic (add, sub, mult, div, mod, sum), rounding (round, ceil, floor, trunc, sign), and the full JavaScript Math API (pow, sqrt, cbrt, log variants, trig/inverse-trig functions, gcd, lcm, hypot, random)
- TypeScript helper signatures for every helper plus a generated Glint template-registry.ts, so helper arguments and return types are checked in .hbs/.gjs templates
- A v2-format addon build (via @embroider/addon-shim, @embroider/addon-dev, and rollup) with per-helper dist/ entry points, letting consumers tree-shake unused helpers out of their build
- A live documentation site (robbiethewagner.github.io/ember-math-helpers) generated from the addon’s own test-app, demonstrating each helper
Common Use Cases
- Formatting a running total or price calculation directly in a template, e.g.
{{mult price quantity}}, without adding a computed property to the component - Rounding or truncating numeric values for display, such as
{{round rating}}or{{floor percentage}} - Performing geometry or unit-conversion math (hypot, pow, sqrt) inline in a template for dashboards or data-visualization UIs
- Using the gcd/lcm helpers for ratio simplification or interval calculations in admin and reporting templates
Under The Hood
Architecture
The addon is a pnpm monorepo split into a publishable ember-math-helpers/ v2 addon package and a test-app/ consumer used purely for testing and docs. Each of the 41 helpers lives in its own file under ember-math-helpers/src/helpers/*.ts, exporting a named pure function (e.g. add, gcd) alongside a default export wrapped in Ember’s helper() factory and a *Signature TypeScript interface describing positional args and return type. src/index.ts re-exports every helper for direct import, and src/template-registry.ts aggregates all signatures into one Registry interface consumed by Glint. There is no shared runtime state or class hierarchy — each helper is independent, so adding or removing one is a fully isolated change with no risk to the others.
Tech Stack
Built as a v2-format Ember addon using @embroider/addon-dev’s rollup plugin (rollup.config.mjs) to compile src/ into dist/ with per-module entry points, plus @embroider/addon-shim for v1 compatibility via addon-main.cjs. TypeScript (~5.9) compiles the helpers, with @glint/core and @glint/environment-ember-template-imports providing template type-checking. The workspace is managed with pnpm workspaces and release-plan for changelog/versioning, targeting ember-source >= 4.12 as a peer dependency. The test-app/ consumer uses ember-cli with QUnit for testing and ember deploy for publishing the docs site.
Code Quality
Every one of the 41 helpers has a matching QUnit unit test under test-app/tests/unit/helpers/*-test.js, giving close to 1:1 test-to-helper coverage, and the addon package’s own test script explicitly defers to the test-app since v2 addons ship no runtime tests. ESLint (with eslint-plugin-ember, typescript-eslint, and eslint-plugin-n) and ember-template-lint run via pnpm lint, and Prettier with prettier-plugin-ember-template-tag enforces formatting. GitHub Actions CI runs on push and pull request. Naming is consistent and minimal (helper files match their Handlebars keyword), and each export carries a documentation comment showing template usage.
What Makes It Unique
The project’s niche is comprehensive coverage: rather than exposing a handful of common operators, it wraps nearly the entire JavaScript Math object as individually tree-shakeable template helpers, including less-common functions like gcd, lcm, hypot, clz32, and fround that most competing helper addons omit. Combined with full TypeScript signatures and a Glint registry, it gives template-level type safety for arithmetic that is otherwise easy to get wrong when values pass through Handlebars as unchecked arguments.