react-from-dom
Advanced tools
Comparing version 0.6.1 to 0.6.2
@@ -34,3 +34,3 @@ var __read = (this && this.__read) || function (o, n) { | ||
var result = ''; | ||
for (var i = length; i > 0; --i) { | ||
for (var index = length; index > 0; --index) { | ||
result += characters[Math.round(Math.random() * (characters.length - 1))]; | ||
@@ -37,0 +37,0 @@ } |
import * as React from 'react'; | ||
interface Options { | ||
export interface Options { | ||
actions?: Action[]; | ||
@@ -19,2 +19,1 @@ index?: number; | ||
export default function convert(input: Node | string, options?: Options): React.ReactNode | Node; | ||
export {}; |
@@ -28,6 +28,10 @@ var __assign = (this && this.__assign) || function () { | ||
}; | ||
var __spreadArray = (this && this.__spreadArray) || function (to, from) { | ||
for (var i = 0, il = from.length, j = to.length; i < il; i++, j++) | ||
to[j] = from[i]; | ||
return to; | ||
var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) { | ||
if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) { | ||
if (ar || !(i in from)) { | ||
if (!ar) ar = Array.prototype.slice.call(from, 0, i); | ||
ar[i] = from[i]; | ||
} | ||
} | ||
return to.concat(ar || Array.prototype.slice.call(from)); | ||
}; | ||
@@ -47,3 +51,3 @@ /* eslint-disable @typescript-eslint/no-use-before-define */ | ||
} | ||
__spreadArray([], __read(node.attributes)).forEach(function (d) { | ||
__spreadArray([], __read(node.attributes), false).forEach(function (d) { | ||
switch (d.name) { | ||
@@ -91,3 +95,3 @@ // this is manually handled above, so break; | ||
function parseChildren(childNodeList, level, options) { | ||
var children = __spreadArray([], __read(childNodeList)).map(function (node, index) { | ||
var children = __spreadArray([], __read(childNodeList), false).map(function (node, index) { | ||
return convertFromNode(node, __assign(__assign({}, options), { index: index, level: level + 1 })); | ||
@@ -115,6 +119,6 @@ }) | ||
var node = input; | ||
var key = level + "-" + index; | ||
var key = "".concat(level, "-").concat(index); | ||
var result = []; | ||
if (randomKey && level === 0) { | ||
key = randomString() + "-" + key; | ||
key = "".concat(randomString(), "-").concat(key); | ||
} | ||
@@ -154,3 +158,3 @@ /* istanbul ignore else */ | ||
/* istanbul ignore else */ | ||
if (/^\s+$/.test(nodeText) && !/[\u202F\u00A0]/.test(nodeText)) { | ||
if (/^\s+$/.test(nodeText) && !/[\u00A0\u202F]/.test(nodeText)) { | ||
return null; | ||
@@ -163,7 +167,7 @@ } | ||
var parentNodeName = node.parentNode.nodeName.toLowerCase(); | ||
if (noTextChildNodes.indexOf(parentNodeName) !== -1) { | ||
if (noTextChildNodes.includes(parentNodeName)) { | ||
/* istanbul ignore else */ | ||
if (/\S/.test(nodeText)) { | ||
// eslint-disable-next-line no-console | ||
console.warn("A textNode is not allowed inside '" + parentNodeName + "'. Your text \"" + nodeText + "\" will be ignored"); | ||
console.warn("A textNode is not allowed inside '".concat(parentNodeName, "'. Your text \"").concat(nodeText, "\" will be ignored")); | ||
} | ||
@@ -192,6 +196,6 @@ return null; | ||
var parser = new DOMParser(); | ||
var doc = parser.parseFromString(input, type); | ||
var node = doc.querySelector(selector); | ||
var document_1 = parser.parseFromString(input, type); | ||
var node = document_1.querySelector(selector); | ||
if (!(node instanceof Node)) { | ||
throw new Error('Error parsing input'); | ||
throw new TypeError('Error parsing input'); | ||
} | ||
@@ -198,0 +202,0 @@ if (nodeOnly) { |
@@ -38,3 +38,3 @@ "use strict"; | ||
var result = ''; | ||
for (var i = length; i > 0; --i) { | ||
for (var index = length; index > 0; --index) { | ||
result += characters[Math.round(Math.random() * (characters.length - 1))]; | ||
@@ -41,0 +41,0 @@ } |
import * as React from 'react'; | ||
interface Options { | ||
export interface Options { | ||
actions?: Action[]; | ||
@@ -19,2 +19,1 @@ index?: number; | ||
export default function convert(input: Node | string, options?: Options): React.ReactNode | Node; | ||
export {}; |
@@ -29,6 +29,10 @@ "use strict"; | ||
}; | ||
var __spreadArray = (this && this.__spreadArray) || function (to, from) { | ||
for (var i = 0, il = from.length, j = to.length; i < il; i++, j++) | ||
to[j] = from[i]; | ||
return to; | ||
var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) { | ||
if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) { | ||
if (ar || !(i in from)) { | ||
if (!ar) ar = Array.prototype.slice.call(from, 0, i); | ||
ar[i] = from[i]; | ||
} | ||
} | ||
return to.concat(ar || Array.prototype.slice.call(from)); | ||
}; | ||
@@ -50,3 +54,3 @@ Object.defineProperty(exports, "__esModule", { value: true }); | ||
} | ||
__spreadArray([], __read(node.attributes)).forEach(function (d) { | ||
__spreadArray([], __read(node.attributes), false).forEach(function (d) { | ||
switch (d.name) { | ||
@@ -57,3 +61,3 @@ // this is manually handled above, so break; | ||
case 'style': | ||
attributes[d.name] = helpers_1.styleToObject(d.value); | ||
attributes[d.name] = (0, helpers_1.styleToObject)(d.value); | ||
break; | ||
@@ -95,3 +99,3 @@ case 'allowfullscreen': | ||
function parseChildren(childNodeList, level, options) { | ||
var children = __spreadArray([], __read(childNodeList)).map(function (node, index) { | ||
var children = __spreadArray([], __read(childNodeList), false).map(function (node, index) { | ||
return convertFromNode(node, __assign(__assign({}, options), { index: index, level: level + 1 })); | ||
@@ -119,6 +123,6 @@ }) | ||
var node = input; | ||
var key = level + "-" + index; | ||
var key = "".concat(level, "-").concat(index); | ||
var result = []; | ||
if (randomKey && level === 0) { | ||
key = helpers_1.randomString() + "-" + key; | ||
key = "".concat((0, helpers_1.randomString)(), "-").concat(key); | ||
} | ||
@@ -158,3 +162,3 @@ /* istanbul ignore else */ | ||
/* istanbul ignore else */ | ||
if (/^\s+$/.test(nodeText) && !/[\u202F\u00A0]/.test(nodeText)) { | ||
if (/^\s+$/.test(nodeText) && !/[\u00A0\u202F]/.test(nodeText)) { | ||
return null; | ||
@@ -167,7 +171,7 @@ } | ||
var parentNodeName = node.parentNode.nodeName.toLowerCase(); | ||
if (helpers_1.noTextChildNodes.indexOf(parentNodeName) !== -1) { | ||
if (helpers_1.noTextChildNodes.includes(parentNodeName)) { | ||
/* istanbul ignore else */ | ||
if (/\S/.test(nodeText)) { | ||
// eslint-disable-next-line no-console | ||
console.warn("A textNode is not allowed inside '" + parentNodeName + "'. Your text \"" + nodeText + "\" will be ignored"); | ||
console.warn("A textNode is not allowed inside '".concat(parentNodeName, "'. Your text \"").concat(nodeText, "\" will be ignored")); | ||
} | ||
@@ -197,6 +201,6 @@ return null; | ||
var parser = new DOMParser(); | ||
var doc = parser.parseFromString(input, type); | ||
var node = doc.querySelector(selector); | ||
var document_1 = parser.parseFromString(input, type); | ||
var node = document_1.querySelector(selector); | ||
if (!(node instanceof Node)) { | ||
throw new Error('Error parsing input'); | ||
throw new TypeError('Error parsing input'); | ||
} | ||
@@ -203,0 +207,0 @@ if (nodeOnly) { |
{ | ||
"name": "react-from-dom", | ||
"version": "0.6.1", | ||
"version": "0.6.2", | ||
"description": "Convert HTML/XML source code or DOM nodes to React elements", | ||
@@ -11,3 +11,4 @@ "author": "Gil Barbara <gilbarbara@gmail.com>", | ||
"react", | ||
"component" | ||
"component", | ||
"dangerouslySetInnerHTML" | ||
], | ||
@@ -33,36 +34,28 @@ "license": "MIT", | ||
"peerDependencies": { | ||
"react": "^15.0.0 || ^16.0.0 || ^17.0.0" | ||
"react": "^16.8.0 || ^17.0.0 || ^18.0.0" | ||
}, | ||
"devDependencies": { | ||
"@gilbarbara/eslint-config": "^0.1.4", | ||
"@gilbarbara/eslint-config": "^0.2.1", | ||
"@gilbarbara/prettier-config": "^0.1.0", | ||
"@gilbarbara/tsconfig": "^0.1.0", | ||
"@size-limit/preset-small-lib": "^5.0.1", | ||
"@types/enzyme": "^3.10.9", | ||
"@types/enzyme-adapter-react-16": "^1.0.6", | ||
"@types/jest": "^26.0.24", | ||
"@types/node": "^16.3.0", | ||
"@types/react": "^17.0.14", | ||
"@types/react-dom": "^17.0.9", | ||
"@typescript-eslint/eslint-plugin": "^4.28.2", | ||
"@typescript-eslint/parser": "^4.28.2", | ||
"del-cli": "^4.0.0", | ||
"enzyme": "^3.11.0", | ||
"enzyme-adapter-react-16": "^1.15.6", | ||
"fetch-mock": "^9.11.0", | ||
"husky": "^4.3.8", | ||
"@size-limit/preset-small-lib": "^7.0.8", | ||
"@testing-library/jest-dom": "^5.16.4", | ||
"@testing-library/react": "^13.0.1", | ||
"@types/jest": "^27.4.1", | ||
"@types/node": "^17.0.23", | ||
"@types/react": "^18.0.3", | ||
"@types/react-dom": "^18.0.0", | ||
"del-cli": "^4.0.1", | ||
"husky": "^7.0.4", | ||
"is-ci-cli": "^2.2.0", | ||
"jest": "^27.0.6", | ||
"jest-chain": "^1.1.5", | ||
"jest-enzyme": "^7.1.2", | ||
"jest-extended": "^0.11.5", | ||
"jest-watch-typeahead": "^0.6.4", | ||
"prettier": "^2.3.2", | ||
"react": "^16.14.0", | ||
"react-dom": "^16.14.0", | ||
"jest": "^27.5.1", | ||
"jest-extended": "^2.0.0", | ||
"jest-watch-typeahead": "^1.0.0", | ||
"react": "^18.0.0", | ||
"react-dom": "^18.0.0", | ||
"repo-tools": "^0.2.2", | ||
"serve": "^12.0.0", | ||
"size-limit": "^5.0.1", | ||
"ts-jest": "^27.0.3", | ||
"typescript": "^4.3.5" | ||
"size-limit": "^7.0.8", | ||
"ts-jest": "^27.1.4", | ||
"ts-node": "^10.7.0", | ||
"typescript": "^4.6.3" | ||
}, | ||
@@ -84,3 +77,4 @@ "scripts": { | ||
"size": "size-limit", | ||
"prepublishOnly": "npm run validate" | ||
"prepublishOnly": "npm run validate", | ||
"prepare": "husky install" | ||
}, | ||
@@ -95,16 +89,12 @@ "eslintConfig": { | ||
{ | ||
"name": "lib", | ||
"path": "./lib/index.js", | ||
"limit": "5 kB" | ||
"limit": "6 kB" | ||
}, | ||
{ | ||
"name": "esm", | ||
"path": "./esm/index.js", | ||
"limit": "5 kB" | ||
"limit": "6 kB" | ||
} | ||
], | ||
"husky": { | ||
"hooks": { | ||
"post-merge": "repo-tools install-packages", | ||
"pre-commit": "repo-tools check-remote && npm run validate" | ||
} | ||
} | ||
] | ||
} |
# react-from-dom | ||
[![NPM version](https://badge.fury.io/js/react-from-dom.svg)](https://www.npmjs.com/package/react-from-dom) [![Build Status](https://travis-ci.com/gilbarbara/react-from-dom.svg?branch=master)](https://travis-ci.com/gilbarbara/react-from-dom) [![Maintainability](https://api.codeclimate.com/v1/badges/8b7357d2d51cd2ee7f8e/maintainability)](https://codeclimate.com/github/gilbarbara/react-from-dom/maintainability) [![Test Coverage](https://api.codeclimate.com/v1/badges/8b7357d2d51cd2ee7f8e/test_coverage)](https://codeclimate.com/github/gilbarbara/react-from-dom/test_coverage) | ||
[![NPM version](https://badge.fury.io/js/react-from-dom.svg)](https://www.npmjs.com/package/react-from-dom) [![CI](https://github.com/gilbarbara/react-from-dom/actions/workflows/main.yml/badge.svg)](https://github.com/gilbarbara/react-from-dom/actions/workflows/main.yml) [![Maintainability](https://api.codeclimate.com/v1/badges/8b7357d2d51cd2ee7f8e/maintainability)](https://codeclimate.com/github/gilbarbara/react-from-dom/maintainability) [![Test Coverage](https://api.codeclimate.com/v1/badges/8b7357d2d51cd2ee7f8e/test_coverage)](https://codeclimate.com/github/gilbarbara/react-from-dom/test_coverage) | ||
@@ -159,2 +159,2 @@ Convert HTML/XML source code or a DOM node to a React element. | ||
MIT | ||
MIT |
@@ -22,3 +22,3 @@ export const styleToObject = (input: string): Record<string, any> => { | ||
for (let i = length; i > 0; --i) { | ||
for (let index = length; index > 0; --index) { | ||
result += characters[Math.round(Math.random() * (characters.length - 1))]; | ||
@@ -25,0 +25,0 @@ } |
@@ -6,3 +6,3 @@ /* eslint-disable @typescript-eslint/no-use-before-define */ | ||
interface Options { | ||
export interface Options { | ||
actions?: Action[]; | ||
@@ -128,3 +128,3 @@ index?: number; | ||
let key = `${level}-${index}`; | ||
const result: Array<Node | React.ReactNode> = []; | ||
const result: React.ReactNode[] = []; | ||
@@ -180,3 +180,3 @@ if (randomKey && level === 0) { | ||
/* istanbul ignore else */ | ||
if (/^\s+$/.test(nodeText) && !/[\u202F\u00A0]/.test(nodeText)) { | ||
if (/^\s+$/.test(nodeText) && !/[\u00A0\u202F]/.test(nodeText)) { | ||
return null; | ||
@@ -192,3 +192,3 @@ } | ||
if (noTextChildNodes.indexOf(parentNodeName) !== -1) { | ||
if (noTextChildNodes.includes(parentNodeName)) { | ||
/* istanbul ignore else */ | ||
@@ -227,7 +227,7 @@ if (/\S/.test(nodeText)) { | ||
const parser = new DOMParser(); | ||
const doc = parser.parseFromString(input, type as DOMParserSupportedType); | ||
const node = doc.querySelector(selector); | ||
const document = parser.parseFromString(input, type as DOMParserSupportedType); | ||
const node = document.querySelector(selector); | ||
if (!(node instanceof Node)) { | ||
throw new Error('Error parsing input'); | ||
throw new TypeError('Error parsing input'); | ||
} | ||
@@ -234,0 +234,0 @@ |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
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
100580
23
1923
160