Comparing version 1.2.0 to 1.3.0
@@ -53,2 +53,5 @@ const { extractProps } = require('./lib');; | ||
module.exports=extractTags; | ||
module.exports=extractTags; | ||
; | ||
module.exports.extractProps = extractProps |
@@ -15,13 +15,14 @@ const { attributeRe } = require('./res');; | ||
* Parse the arguments part of an XML element | ||
* @param {string} s String to extract attributes from | ||
* @param {string} string String to extract attributes from. | ||
* @param {parseValue} string Parse `true` and `false` values into a boolean, and numbers into integers. Default `true`. | ||
*/ | ||
const extractProps = s => { | ||
const extractProps = (string, parseValue = true) => { | ||
const o = {}; | ||
const re = new RegExp(attributeRe.source, 'gu'); | ||
s.replace(re, (match, name, doubleQuoteVal, singleQuoteVal) => { | ||
string.replace(re, (match, name, doubleQuoteVal, singleQuoteVal) => { | ||
const value = singleQuoteVal || doubleQuoteVal; | ||
const v = value === undefined ? true : value; | ||
const val = getPropValue(v); | ||
const val = parseValue ? getPropValue(v) : v; | ||
o[name] = val; | ||
@@ -28,0 +29,0 @@ }); |
@@ -0,1 +1,7 @@ | ||
## 10 February 2019 | ||
### 1.3.0 | ||
- [feature] Expose `extractProps` and add option to disable parsing. | ||
## 1 October 2018 | ||
@@ -2,0 +8,0 @@ |
{ | ||
"name": "rexml", | ||
"version": "1.2.0", | ||
"version": "1.3.0", | ||
"description": "Simple XML parsing with a regular expression.", | ||
@@ -42,12 +42,12 @@ "main": "build", | ||
"devDependencies": { | ||
"@babel/cli": "7.1.2", | ||
"@babel/core": "7.1.2", | ||
"@babel/plugin-proposal-unicode-property-regex": "7.0.0", | ||
"@babel/cli": "7.2.3", | ||
"@babel/core": "7.2.2", | ||
"@babel/plugin-proposal-unicode-property-regex": "7.2.0", | ||
"@babel/register": "7.0.0", | ||
"alamode": "1.5.1", | ||
"documentary": "1.20.1", | ||
"alamode": "1.7.3", | ||
"documentary": "1.21.1", | ||
"eslint-config-artdeco": "1.0.1", | ||
"yarn-s": "1.1.0", | ||
"zoroaster": "3.6.1" | ||
"zoroaster": "3.6.6" | ||
} | ||
} |
@@ -11,2 +11,4 @@ # rexml | ||
<p align="center"><a href="#table-of-contents"><img src=".documentary/section-breaks/0.svg?sanitize=true"></a></p> | ||
## Table Of Contents | ||
@@ -17,3 +19,7 @@ | ||
* [`rexml(tag: string, string: string): {content, props}[]`](#rexmltag-stringstring-string-content-props) | ||
* [`extractProps(string: string, parseValue?: boolean): Object<string,(boolean|string|number)>`](#extractpropsstring-stringparsevalue-boolean-objectstringbooleanstringnumber) | ||
- [Copyright](#copyright) | ||
<p align="center"><a href="#table-of-contents"><img src=".documentary/section-breaks/1.svg?sanitize=true"></a></p> | ||
## API | ||
@@ -27,2 +33,4 @@ | ||
<p align="center"><a href="#table-of-contents"><img src=".documentary/section-breaks/2.svg?sanitize=true" width="15"></a></p> | ||
### `rexml(`<br/> `tag: string,`<br/> `string: string,`<br/>`): {content, props}[]` | ||
@@ -70,6 +78,71 @@ | ||
--- | ||
<p align="center"><a href="#table-of-contents"><img src=".documentary/section-breaks/3.svg?sanitize=true" width="15"></a></p> | ||
(c) [Art Deco][1] 2018 | ||
### `extractProps(`<br/> `string: string,`<br/> `parseValue?: boolean,`<br/>`): Object<string,(boolean|string|number)>` | ||
[1]: https://artdeco.bz | ||
Extracts the properties from the attributes part of the tag and returns them as an object. It will parse values if not specified otherwise. | ||
```javascript | ||
import { extractProps } from 'rexml' | ||
const s = `id="d2" | ||
class="example" | ||
value="123" | ||
parsable="true" | ||
ignore="false" | ||
required` | ||
const res = extractProps(s) | ||
console.log(JSON.stringify(res, null, 2)) | ||
// don't parse booleans and integers | ||
const res2 = extractProps(s, false) | ||
console.log(JSON.stringify(res2, null, 2)) | ||
``` | ||
```json | ||
{ | ||
"id": "d2", | ||
"class": "example", | ||
"value": 123, | ||
"parsable": true, | ||
"ignore": false, | ||
"required": true | ||
} | ||
{ | ||
"id": "d2", | ||
"class": "example", | ||
"value": "123", | ||
"parsable": "true", | ||
"ignore": "false", | ||
"required": true | ||
} | ||
``` | ||
<p align="center"><a href="#table-of-contents"><img src=".documentary/section-breaks/4.svg?sanitize=true"></a></p> | ||
## Copyright | ||
<table> | ||
<tr> | ||
<th> | ||
<a href="https://artd.eco"> | ||
<img src="https://raw.githubusercontent.com/wrote/wrote/master/images/artdeco.png" alt="Art Deco" /> | ||
</a> | ||
</th> | ||
<th> | ||
© <a href="https://artd.eco">Art Deco</a> | ||
2019 | ||
</th> | ||
<th> | ||
<a href="https://www.technation.sucks" title="Tech Nation Visa"> | ||
<img src="https://raw.githubusercontent.com/artdecoweb/www.technation.sucks/master/anim.gif" alt="Tech Nation Visa" /> | ||
</a> | ||
</th> | ||
<th> | ||
<a href="https://www.technation.sucks">Tech Nation Visa Sucks</a> | ||
</th> | ||
</tr> | ||
</table> | ||
<p align="center"><a href="#table-of-contents"><img src=".documentary/section-breaks/-1.svg?sanitize=true"></a></p> |
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
25533
142
144