@fusionstrings/swisseph-wasm

中文文档
0.1.5发布于 2026/01/13MITTypeScriptESM + CJS零依赖近 30 天下载 6716

High-precision Swiss Ephemeris bindings for WebAssembly (Rust based)

原始使用文档
文档目录16 节
  1. Features
  2. ⚡ Benchmarks
  3. 1. Complex Calculations (e.g. Moon Position)
  4. 2. Simple Calculations (e.g. Sun Position)
  5. Installation
  6. Deno / JSR
  7. Rust (Cargo)
  8. NPM / Node.js
  9. Browser (Zero-Config)
  10. Quick Start
  11. Building from Source
  12. Prerequisites
  13. Build Command
  14. Maintenance
  15. Version Management
  16. License

swisseph-wasm 🌌

High-precision, WebAssembly bindings for the Swiss Ephemeris.

  • 🚀 Best-in-Class: Faster, smaller, and more accurate than pure JS implementations.
  • 🛡️ Safe: Rust-based memory safety for FFI interactions.
  • 📦 Universal: Works in Node.js, Deno, Bun, and Browsers.

JSR npm Crates.io CI

Features

  • Full Swiss Ephemeris: Wraps the complete C library (v2.10.03).
  • Zero Dependencies: Generated WASM has no external runtime deps.
  • Type-Safe: Complete TypeScript definitions.
  • Isomorphic: Runs everywhere WebAssembly runs.

⚡ Benchmarks

1. Complex Calculations (e.g. Moon Position)

When precision matters, swisseph-wasm is both faster and more accurate.

Environmentswisseph-wasmastronomy-engineComparison
Deno (Bench)~182,000 iter/s~126,000 iter/s1.44x Faster 🚀

2. Simple Calculations (e.g. Sun Position)

For simple calculations, the overhead of calling WebAssembly dominates. Pure JS is faster here.

Environmentswisseph-wasmastronomy-engineNote
Browser (Chrome)~319,000 ops/sec~577,000 ops/secInlined WASM vs Pure JS
Deno (Native)~178,000 ops/sec~434,000 ops/secDefault Loader

Summary: Use swisseph-wasm for professional-grade astrology (precision + complex speed). Use astronomy-engine for UI/visualizations (low precision + simple speed).

Run them yourself:

deno task bench
deno run -A benches/deno_throughput.ts
# For browser: Serve root and open benches/browser_bench.html

Installation

Deno / JSR

deno add jsr:@fusionstrings/swisseph-wasm

Rust (Cargo)

Use as a native Rust crate:

cargo add swisseph-wasm

Advanced: Import raw WASM (Deno):

import wasmBytes from "@fusionstrings/swisseph-wasm/wasm";
const module = new WebAssembly.Module(wasmBytes);

NPM / Node.js

npm install @fusionstrings/swisseph-wasm

Browser (Zero-Config)

Use the bundled browser version (inlined WASM) directly:

import { swe_julday } from "@fusionstrings/swisseph-wasm/browser";
// WASM initializes automatically

Quick Start

import {
  SE_GREG_CAL,
  SE_MOON,
  SE_SUN,
  swe_calc_ut,
  swe_julday,
} from "@fusionstrings/swisseph-wasm";

// 1. Calculate Julian Day for Jan 1, 2000, 12:00 UTC
const jd = swe_julday(2000, 1, 1, 12.0, SE_GREG_CAL);
console.log(`Julian Day: ${jd}`); // 2451545.0

// 2. Calculate Sun Position
const sun = swe_calc_ut(jd, SE_SUN, 0);
console.log("Sun Longitude:", sun.longitude);

// 3. Calculate Moon Position
const moon = swe_calc_ut(jd, SE_MOON, 0);
console.log("Moon Longitude:", moon.longitude);

Building from Source

Prerequisites

  • Rust: rustup target add wasm32-unknown-unknown
  • Deno: For task management.
  • LLVM: Required for compiling the C library to WASM.

macOS Users:

brew install llvm

Build Command

The build script automatically detects Homebrew LLVM.

deno task build

Maintenance

Version Management

To update the version across Deno, Cargo, and NPM configs:

deno task bump-version <new-version>
# Example: deno task bump-version 1.2.3

This command validates the version format, updates all config files, and syncs Cargo.lock.

License

MIT License. Based on the Swiss Ephemeris (GPL/Commercial dual license). Note: Using this library implies compliance with the Swiss Ephemeris license terms.

版本与发布记录

@fusionstrings/swisseph-wasm 共发布 5 个版本,首次发布于 2026/01/07;过去 12 个月发布了 5 个版本。

版本发布日期距今
0.1.5latest2026/01/1310 个月前
0.1.42026/01/0710 个月前
0.1.4-pre.32026/01/0710 个月前
0.1.32026/01/0710 个月前
0.1.22026/01/0710 个月前

关于 @fusionstrings/swisseph-wasm 的常见问题

@fusionstrings/swisseph-wasm 是什么?

High-precision Swiss Ephemeris bindings for WebAssembly (Rust based)

如何安装 @fusionstrings/swisseph-wasm?

在项目目录运行 npm install @fusionstrings/swisseph-wasm,或使用 pnpm add / yarn add / bun add。

@fusionstrings/swisseph-wasm 支持 TypeScript 吗?

支持。包内自带 TypeScript 类型声明(package.json 声明了 types 入口),安装后即可获得类型提示,无需再安装 @types 包。

@fusionstrings/swisseph-wasm 支持 ESM 还是 CommonJS?

同时提供 ES Module 与 CommonJS 入口,import 和 require() 都可以使用,打包工具会自动选择合适的版本。

@fusionstrings/swisseph-wasm 可以商用吗?

@fusionstrings/swisseph-wasm 使用 MIT 许可。宽松许可:允许商业使用、修改和再分发,通常只需在分发时保留原版权与许可声明。以上为概括,不构成法律意见,请以许可原文为准。

@fusionstrings/swisseph-wasm 的下载量有多少?

根据 npm 官方下载统计,@fusionstrings/swisseph-wasm 在 2026/10/16 – 2026/11/14 这 30 天内被下载 6,716 次,日均约 224 次。下载量会把 CI 构建、镜像同步和作为其他包依赖的安装一并计入,适合横向比较热度,不能直接等同于使用人数。

@fusionstrings/swisseph-wasm 还在维护吗?

最新版本 0.1.5 发布于 2026/01/13(10 个月前);至今共发布 5 个版本,其中过去 12 个月发布了 5 个;首次发布于 2026/01/07。发布频率只是参考信号:功能稳定的工具可能很少需要更新,建议结合源码仓库的 issue 和提交记录判断。