Skip to content

Commit 0159ae8

Browse files
committed
Update README and CHANGELOG
Closes nfarina#78
1 parent bf93b18 commit 0159ae8

File tree

2 files changed

+70
-33
lines changed

2 files changed

+70
-33
lines changed

CHANGELOG.md

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,36 @@
11
# Change Log
22

3+
## [v2.0.0](https://github.com/nfarina/xmldoc/tree/v2.0.0) (2024)
4+
5+
**Major Changes:**
6+
7+
- Complete TypeScript rewrite with full type definitions
8+
- Dual package support for both CommonJS and ESM environments
9+
- Maintained backwards compatibility with existing code
10+
- Updated `sax` dependency to 1.2.4
11+
- Added support for modern module resolution via package.json exports field
12+
- Improved HTML compatibility with self-closing tags
13+
- Enhanced documentation and examples
14+
- Added proper TypeScript declaration files
15+
316
## [v1.0.0](https://github.com/nfarina/xmldoc/tree/v1.0.0) (2016-12-26)
17+
418
[Full Changelog](https://github.com/nfarina/xmldoc/compare/v0.5.1...v1.0.0)
519

620
**Closed issues:**
721

822
- Excellent library with a beautiful, clean API [\#42](https://github.com/nfarina/xmldoc/issues/42)
923
- Order of elements changed [\#41](https://github.com/nfarina/xmldoc/issues/41)
1024
- While writing back xml document to a file it removes all comments [\#39](https://github.com/nfarina/xmldoc/issues/39)
11-
- react native using xmldoc to parser xml [\#38](https://github.com/nfarina/xmldoc/issues/38)
25+
- react native using xmldoc to parser xml [\#38](https://github.com/nfarina/xmldoc/issues/38)
1226
- Order of val in relation to children? [\#37](https://github.com/nfarina/xmldoc/issues/37)
1327

1428
**Merged pull requests:**
1529

1630
- Fix CData overwriting bug [\#43](https://github.com/nfarina/xmldoc/pull/43) ([calebmer](https://github.com/calebmer))
1731

1832
## [v0.5.1](https://github.com/nfarina/xmldoc/tree/v0.5.1) (2016-05-12)
33+
1934
[Full Changelog](https://github.com/nfarina/xmldoc/compare/v0.5.0...v0.5.1)
2035

2136
**Closed issues:**
@@ -27,6 +42,7 @@
2742
- GLOBAL is producing deprecation warnings in node V6 [\#36](https://github.com/nfarina/xmldoc/pull/36) ([jmalins](https://github.com/jmalins))
2843

2944
## [v0.5.0](https://github.com/nfarina/xmldoc/tree/v0.5.0) (2016-04-27)
45+
3046
[Full Changelog](https://github.com/nfarina/xmldoc/compare/v0.4.0...v0.5.0)
3147

3248
**Closed issues:**
@@ -46,6 +62,7 @@
4662
- Fixing \#29 - Incorrect escaping of < > [\#30](https://github.com/nfarina/xmldoc/pull/30) ([buholzer](https://github.com/buholzer))
4763

4864
## [v0.4.0](https://github.com/nfarina/xmldoc/tree/v0.4.0) (2015-11-16)
65+
4966
[Full Changelog](https://github.com/nfarina/xmldoc/compare/v0.3.1...v0.4.0)
5067

5168
**Closed issues:**
@@ -59,6 +76,7 @@
5976
- encode attribute values to keep xml valid [\#21](https://github.com/nfarina/xmldoc/pull/21) ([dmvjs](https://github.com/dmvjs))
6077

6178
## [v0.3.1](https://github.com/nfarina/xmldoc/tree/v0.3.1) (2015-05-22)
79+
6280
**Closed issues:**
6381

6482
- xmldoc error [\#19](https://github.com/nfarina/xmldoc/issues/19)
@@ -82,6 +100,4 @@
82100
- Add escaping '\<' and '\>' in toString\(\) [\#11](https://github.com/nfarina/xmldoc/pull/11) ([martnst](https://github.com/martnst))
83101
- add whole document serialization via toString\(whole=true, compressed=true\) [\#4](https://github.com/nfarina/xmldoc/pull/4) ([jankuca](https://github.com/jankuca))
84102

85-
86-
87-
\* *This Change Log was automatically generated by [github_changelog_generator](https://github.com/skywinder/Github-Changelog-Generator)*
103+
\* _This Change Log was automatically generated by [github_changelog_generator](https://github.com/skywinder/Github-Changelog-Generator)_

README.md

Lines changed: 50 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,43 +1,61 @@
1-
21
[![Build Status](https://travis-ci.org/nfarina/xmldoc.svg)](https://travis-ci.org/nfarina/xmldoc)
32
[![Coverage Status](https://coveralls.io/repos/github/nfarina/xmldoc/badge.svg?branch=master)](https://coveralls.io/github/nfarina/xmldoc?branch=master)
43

54
## Introduction
65

7-
`xmldoc` lets you parse XML documents with ease. It's a pure-JavaScript, one-file XML document class with a single dependency on the excellent [`sax`][sax] parser.
6+
`xmldoc` lets you parse XML documents with ease. It's a lightweight XML document class with a single dependency on the excellent [`sax`][sax] parser.
87

98
For more on why I wrote this class, see the [blog post][blog].
109

11-
[blog]: http://nfarina.com/post/34302964969/a-lightweight-xml-document-class-for-nodejs-javascript
10+
As of version 2.0, `xmldoc` fully supports TypeScript and can be imported in both CommonJS and ESM environments.
11+
12+
[blog]: http://nfarina.com/post/34302964969/a-lightweight-xml-document-class-for-nodejs-javascript
1213

1314
## Release Notes
1415

15-
See [CHANGELOG.md](./CHANGELOG.md) for details (built with [GitHub Changelog Generator](https://skywinder.github.io/github-changelog-generator/)).
16+
See [CHANGELOG.md](./CHANGELOG.md) for details.
1617

1718
## Installation
1819

19-
npm install xmldoc
20+
```bash
21+
npm install xmldoc
22+
# or
23+
yarn add xmldoc
24+
```
2025

2126
Or just download the repository and include it in your `node_modules` directly. Or just download the [single JS file][blob]!
2227

23-
[blob]: https://github.com/nfarina/xmldoc/blob/master/lib/xmldoc.js
24-
25-
## Installation - React Native
26-
27-
I haven't tested this myself but [installing `buffer` and `stream` separately](https://github.com/nfarina/xmldoc/issues/38) may be necessary for `xmldoc` to work on React Native:
28-
29-
npm install buffer stream xmldoc
28+
[blob]: https://github.com/nfarina/xmldoc/blob/master/lib/xmldoc.js
3029

3130
## Usage
3231

32+
### CommonJS (Node.js)
33+
3334
```js
34-
var xmldoc = require('xmldoc');
35+
const { XmlDocument } = require("xmldoc");
3536

36-
var document = new xmldoc.XmlDocument("<some>xml</some>");
37+
const document = new XmlDocument("<some>xml</some>");
3738

3839
// do things
3940
```
4041

42+
### ESM / TypeScript
43+
44+
```ts
45+
// ESM environments
46+
import { XmlDocument } from "xmldoc";
47+
48+
const document = new XmlDocument("<some>xml</some>");
49+
```
50+
51+
### React Native
52+
53+
If you're using React Native, you may need to install `buffer` and `stream` separately:
54+
55+
```bash
56+
npm install buffer stream xmldoc
57+
```
58+
4159
## Classes
4260

4361
The primary exported class is `XmlDocument`, which you'll use to consume your XML text. `XmlDocument` contains a hierarchy of `XmlElement` instances representing the XML structure.
@@ -46,12 +64,12 @@ Both `XmlElement` and `XmlDocument` contain the same members and methods you can
4664

4765
## Members
4866

49-
* `name` - the node name, like "tat" for `<tat>`. XML "namespaces" are ignored by the underlying [sax-js](https://github.com/isaacs/sax-js) parser, so you'll simply get "office:body" for `<office:body>`.
50-
* `attr` - an object dict containing attribute properties, like `bookNode.attr.title` for `<book title="...">`.
51-
* `val` - the string "value" of the node, if any, like "world" for `<hello>world</hello>`.
52-
* `children` - an array of `XmlElement` children of the node.
53-
* `firstChild`, `lastChild` - pretty much what it sounds like; null if no children
54-
* `line`, `column`, `position`, `startTagPosition` - information about the element's original position in the XML string.
67+
- `name` - the node name, like "tat" for `<tat>`. XML "namespaces" are ignored by the underlying [sax-js](https://github.com/isaacs/sax-js) parser, so you'll simply get "office:body" for `<office:body>`.
68+
- `attr` - an object dict containing attribute properties, like `bookNode.attr.title` for `<book title="...">`.
69+
- `val` - the string "value" of the node, if any, like "world" for `<hello>world</hello>`.
70+
- `children` - an array of `XmlElement` children of the node.
71+
- `firstChild`, `lastChild` - pretty much what it sounds like; null if no children
72+
- `line`, `column`, `position`, `startTagPosition` - information about the element's original position in the XML string.
5573

5674
Each member defaults to a sensible "empty" value like `{}` for `attr`, `[]` for `children`, and `""` for `val`.
5775

@@ -122,16 +140,19 @@ This is just an override of the standard JavaScript method, it will give you a s
122140
The default implementation of `toString()`, that is, the one you get when you just `console.log("Doc: " + myDoc)` will pretty-print the XML with linebreaks and indents. You can pass a couple options to control the output:
123141

124142
```js
125-
xml.toString({compressed:true}) // strips indents and linebreaks
126-
xml.toString({trimmed:true}) // trims long strings for easier debugging
127-
xml.toString({preserveWhitespace:true}) // prevents whitespace being removed from around element values
143+
xml.toString({ compressed: true }); // strips indents and linebreaks
144+
xml.toString({ trimmed: true }); // trims long strings for easier debugging
145+
xml.toString({ preserveWhitespace: true }); // prevents whitespace from being removed from around element values
146+
xml.toString({ html: true }); // uses HTML self-closing tag rules for elements without children
128147
```
129148

130149
Putting it all together:
131150

132151
```js
133152
var xml = "<author><name>looooooong value</name></author>";
134-
console.log("My document: \n" + new XmlDocument(xml).toString({trimmed:true}))
153+
console.log(
154+
"My document: \n" + new XmlDocument(xml).toString({ trimmed: true }),
155+
);
135156
```
136157

137158
Prints:
@@ -143,9 +164,9 @@ Prints:
143164

144165
## Feedback
145166

146-
Feel free to file issues or hit me up on [Twitter][twitter].
167+
Feel free to file issues or hit me up on [X][x].
147168

148-
[underscore]: http://underscorejs.org
149-
[XPath]: http://en.wikipedia.org/wiki/XPath
150-
[twitter]: http://twitter.com/nfarina
151-
[sax]: https://github.com/isaacs/sax-js
169+
[underscore]: http://underscorejs.org
170+
[XPath]: http://en.wikipedia.org/wiki/XPath
171+
[x]: http://twitter.com/nfarina
172+
[sax]: https://github.com/isaacs/sax-js

0 commit comments

Comments
 (0)