xml-model 1.0.0-beta.0 → 1.0.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.
Files changed (2) hide show
  1. package/README.md +29 -1
  2. package/package.json +2 -2
package/README.md CHANGED
@@ -21,4 +21,32 @@ export default defineConfig({
21
21
 
22
22
  ## Documentation
23
23
 
24
- check source
24
+ ### Example
25
+
26
+ ```typescript
27
+ import "reflect-metadata";
28
+ import { Model, getModel, XML } from "xml-model";
29
+
30
+ @Model({
31
+ fromXML(ctx) {
32
+ const instance = new MyClass();
33
+ if (ctx.properties.foo) instance.foo = ctx.properties.foo;
34
+ return instance;
35
+ },
36
+ })
37
+ class MyClass {
38
+ foo = "bar";
39
+ }
40
+
41
+ const model = getModel(MyClass);
42
+
43
+ const a: MyClass = model.fromXML("<my-class><foo>test</foo></my-class>");
44
+ console.log(JSON.stringify(a)); // {"foo":"test"}
45
+
46
+ const b = new MyClass();
47
+ console.log(XML.stringify(model.toXML(b))); // <my-class><foo>bar</foo></my-class>
48
+ b.foo = "other";
49
+ console.log(XML.stringify(model.toXML(b))); // <my-class><foo>other</foo></my-class>
50
+ ```
51
+
52
+ See [source code](https://github.com/MathisTLD/xml-model) for more
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "xml-model",
3
- "version": "1.0.0-beta.0",
3
+ "version": "1.0.0",
4
4
  "description": "allows transparent XML <-> Object conversion in typescript",
5
5
  "license": "MIT",
6
6
  "author": "MathisTLD",
@@ -66,4 +66,4 @@
66
66
  "lint-staged": {
67
67
  "*": "oxfmt --no-error-on-unmatched-pattern"
68
68
  }
69
- }
69
+ }