Skip to content
endographPublic

About

No description, website, or topics provided.

Resources

Stars

2 stars

Watchers

0 watching

Forks

Repository files navigation

quanto

Website · Playground · Design · Usage · Writing a codec · Codecs · Dates

quanto

A flexible input parser and formatter.

People type 5'11", 180cm and 1,8 m and mean the same height. quanto turns that into a typed value you can store, compare and format back.

import { length } from '@quantojs/common';

length().parse(`5'11"`);  // { ok: true, value: { value: 71, unit: 'in' } }
length().parse('1,8 m');  // { ok: true, value: { value: 1.8, unit: 'm' } }
length().parse('70 kg');  // { ok: false, issues: [{ code: 'unknown_unit', … }] }
  • Forgiving. Locale-aware numbers, compound input like 2h30m, smart quotes, $1.2k, next fri.
  • Plain data. Values are JSON. Validate them on the server with any Standard Schema library, no re-parsing.
  • Round-trips. Whatever format prints, parse reads back.
  • Yours to extend. quanto is the protocol; the codecs are a bootstrap. Yours use the same API as the first-party ones, and a fixtures file is the spec.

@quantojs/common has length, mass, duration, temperature, volume, area, speed, data size and rate, compute (FLOPs and FLOPS), energy, power, pressure, angle, frequency, fuel economy, pace, torque, force, acceleration, flow rate, density, electrical (voltage, current, resistance, capacitance, charge), light (lumens, lux, nits, color temperature), radiation dose, sound level, plain numbers, percent, proportions (‰, basis points, ppm) and ratios, with money in @quantojs/common/money, betting odds in @quantojs/common/odds and CSS colors (hex, names, rgb(), oklch(), color()…) in @quantojs/common/css-color. @quantojs/datetime adds dates, times, ranges like Oct 3-5 and offsets like 2 weeks before, and separate packages add phone numbers, coordinates (plus codes and geohashes too), ring and shoe sizes, music and addresses. Not sure which one you'll get? merge them and take the first that parses, or take @quantojs/anything, which reads all of it.

Pre-release, not on npm yet.

Development

bun install
bun run typecheck
bun run build
bun run test
bun run site        # the website and playground, on localhost:4173

It's a bun workspace: the core (the protocol) lives in packages/quanto, the common codecs in packages/common, dates in packages/datetime, and the website in apps/site. Tests and the site resolve the packages to source, so nothing needs building first.

About

No description, website, or topics provided.

Resources

Stars

2 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages