html-react-parser 1.2.9 → 1.4.2

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.
@@ -1,54 +1,48 @@
1
1
  var reactProperty = require('react-property');
2
2
  var utilities = require('./utilities');
3
3
 
4
- var setStyleProp = utilities.setStyleProp;
5
-
6
- var htmlProperties = reactProperty.html;
7
- var svgProperties = reactProperty.svg;
8
- var isCustomAttribute = reactProperty.isCustomAttribute;
9
-
10
- var hasOwnProperty = Object.prototype.hasOwnProperty;
11
-
12
4
  /**
13
5
  * Converts HTML/SVG DOM attributes to React props.
14
6
  *
15
7
  * @param {object} [attributes={}] - HTML/SVG DOM attributes.
16
8
  * @return {object} - React props.
17
9
  */
18
- function attributesToProps(attributes) {
10
+ module.exports = function attributesToProps(attributes) {
19
11
  attributes = attributes || {};
20
12
 
21
13
  var attributeName;
22
14
  var attributeNameLowerCased;
23
15
  var attributeValue;
24
- var property;
16
+ var propName;
17
+ var propertyInfo;
25
18
  var props = {};
26
19
 
27
20
  for (attributeName in attributes) {
28
21
  attributeValue = attributes[attributeName];
29
22
 
30
23
  // ARIA (aria-*) or custom data (data-*) attribute
31
- if (isCustomAttribute(attributeName)) {
24
+ if (reactProperty.isCustomAttribute(attributeName)) {
32
25
  props[attributeName] = attributeValue;
33
26
  continue;
34
27
  }
35
28
 
36
- // convert HTML attribute to React prop
29
+ // convert HTML/SVG attribute to React prop
37
30
  attributeNameLowerCased = attributeName.toLowerCase();
38
- if (hasOwnProperty.call(htmlProperties, attributeNameLowerCased)) {
39
- property = htmlProperties[attributeNameLowerCased];
40
- props[property.propertyName] =
41
- property.hasBooleanValue ||
42
- (property.hasOverloadedBooleanValue && !attributeValue)
43
- ? true
44
- : attributeValue;
45
- continue;
46
- }
47
-
48
- // convert SVG attribute to React prop
49
- if (hasOwnProperty.call(svgProperties, attributeName)) {
50
- property = svgProperties[attributeName];
51
- props[property.propertyName] = attributeValue;
31
+ propName = reactProperty.possibleStandardNames[attributeNameLowerCased];
32
+
33
+ if (propName) {
34
+ props[propName] = attributeValue;
35
+ propertyInfo = reactProperty.getPropertyInfo(propName);
36
+ switch (propertyInfo && propertyInfo.type) {
37
+ case reactProperty.BOOLEAN:
38
+ props[propName] = true;
39
+ break;
40
+ case reactProperty.OVERLOADED_BOOLEAN:
41
+ if (attributeValue === '') {
42
+ props[propName] = true;
43
+ }
44
+ break;
45
+ }
52
46
  continue;
53
47
  }
54
48
 
@@ -59,9 +53,7 @@ function attributesToProps(attributes) {
59
53
  }
60
54
 
61
55
  // transform inline style to object
62
- setStyleProp(attributes.style, props);
56
+ utilities.setStyleProp(attributes.style, props);
63
57
 
64
58
  return props;
65
- }
66
-
67
- module.exports = attributesToProps;
59
+ };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "html-react-parser",
3
- "version": "1.2.9",
3
+ "version": "1.4.2",
4
4
  "description": "HTML to React parser.",
5
5
  "author": "Mark <mark@remarkablemark.org>",
6
6
  "main": "index.js",
@@ -15,7 +15,7 @@
15
15
  "_postinstall": "husky install",
16
16
  "postpublish": "pinst --enable",
17
17
  "prepublishOnly": "pinst --disable && npm run lint && npm run lint:dts && npm run test:ci && npm run clean && npm run build",
18
- "release": "standard-version --no-verify",
18
+ "size-limit": "size-limit",
19
19
  "test": "jest --coverage --testPathIgnorePatterns test/integration/",
20
20
  "test:ci": "npm test -- --ci",
21
21
  "test:module": "node --experimental-modules test/module/index.mjs",
@@ -37,37 +37,36 @@
37
37
  "dom"
38
38
  ],
39
39
  "dependencies": {
40
- "domhandler": "4.2.2",
41
- "html-dom-parser": "1.0.2",
42
- "react-property": "1.0.2",
40
+ "domhandler": "4.3.0",
41
+ "html-dom-parser": "1.0.4",
42
+ "react-property": "2.0.0",
43
43
  "style-to-js": "1.1.0"
44
44
  },
45
45
  "devDependencies": {
46
- "@commitlint/cli": "13.1.0",
47
- "@commitlint/config-conventional": "13.1.0",
48
- "@rollup/plugin-commonjs": "20.0.0",
49
- "@rollup/plugin-node-resolve": "13.0.4",
50
- "@size-limit/preset-big-lib": "5.0.3",
51
- "@types/react": "17.0.20",
52
- "@typescript-eslint/parser": "4.30.0",
46
+ "@commitlint/cli": "15.0.0",
47
+ "@commitlint/config-conventional": "15.0.0",
48
+ "@rollup/plugin-commonjs": "21.0.1",
49
+ "@rollup/plugin-node-resolve": "13.0.6",
50
+ "@size-limit/preset-big-lib": "7.0.4",
51
+ "@types/react": "17.0.37",
52
+ "@typescript-eslint/parser": "5.6.0",
53
53
  "benchmark": "2.1.4",
54
- "dtslint": "4.1.6",
55
- "eslint": "7.32.0",
54
+ "dtslint": "4.2.1",
55
+ "eslint": "8.4.0",
56
56
  "eslint-plugin-prettier": "4.0.0",
57
- "husky": "7.0.2",
58
- "jest": "27.1.0",
59
- "lint-staged": "11.1.2",
57
+ "husky": "7.0.4",
58
+ "jest": "27.4.3",
59
+ "lint-staged": "12.1.2",
60
60
  "pinst": "2.1.6",
61
- "preact": "10.5.14",
62
- "prettier": "2.3.2",
61
+ "preact": "10.6.2",
62
+ "prettier": "2.5.1",
63
63
  "react": "17.0.2",
64
64
  "react-dom": "17.0.2",
65
65
  "rimraf": "3.0.2",
66
- "rollup": "2.56.3",
66
+ "rollup": "2.60.2",
67
67
  "rollup-plugin-terser": "7.0.2",
68
- "size-limit": "5.0.3",
69
- "standard-version": "9.3.1",
70
- "typescript": "4.4.2"
68
+ "size-limit": "7.0.4",
69
+ "typescript": "4.5.2"
71
70
  },
72
71
  "peerDependencies": {
73
72
  "react": "0.14 || 15 || 16 || 17"