Comparing version 5.0.1 to 5.1.0
@@ -9,2 +9,6 @@ # Changelog | ||
# 5.1.0 | ||
* `FEAT`: proxy mode exposes clonable view [`73c6c44a`](https://github.com/nikku/saxen/commit/73c6c44ade3127f3819ceb825e241bb39d74fd93) | ||
# 5.0.1 | ||
@@ -11,0 +15,0 @@ |
@@ -16,3 +16,3 @@ { | ||
], | ||
"version": "5.0.1", | ||
"version": "5.1.0", | ||
"main": "./parser.js", | ||
@@ -19,0 +19,0 @@ "bugs": { |
@@ -33,3 +33,4 @@ 'use strict'; | ||
return { | ||
get: getFn | ||
get: getFn, | ||
enumerable: true | ||
}; | ||
@@ -36,0 +37,0 @@ } |
@@ -60,3 +60,8 @@ # `/saxen/` parser <img src="https://upload.wikimedia.org/wikipedia/commons/thumb/5/5f/Coat_of_arms_of_Saxony.svg/220px-Coat_of_arms_of_Saxony.svg.png" align="right" /> | ||
In [proxy mode](#proxy-mode), `openTag` and `closeTag` a view of the current element replaces the raw element name. In addition element attributes are not passed as a getter to `openTag`. Instead, they get exposed via the `element.attrs`: | ||
* `openTag(element, decodeEntities, selfClosing, contextGetter)` | ||
* `closeTag(element, selfClosing, contextGetter)` | ||
## Namespace Handling | ||
@@ -82,2 +87,36 @@ | ||
## Proxy Mode | ||
In this mode, the first argument passed to `openTag` and `closeTag` is an object that exposes more internal XML parse state. This needs to be explicity enabled by instantiating the parser with `{ proxy: true }`. | ||
```javascript | ||
// instantiate parser with proxy=true | ||
var parser = new Parser({ proxy: true }); | ||
parser.ns({ | ||
'http://foo-ns': 'foo' | ||
}); | ||
parser.on('openTag', function(el, decodeEntities, selfClosing, getContext) { | ||
el.originalName; // root | ||
el.name; // foo:root | ||
el.attrs; // { 'xmlns:foo': ..., id: '1' } | ||
el.ns; // { xmlns: 'foo', foo: 'foo', foo$uri: 'http://foo-ns' } | ||
}); | ||
parser.parse('<root xmlns:foo="http://foo-ns" id="1" />') | ||
``` | ||
Proxy mode comes with a performance penelty of roughly five percent. | ||
__Caution!__ For performance reasons the exposed element is a simple view into the current parser state. Because of that, it will change with the parser advancing and cannot be cached. If you would like to retain a persistent copy of the values, create a shallow clone: | ||
```javascript | ||
parser.on('openTag', function(el) { | ||
var copy = Object.assign({}, el); | ||
// copy, ready to keep around | ||
}); | ||
``` | ||
## Non-Features | ||
@@ -84,0 +123,0 @@ |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
30054
728
142