Skip to content

Commit

Permalink
patch esm to support node, bun, web
Browse files Browse the repository at this point in the history
  • Loading branch information
ciscorn committed Jan 20, 2024
1 parent 382ee6e commit f767792
Show file tree
Hide file tree
Showing 4 changed files with 53 additions and 9 deletions.
4 changes: 3 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,15 @@ resolver = "2"
members = ["./japan-geoid-*"]

[workspace.package]
version = "0.3.0"
version = "0.3.1"
edition = "2021"
authors = [
"Taku Fukada <[email protected]>",
"MIERUNE Inc. <[email protected]>",
]
description = "Calculates geoid heights for Japan using GSI's geoid model."
license-file = "LICENSE.txt"
license = "MIT"
repository = "https://github.com/MIERUNE/japan-geoid"
categories = ["science", "science::geo"]

Expand All @@ -23,6 +24,7 @@ edition.workspace = true
categories.workspace = true
authors.workspace = true
description.workspace = true
license = "MIT"
license-file.workspace = true
repository.workspace = true

Expand Down
19 changes: 12 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

A Rust, Python and JavaScript (WASM) library for calculating geoid heights for Japan using [GSI's geoid model](https://fgd.gsi.go.jp/download/geoid.php). This library contains geoid data based on `gsigeo2011_ver2_2.asc`, created with permission: 「測量法に基づく国土地理院長承認(使用)R 5JHs 560」.

Rust および Python で日本のジオイド高を計算するためライブラリです。国土地理院のジオイドモデル「[日本のジオイド2011](https://fgd.gsi.go.jp/download/geoid.php)」を用いて、国土地理院による C++ のサンプルコードに準拠した補間計算を行います。本ライブラリは、日本のジオイド2011 v.2.2 (`gsigeo2011_ver2_2.asc`) を元にしたジオイドデータを含んでいます(測量法に基づく国土地理院長承認(使用)R 5JHs 560)。
Rust, Python, JavaScript で日本のジオイド高を計算するためライブラリです。国土地理院のジオイドモデル「[日本のジオイド2011](https://fgd.gsi.go.jp/download/geoid.php)」を用いて、国土地理院による C++ のサンプルコードに準拠した補間計算を行います。本ライブラリは、日本のジオイド2011 v.2.2 (`gsigeo2011_ver2_2.asc`) を元にしたジオイドデータを含んでいます(測量法に基づく国土地理院長承認(使用)R 5JHs 560)。

License: MIT

Expand Down Expand Up @@ -77,19 +77,24 @@ npm add japan-geoid
### Usage

```javascript
import { load_embedded_gsigeo2011 } from 'japan-geoid';
import init, { load_embedded_gsigeo2011 } from "japan-geoid";

await init(); // load WASM

const geoid = load_embedded_gsigeo2011();

geoid.get_height(138.2839817085188, 37.12378643088312); // => 39.47387115961899
console.log(
geoid.get_height(138.2839817085188, 37.12378643088312)
); // => 39.47387115961899

geoid.get_heights(
[138.2839817085188, 141.36199967724426],
[37.12378643088312, 43.06539278249951]
console.log(
geoid.get_heights(
[138.2839817085188, 141.36199967724426],
[37.12378643088312, 43.06539278249951]
)
); // => Float64Array(2) [ 39.47387115961899, 31.90071200378531 ]
```


## License

MIT License
Expand Down
2 changes: 1 addition & 1 deletion japan-geoid-py/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ authors = [
{ name = "Taku Fukada", email = "[email protected]" },
{ name = "MIERUNE Inc.", email = "[email protected]" },
]
license = { file = "LICENSE.txt" }
license = "MIT"
requires-python = ">=3.8"
classifiers = [
"License :: OSI Approved :: MIT License",
Expand Down
37 changes: 37 additions & 0 deletions patch_esm.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
import json
from pathlib import Path

pkg = Path("./pkg")

with open(pkg / "package.json", encoding="utf-8") as f:
package = json.load(f)

package["type"] = "module"
package["main"] = "japan_geoid.js"

with open(pkg / "package.json", "w", encoding="utf-8") as f:
json.dump(package, f, indent=2)


with open(pkg / "japan_geoid.js", encoding="utf-8") as f:
lines = f.readlines()

patched = False
with open(pkg / "japan_geoid.js", "w", encoding="utf-8") as f:
for line in lines:
if line.strip() == "input = fetch(input);":
f.write(
"""try {
input = await fetch(input);
} catch (e) {
if (!(e instanceof TypeError)) {
throw e;
}
input = await (await import("node:fs/promises")).readFile(input);
}"""
)
patched = True
else:
f.write(line)

assert patched

0 comments on commit f767792

Please sign in to comment.