convert-text-to-react
Advanced tools
Comparing version
import * as React from "react"; | ||
export declare const toJSX: (raw: string) => string | null; | ||
export declare const createConverter: (components: object) => (raw: string) => React.ReactElement<any>; | ||
export declare const toCode: (raw: string) => string | null; | ||
export declare const convert: (raw: string, components: object) => React.ReactElement<any>; |
@@ -5,11 +5,11 @@ "use strict"; | ||
const React = require("react"); | ||
exports.toJSX = (raw) => babel.transform(raw, { | ||
plugins: ["@babel/plugin-transform-react-jsx", "@babel/plugin-syntax-object-rest-spread"], | ||
exports.toCode = (raw) => babel.transform(raw, { | ||
plugins: ["@babel/plugin-transform-react-jsx"], | ||
}).code; | ||
exports.createConverter = (components) => (raw) => { | ||
const code = exports.toJSX(raw); | ||
exports.convert = (raw, components) => { | ||
const code = exports.toCode(raw); | ||
const keys = Object.keys(components); | ||
const values = keys.map(key => components[key]); | ||
const create = new Function("React", ...keys, `return props => ${code}`); | ||
return create(React, ...values)(); | ||
const create = new Function("React", ...keys, `return ${code}`); | ||
return create(React, ...values); | ||
}; |
@@ -1,2 +0,2 @@ | ||
export { toJSX, createConverter } from "./converter"; | ||
export { toCode, convert } from "./converter"; | ||
export { ExampleComponent, ExampleComponentProps } from "./example"; |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
var converter_1 = require("./converter"); | ||
exports.toJSX = converter_1.toJSX; | ||
exports.createConverter = converter_1.createConverter; | ||
exports.toCode = converter_1.toCode; | ||
exports.convert = converter_1.convert; | ||
var example_1 = require("./example"); | ||
exports.ExampleComponent = example_1.ExampleComponent; |
{ | ||
"name": "convert-text-to-react", | ||
"version": "0.2.2", | ||
"version": "0.2.3", | ||
"description": "プレーンテキストをReactに変換する", | ||
@@ -32,3 +32,2 @@ "main": "lib/index.js", | ||
"@babel/core": "^7.1.6", | ||
"@babel/plugin-syntax-object-rest-spread": "^7.2.0", | ||
"@babel/plugin-transform-react-jsx": "^7.1.6", | ||
@@ -42,6 +41,6 @@ "react": "^16.6.3" | ||
"@types/react-dom": "^16.0.11", | ||
"react-dom": "^16.6.3", | ||
"jest": "^23.6.0", | ||
"jest-cli": "^23.6.0", | ||
"prettier": "^1.15.3", | ||
"react-dom": "^16.6.3", | ||
"ts-jest": "^23.10.5", | ||
@@ -48,0 +47,0 @@ "ts-node": "^7.0.1", |
@@ -13,5 +13,5 @@ # convert-text-to-react | ||
import * as ReactDOM from "react-dom/server"; | ||
import { createConverter, ExampleComponent } from "convert-text-to-react"; | ||
import { convert, ExampleComponent } from "convert-text-to-react"; | ||
const inputText = "<ExampleComponent x={1} y={-20}>Result of multiplication:</ExampleComponent>"; | ||
const rawText = "<ExampleComponent x={1} y={-20}>Result of multiplication:</ExampleComponent>"; | ||
@@ -22,4 +22,3 @@ const components = { | ||
const converter = createConverter(components); | ||
const result = converter(inputText); | ||
const result = convert(rawText, components); | ||
@@ -26,0 +25,0 @@ console.log(ReactDOM.renderToStaticMarkup(result); |
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
Uses eval
Supply chain riskPackage uses dynamic code execution (e.g., eval()), which is a dangerous practice. This can prevent the code from running in certain environments and increases the risk that the code may contain exploits or malicious behavior.
Found 1 instance in 1 package
Uses eval
Supply chain riskPackage uses dynamic code execution (e.g., eval()), which is a dangerous practice. This can prevent the code from running in certain environments and increases the risk that the code may contain exploits or malicious behavior.
Found 1 instance in 1 package
182052
5.72%3
-25%23
15%271
12.92%34
-2.86%- Removed