@sie-js/wbxml 1.0.0 → 1.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -1,32 +1,117 @@
1
+ # @sie-js/wbxml
2
+
1
3
  [![NPM Version](https://img.shields.io/npm/v/%40sie-js%2Fwbxml)](https://www.npmjs.com/package/@sie-js/wbxml)
2
4
 
3
- # USAGE
5
+ Converts between WBXML and XML. It is [libwbxml](https://github.com/libwbxml/libwbxml) built for WebAssembly, so it needs Node.js 20 or newer and nothing else.
6
+
7
+ ## Command line
8
+
9
+ ```bash
10
+ npm install -g @sie-js/wbxml
11
+ ```
12
+
13
+ This installs `wbxml2xml` and `xml2wbxml`. They accept the same options as the libwbxml tools of the same name. There is also `wbxml`, which runs both as subcommands (`wbxml decode`, `wbxml encode`) and works with `npx @sie-js/wbxml` without installing.
14
+
15
+ ```bash
16
+ xml2wbxml -o settings.wbxml settings.xml
17
+ wbxml2xml -l OTA -i 4 settings.wbxml
18
+ wbxml2xml -m compact < si.wbxml > si.xml
19
+ ```
20
+
21
+ Without an input file, or with `-`, the input is read from stdin. Without `-o`, the result goes to stdout. `xml2wbxml` will not write binary data to a terminal unless you pass `-o -`.
22
+
23
+ ### wbxml2xml
24
+
25
+ | Option | Meaning |
26
+ |---------------------------|---------------------------------------------------------------------------|
27
+ | `-o, --output <file>` | Output file |
28
+ | `-m, --mode <mode>` | `0` or `compact`, `1` or `indent` (default), `2` or `canonical` |
29
+ | `-i, --indent <n>` | Indent width for the `indent` mode, default 0 |
30
+ | `-k, --keep-whitespace` | Keep ignorable whitespace |
31
+ | `-l, --lang <lang>` | Document language, for documents without a known public ID |
32
+ | `-c, --charset <charset>` | Charset for documents that don't declare one |
33
+ | `--list-langs` | Print supported languages |
34
+ | `--list-charsets` | Print supported charsets |
35
+
36
+ Nokia/Ericsson OTA settings and some other formats have no public ID, so they can only be decoded with `-l`, e.g. `-l OTA`.
37
+
38
+ ### xml2wbxml
39
+
40
+ | Option | Meaning |
41
+ |-----------------------------|-----------------------------------------------|
42
+ | `-o, --output <file>` | Output file |
43
+ | `-v, --wbxml-version <ver>` | `1.0`, `1.1`, `1.2` or `1.3` (default) |
44
+ | `-k, --keep-whitespace` | Keep ignorable whitespace |
45
+ | `-n, --no-string-table` | Don't build a string table |
46
+ | `-a, --anonymous` | Don't write the public ID |
47
+
48
+ Building the string table gets very slow on documents with thousands of text nodes; use `-n` for those.
49
+
50
+ The tools exit with 1 if the conversion or file I/O fails and with 2 if the command line is wrong.
51
+
52
+ ## Library
53
+
4
54
  ```typescript
5
55
  import { xml2wbxml, wbxml2xml } from '@sie-js/wbxml';
6
56
 
7
57
  const xml = `<?xml version="1.0"?>
8
58
  <!DOCTYPE CHARACTERISTIC-LIST SYSTEM "characteristic-list.dtd">
9
59
  <CHARACTERISTIC-LIST>
10
- <CHARACTERISTIC TYPE="ADDRESS">
11
- <PARM NAME="BEARER" VALUE="GSM/CSD"/>
12
- <PARM NAME="PROXY" VALUE="123.34.6.7"/>
13
- <PARM NAME="CSD_DIALSTRING" VALUE="+45"/>
14
- <PARM NAME="PPP_AUTHTYPE" VALUE="PAP"/>
15
- </CHARACTERISTIC>
16
- <CHARACTERISTIC TYPE="URL" VALUE="http://wap.dk"/>
17
- <CHARACTERISTIC TYPE="NAME">
18
- <PARM NAME="NAME" VALUE="ABC"/>
19
- </CHARACTERISTIC>
20
- <CHARACTERISTIC TYPE="BOOKMARK">
21
- <PARM NAME="NAME" VALUE="Wap"/>
22
- <PARM NAME="URL" VALUE="http://wap.dk"/>
23
- </CHARACTERISTIC>
60
+ <CHARACTERISTIC TYPE="BOOKMARK">
61
+ <PARM NAME="NAME" VALUE="Wap"/>
62
+ <PARM NAME="URL" VALUE="http://wap.dk"/>
63
+ </CHARACTERISTIC>
24
64
  </CHARACTERISTIC-LIST>`;
25
65
 
26
- const wbxml = xml2wbxml(xml, { version: "1.3" });
27
- console.log(wbxml);
28
- console.log(wbxml2xml(out, { lang: "OTA" }));
66
+ const wbxml = xml2wbxml(xml);
67
+ console.log(wbxml2xml(wbxml, { lang: 'OTA', indent: 4 }));
29
68
  ```
30
69
 
31
- # CREDITS
32
- [libwbxml](https://github.com/libwbxml/libwbxml)
70
+ `xml2wbxml(xml, options)` takes a string or bytes and returns a `Buffer`. A string is encoded as UTF-8; pass bytes if the document uses the encoding from its XML declaration. Options: `version`, `preserveWhitespace`, `noStringTable`, `noPublicId`.
71
+
72
+ `wbxml2xml(wbxml, options)` returns a string. It decodes documents in any of the supported charsets; `charset` is used for documents that don't declare one. Options: `mode`, `indent`, `preserveWhitespace`, `lang`, `charset`.
73
+
74
+ Allowed option values are exported as `WBXML_VERSIONS`, `WBXML_GEN_MODES`, `WBXML_LANGS` and `WBXML_CHARSETS`. Any other value throws `WBXMLOptionError`.
75
+
76
+ ## Building
77
+
78
+ You need [Emscripten](https://emscripten.org/) and pnpm.
79
+
80
+ ```bash
81
+ pnpm install
82
+ pnpm run build:wasm
83
+ pnpm run build
84
+ pnpm test
85
+ ```
86
+
87
+ `build:wasm` downloads and builds libexpat and libwbxml into `build/`. libwbxml is patched first (see `patches/`): unpatched, it runs out of stack and becomes very slow on documents with many elements, and never uses iconv, so it can't decode documents in charsets other than UTF-8.
88
+
89
+ ## License
90
+
91
+ LGPL-2.1-or-later, same as libwbxml. Uses [libwbxml](https://github.com/libwbxml/libwbxml) and [libexpat](https://github.com/libexpat/libexpat).
92
+
93
+ ## AI-assisted contributions
94
+
95
+ We are not against AI. We are against vibe coding, AI slop, and attempts to offload engineering work to a model. This project prioritizes quality, not development speed or results at any cost.
96
+
97
+ 1. **Do not use AI-generated text in human-to-human communication.**
98
+
99
+ Write comments, discussions, PR descriptions, and responses to reviewers yourself.
100
+
101
+ 2. **Do not let AI submit PRs or commits.**
102
+
103
+ The author must always be a human who has personally reviewed the changes and takes responsibility for them.
104
+
105
+ 4. **Do not submit code primarily designed or written by AI.**
106
+
107
+ Architecture, algorithms, code organization, and the final implementation must be decided by a human. AI may only be used as an auxiliary tool.
108
+
109
+ 6. **You must understand all the code you submit.**
110
+
111
+ You must be able to explain every change, justify your decisions, and fix any problems yourself. If you do not understand the code, open a feature request instead of a PR.
112
+
113
+ 8. **Code must be simple, clear, and tested.**
114
+
115
+ Follow KISS, the project's coding style, and its existing architecture. Do not introduce unnecessary abstractions, dependencies, or untested changes.
116
+
117
+ AI slop PRs will be closed without review.