|
| 1 | +# pob-parser |
| 2 | + |
| 3 | +A high-performance, robust, and zero-dependency library for parsing, encoding, decoding, and fetching Path of Building (PoB) import codes and pobb.in links. Available in both TypeScript/JavaScript (npm) and Rust (crates.io). |
| 4 | + |
| 5 | +## Features |
| 6 | + |
| 7 | +- Zero external dependencies (JS/TS version) using modern Web Streams. |
| 8 | +- High performance and safe encoding/decoding using base64 and zlib. |
| 9 | +- Link parsing and retrieval: Resolves standard and user-profile URLs for pobb.in to fetch the raw import codes. |
| 10 | +- Idiomatic Rust version with conditional async/blocking fetching using features. |
| 11 | +- Local playground demo: A minimal, terminal-inspired web application included in the repository to test, edit, and re-encode builds. |
| 12 | + |
| 13 | +## Installation |
| 14 | + |
| 15 | +### TypeScript / JavaScript (npm) |
| 16 | + |
| 17 | +```bash |
| 18 | +npm install pob-parser |
| 19 | +``` |
| 20 | + |
| 21 | +### Rust (crates.io) |
| 22 | + |
| 23 | +Add to your Cargo.toml: |
| 24 | +```toml |
| 25 | +[dependencies] |
| 26 | +pob-parser = "1.0.0" |
| 27 | +``` |
| 28 | + |
| 29 | +To enable HTTP fetching (async/blocking): |
| 30 | +```toml |
| 31 | +pob-parser = { version = "1.0.0", features = ["fetch", "blocking"] } |
| 32 | +``` |
| 33 | + |
| 34 | +## Quick Start Examples |
| 35 | + |
| 36 | +### TypeScript / JavaScript |
| 37 | + |
| 38 | +```typescript |
| 39 | +import { encode, decode, parseUrl, fetchRawCode, fetchAndDecode } from 'pob-parser'; |
| 40 | + |
| 41 | +// 1. Decode a PoB code to XML |
| 42 | +const pobCode = "eJzLSM3JyVcozy/KSQEAGgsEXQ=="; // "hello world" compressed |
| 43 | +const xml = await decode(pobCode); |
| 44 | +console.log(xml); // "hello world" |
| 45 | + |
| 46 | +// 2. Encode XML to PoB Code |
| 47 | +const newPobCode = await encode(xml); |
| 48 | +console.log(newPobCode); // "eJzLSM3JyVcozy_KSQEAGgsEXQ" (URL-safe, no padding) |
| 49 | + |
| 50 | +// 3. Parse a pobb.in URL |
| 51 | +const parsed = parseUrl("https://pobb.in/eQVFNoqVZrza"); |
| 52 | +console.log(parsed); |
| 53 | +// { id: 'eQVFNoqVZrza', rawUrl: 'https://pobb.in/eQVFNoqVZrza/raw' } |
| 54 | + |
| 55 | +// 4. Fetch and decode from pobb.in |
| 56 | +const fetchedXml = await fetchAndDecode("https://pobb.in/eQVFNoqVZrza"); |
| 57 | +console.log(fetchedXml); |
| 58 | +``` |
| 59 | + |
| 60 | +### Rust |
| 61 | + |
| 62 | +```rust |
| 63 | +use pob_parser::{decode, encode, parse_url}; |
| 64 | + |
| 65 | +fn main() -> Result<(), pob_parser::Error> { |
| 66 | + // 1. Decode PoB code |
| 67 | + let xml = decode("eJzLSM3JyVcozy/KSQEAGgsEXQ==")?; |
| 68 | + println!("{}", xml); // "hello world" |
| 69 | + |
| 70 | + // 2. Encode XML |
| 71 | + let encoded = encode(&xml)?; |
| 72 | + println!("{}", encoded); // "eJzLSM3JyVcozy_KSQEAGgsEXQ" |
| 73 | + |
| 74 | + // 3. Parse pobb.in link |
| 75 | + let parsed = parse_url("https://pobb.in/eQVFNoqVZrza").unwrap(); |
| 76 | + println!("Raw URL: {}", parsed.raw_url); |
| 77 | + |
| 78 | + Ok(()) |
| 79 | +} |
| 80 | + |
| 81 | +// 4. Fetch and decode (requires the "fetch" feature) |
| 82 | +#[cfg(feature = "fetch")] |
| 83 | +async fn fetch_example() -> Result<(), pob_parser::Error> { |
| 84 | + let xml = pob_parser::fetch_and_decode("https://pobb.in/eQVFNoqVZrza", None).await?; |
| 85 | + println!("{}", xml); |
| 86 | + Ok(()) |
| 87 | +} |
| 88 | +``` |
| 89 | + |
| 90 | +## Local Playground |
| 91 | + |
| 92 | +### Run Locally with CORS Proxy |
| 93 | + |
| 94 | +Since browsers block cross-origin requests (CORS) when executing client-side fetches directly to pobb.in, a local dev server with a built-in proxy is provided for testing: |
| 95 | + |
| 96 | +1. Build the library bundles: |
| 97 | + ```bash |
| 98 | + cd js |
| 99 | + npm run build |
| 100 | + ``` |
| 101 | +2. Start the dev server: |
| 102 | + ```bash |
| 103 | + npm start |
| 104 | + ``` |
| 105 | +3. Open http://localhost:3000 in your browser to access the playground. |
| 106 | + |
| 107 | +## Credits |
| 108 | + |
| 109 | +- [PathOfBuildingAPI](https://github.com/ppoelzl/PathOfBuildingAPI) by ppoelzl |
| 110 | +- [pasteofexile](https://github.com/Dav1dde/pasteofexile) by Dav1dde |
0 commit comments