Getting started

JavaScript / TypeScript

npm install, init loads the WebAssembly core, then synchronous calls — for browsers and Node.js alike.

For: developers

Installation

npm install x-iztro@0.10

The package is the same Rust core compiled to WebAssembly plus a TypeScript layer: ESM, with zero runtime dependencies. It is written in TypeScript and ships complete .d.ts declarations, so TypeScript projects need no separate @types/ package; TypeScript 5.0 or later with ES2022 in lib is required. Requires Node.js 22 or later, or a modern browser with WebAssembly. Vite, webpack and Next.js Turbopack emit the .wasm as a static asset on their own; see Using it with bundlers and frameworks.

Building from source

Only needed when changing the Rust side:

cd js && npm ci && npm run build

Charting

import { init, astro } from 'x-iztro';

await init(); // load the core, once; every call after this is synchronous

const chart = astro.bySolar('2000-8-16', 2, 'female');

console.log(chart.solarDate);           // solar date
console.log(chart.lunarDate);           // lunar date
console.log(chart.chineseDate);         // four pillars
console.log(chart.time, chart.timeRange);
console.log(chart.sign, chart.zodiac);  // sign, zodiac
console.log(chart.soul, chart.body);    // Soul star, Body star
console.log(chart.fiveElementsClass);   // Five Elements class
2000-8-16
二〇〇〇年七月十七
庚辰 甲申 丙午 庚寅
寅时 03:00~05:00
狮子座 龙
破军 文昌
木三局

Lunar charts use astro.byLunar. The optional arguments after gender go in an object (fixLeap, language, config, plus isLeapMonth for lunar dates):

const lunar = astro.byLunar('2000-7-17', 2, 'female', { isLeapMonth: false });

Every field of the returned Astrolabe is typed, display fields are already translated into the chart language, and JSON.stringify(chart) gives the same JSON shape as iztro.

Next

The full API is in the JavaScript API reference.

On this page