react-from-dom
Advanced tools
Comparing version 0.7.2 to 0.7.3
@@ -45,8 +45,11 @@ "use strict"; | ||
} | ||
const attributes = input.replace(/\s+/g, "").split(/ ?; ?/); | ||
return attributes.reduce((acc, d) => { | ||
const [key, value] = d.split(/ ?: ?/); | ||
return input.split(/ ?; ?/).reduce((acc, item) => { | ||
const [key, value] = item.split(/ ?: ?/).map((d, index) => index === 0 ? d.replace(/\s+/g, "") : d.trim()); | ||
if (key && value) { | ||
const nextKey = key.replace(/-(\w)/g, (_$0, $1) => $1.toUpperCase()); | ||
acc[key.startsWith("-") ? key : nextKey] = Number.isNaN(Number(value)) ? value : Number(value); | ||
const nextKey = key.replace(/(\w)-(\w)/g, (_$0, $1, $2) => `${$1}${$2.toUpperCase()}`); | ||
let nextValue = value.trim(); | ||
if (!Number.isNaN(Number(value))) { | ||
nextValue = Number(value); | ||
} | ||
acc[key.startsWith("-") ? key : nextKey] = nextValue; | ||
} | ||
@@ -53,0 +56,0 @@ return acc; |
{ | ||
"name": "react-from-dom", | ||
"version": "0.7.2", | ||
"version": "0.7.3", | ||
"description": "Convert HTML/XML source code or DOM nodes to React elements", | ||
@@ -44,8 +44,8 @@ "author": "Gil Barbara <gilbarbara@gmail.com>", | ||
"@size-limit/preset-small-lib": "^11.0.2", | ||
"@swc/core": "^1.4.2", | ||
"@swc/core": "^1.4.5", | ||
"@testing-library/jest-dom": "^6.4.2", | ||
"@testing-library/react": "^14.2.1", | ||
"@types/node": "^20.11.21", | ||
"@types/react": "^18.2.60", | ||
"@types/react-dom": "^18.2.19", | ||
"@types/node": "^20.11.25", | ||
"@types/react": "^18.2.64", | ||
"@types/react-dom": "^18.2.21", | ||
"@vitejs/plugin-react-swc": "^3.6.0", | ||
@@ -52,0 +52,0 @@ "@vitest/coverage-v8": "^1.3.1", |
@@ -7,13 +7,16 @@ export const styleToObject = (input: string): Record<string, any> => { | ||
const attributes = input.replace(/\s+/g, '').split(/ ?; ?/); | ||
return input.split(/ ?; ?/).reduce<Record<string, string | number>>((acc, item: string) => { | ||
const [key, value] = item | ||
.split(/ ?: ?/) | ||
.map((d, index) => (index === 0 ? d.replace(/\s+/g, '') : d.trim())); | ||
return attributes.reduce<Record<string, string | number>>((acc, d: string) => { | ||
const [key, value] = d.split(/ ?: ?/); | ||
if (key && value) { | ||
const nextKey = key.replace(/-(\w)/g, (_$0, $1) => $1.toUpperCase()); | ||
const nextKey = key.replace(/(\w)-(\w)/g, (_$0, $1, $2) => `${$1}${$2.toUpperCase()}`); | ||
let nextValue: string | number = value.trim(); | ||
acc[key.startsWith('-') ? key : nextKey] = Number.isNaN(Number(value)) | ||
? value | ||
: Number(value); | ||
if (!Number.isNaN(Number(value))) { | ||
nextValue = Number(value); | ||
} | ||
acc[key.startsWith('-') ? key : nextKey] = nextValue; | ||
} | ||
@@ -20,0 +23,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
131341
1924