Skip to content

Commit fc61d3a

Browse files
Harrison IfeanyichukwuHarrison Ifeanyichukwu
authored andcommitted
feat: added installTo static method
1 parent 49fd182 commit fc61d3a

File tree

2 files changed

+15
-12
lines changed

2 files changed

+15
-12
lines changed

README.md

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -43,46 +43,47 @@ Following the specification, the `XMLSerializer` interface is a constructor and
4343
```javascript
4444
import XMLSerializer from '@teclone/xml-serializer';
4545

46-
let instance = new XMLSerializer();
46+
const instance = new XMLSerializer();
4747
console.log(instance.serializeToString(someXmlNode));
4848
```
4949

5050
The constructor can take a boolean argument that indicates if whitespace should be preserved in the serialized output. Default value is `true`;
5151

5252
```javascript
5353
// do not preserve white space
54-
let instance = new XMLSerializer(false);
55-
let xmlString = instance.serializeToString(document);
54+
const instance = new XMLSerializer(false);
55+
const xmlString = instance.serializeToString(document);
5656
```
5757

5858
### Using with [JSDOM](https://github.com/jsdom/jsdom)
5959

60-
Currently, JSDOM has not implemented the `XMLSerializer` interface. This can be easily integrated with JSDOM and any other similar mockup environment or for web scrapping and xml feed parsing like below.
60+
Currently [at the time of creating this], JSDOM has not implemented the `XMLSerializer` interface. This can be easily integrated with JSDOM and any other similar mockup environment or for web scrapping and xml feed parsing like below.
6161

6262
```javascript
6363
//assumes jsdom has been installed.
6464
import XMLSerializer from '@teclone/xml-serializer';
6565
import { JSDOM } from 'jsdom';
6666

67-
let dom = new JSDOM();
68-
dom.window.XMLSerializer = XMLSerializer;
67+
const dom = new JSDOM();
68+
XMLSerializer.installTo(dom.window);
69+
6970
global.window = dom.window;
7071

7172
//start running your tests or do something else.
7273
```
7374

7475
### Using on the browser
7576

76-
The browser build is available inside the `dist` folder when you npm install the package. You can also this repo and run the build command locally. It exposes an `XMLSerializer` construct on the `window` object.
77+
The browser build is available inside the `build/dist` folder when you npm install the package. You can also clone this repo and run the build command locally. It exposes an `XMLSerializer` construct on the `window` object.
7778

7879
```html
7980
<script
8081
type="text/javascript"
81-
src="node_modules/@teclone/xml-serializer/dist/main.min.js"
82+
src="node_modules/@teclone/xml-serializer/build/dist/main.js"
8283
>
8384
<script>
8485
<script type="text/javascript">
85-
let serializer = new XMLSerializer();
86+
const serializer = new XMLSerializer();
8687
// do some serialization stuffs
8788
</script>
8889
```
@@ -93,7 +94,7 @@ By default, the serializer preserves white space during the serialization proces
9394

9495
```javascript
9596
//do not preserve white space
96-
let instance = new XMLSerializer(false);
97+
const instance = new XMLSerializer(false);
9798
```
9899

99100
Another improvement is that it removes all duplicate xml prefix definition on as recommended in the specification document unlike what web browsers do. Below is an example of

src/main.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import Serializer from './modules/Serializer.js';
22

3-
export class XMLSerializer {
3+
class XMLSerializer {
44
/**
55
*@param {boolean} [preserveWhiteSpace=true] - boolean value indicating if white spaces
66
* should be preserved as it is in the source
@@ -32,6 +32,8 @@ export class XMLSerializer {
3232
/**
3333
* installs the serialize to the given target object
3434
*/
35-
XMLSerializer.install = target => {
35+
XMLSerializer.installTo = target => {
3636
target.XMLSerializer = XMLSerializer;
3737
};
38+
39+
export default XMLSerializer;

0 commit comments

Comments
 (0)