Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

hast-to-hyperscript

Package Overview
Dependencies
Maintainers
2
Versions
29
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

hast-to-hyperscript - npm Package Compare versions

Comparing version 9.0.0 to 9.0.1

164

index.js

@@ -17,4 +17,2 @@ 'use strict'

var dashes = /-([a-z])/g
module.exports = wrapper

@@ -24,6 +22,6 @@

var settings = options || {}
var r = react(h)
var v = vue(h)
var vd = vdom(h)
var prefix
var r
var v
var vd

@@ -41,21 +39,12 @@ if (typeof h !== 'function') {

r = react(h)
v = vue(h)
vd = vdom(h)
if (prefix === null || prefix === undefined) {
prefix = r === true || v === true || vd === true ? 'h-' : false
}
if (root(node)) {
if (node.children.length === 1 && element(node.children[0])) {
node = node.children[0]
} else {
node = {
type: 'element',
tagName: 'div',
properties: {},
children: node.children
}
}
node =
node.children.length === 1 && element(node.children[0])
? node.children[0]
: {
type: 'element',
tagName: 'div',
properties: {},
children: node.children
}
} else if (!element(node)) {

@@ -69,3 +58,3 @@ throw new Error(

schema: settings.space === 'svg' ? svg : html,
prefix: prefix,
prefix: prefix == null ? (r || v || vd ? 'h-' : null) : prefix,
key: 0,

@@ -84,11 +73,7 @@ react: r,

var name = node.tagName
var properties
var attributes
var children
var property
var elements
var length
var index
var attributes = {}
var nodes = []
var index = -1
var key
var value
var result

@@ -100,21 +85,14 @@ if (parentSchema.space === 'html' && name.toLowerCase() === 'svg') {

if (ctx.vdom === true && schema.space === 'html') {
name = name.toUpperCase()
for (key in node.properties) {
addAttribute(attributes, key, node.properties[key], ctx, name)
}
properties = node.properties
attributes = {}
for (property in properties) {
addAttribute(attributes, property, properties[property], ctx)
if (ctx.vdom) {
if (schema.space === 'html') {
name = name.toUpperCase()
} else {
attributes.namespace = ns[schema.space]
}
}
if (
typeof attributes.style === 'string' &&
(ctx.vdom === true || ctx.vue === true || ctx.react === true)
) {
// VDOM, Vue, and React accept `style` as object.
attributes.style = parseStyle(attributes.style, name)
}
if (ctx.prefix) {

@@ -125,38 +103,26 @@ ctx.key++

if (ctx.vdom && schema.space !== 'html') {
attributes.namespace = ns[schema.space]
}
if (node.children) {
while (++index < node.children.length) {
value = node.children[index]
elements = []
children = node.children
length = children ? children.length : 0
index = -1
while (++index < length) {
value = children[index]
if (element(value)) {
elements.push(toH(h, value, ctx))
} else if (text(value)) {
elements.push(value.value)
if (element(value)) {
nodes.push(toH(h, value, ctx))
} else if (text(value)) {
nodes.push(value.value)
}
}
}
// Ensure no React warnings are triggered for void elements having children
// passed in.
result =
elements.length === 0
? h.call(node, name, attributes)
: h.call(node, name, attributes, elements)
// Restore parent schema.
ctx.schema = parentSchema
return result
// Ensure no React warnings are triggered for void elements having children
// passed in.
return nodes.length
? h.call(node, name, attributes, nodes)
: h.call(node, name, attributes)
}
function addAttribute(props, prop, value, ctx) {
var hyperlike = ctx.hyperscript || ctx.vdom || ctx.vue
var schema = ctx.schema
var info = find(schema, prop)
function addAttribute(props, prop, value, ctx, name) {
var info = find(ctx.schema, prop)
var subprop

@@ -167,7 +133,6 @@

if (
value === null ||
value === undefined ||
value == null ||
value !== value ||
(hyperlike && value === false) ||
(hyperlike && info.boolean && !value)
(value === false && (ctx.vue || ctx.vdom || ctx.hyperscript)) ||
(!value && info.boolean && (ctx.vue || ctx.vdom || ctx.hyperscript))
) {

@@ -177,3 +142,3 @@ return

if (value !== null && typeof value === 'object' && 'length' in value) {
if (value && typeof value === 'object' && 'length' in value) {
// Accept `array`.

@@ -185,14 +150,21 @@ // Most props are space-separated.

// Treat `true` and truthy known booleans.
if (info.boolean && ctx.hyperscript === true) {
if (info.boolean && ctx.hyperscript) {
value = ''
}
// VDOM, Vue, and React accept `style` as object.
if (
info.property === 'style' &&
typeof value === 'string' &&
(ctx.react || ctx.vue || ctx.vdom)
) {
value = parseStyle(value, name)
}
if (ctx.vue) {
if (prop !== 'style') {
subprop = 'attrs'
}
if (info.property !== 'style') subprop = 'attrs'
} else if (!info.mustUseProperty) {
if (ctx.vdom === true) {
subprop = 'attributes'
} else if (ctx.hyperscript === true) {
if (ctx.vdom) {
if (info.property !== 'style') subprop = 'attributes'
} else if (ctx.hyperscript) {
subprop = 'attrs'

@@ -203,8 +175,5 @@ }

if (subprop) {
if (props[subprop] === undefined) {
props[subprop] = {}
}
if (!props[subprop]) props[subprop] = {}
props[subprop][info.attribute] = value
} else if (ctx.react && info.space) {
} else if (info.space && ctx.react) {
props[hastToReact[info.property] || info.property] = value

@@ -220,3 +189,3 @@ } else {

return Boolean(
node && ('_owner' in node || '_store' in node) && node.key === null
node && ('_owner' in node || '_store' in node) && node.key == null
)

@@ -254,16 +223,9 @@ }

function iterator(name, value) {
result[styleCase(name)] = value
if (name.slice(0, 4) === '-ms-') name = 'ms-' + name.slice(4)
result[name.replace(/-([a-z])/g, styleReplacer)] = value
}
}
function styleCase(value) {
if (value.slice(0, 4) === '-ms-') {
value = 'ms-' + value.slice(4)
}
return value.replace(dashes, styleReplacer)
}
function styleReplacer($0, $1) {
return $1.toUpperCase()
}
{
"name": "hast-to-hyperscript",
"version": "9.0.0",
"version": "9.0.1",
"description": "hast utility to transform to something else (react, vue, etc) through a hyperscript DSL",

@@ -53,14 +53,14 @@ "license": "MIT",

"@types/virtual-dom": "^2.0.0",
"browserify": "^16.0.0",
"dtslint": "^3.0.0",
"browserify": "^17.0.0",
"dtslint": "^4.0.0",
"hyperscript": "^2.0.0",
"nyc": "^15.0.0",
"prettier": "^2.0.0",
"react": "^16.0.0",
"react-dom": "^16.0.0",
"rehype": "^10.0.0",
"remark-cli": "^8.0.0",
"remark-preset-wooorm": "^7.0.0",
"react": "^17.0.0",
"react-dom": "^17.0.0",
"rehype": "^11.0.0",
"remark-cli": "^9.0.0",
"remark-preset-wooorm": "^8.0.0",
"tape": "^5.0.0",
"tinyify": "^2.0.0",
"tinyify": "^3.0.0",
"unist-builder": "^2.0.0",

@@ -71,6 +71,6 @@ "vdom-to-html": "^2.0.0",

"vue-server-renderer": "^2.0.0",
"xo": "^0.32.0"
"xo": "^0.34.0"
},
"scripts": {
"format": "remark . -qfo && prettier --write \"**/*.{js,ts}\" && xo --fix",
"format": "remark . -qfo && prettier . -w --loglevel warn && xo --fix",
"build-bundle": "browserify index.js -s hastToHyperscript > hast-to-hyperscript.js",

@@ -102,8 +102,17 @@ "build-mangle": "browserify index.js -s hastToHyperscript -p tinyify > hast-to-hyperscript.min.js",

"rules": {
"unicorn/no-fn-reference-in-iterator": "off",
"unicorn/prefer-type-error": "off",
"@typescript-eslint/prefer-readonly-parameter-types": "off",
"complexity": "off",
"eqeqeq": [
"error",
"always",
{
"null": "ignore"
}
],
"guard-for-in": "off",
"max-params": "off",
"no-eq-null": "off",
"no-self-compare": "off",
"complexity": "off"
"unicorn/explicit-length-check": "off",
"unicorn/no-fn-reference-in-iterator": "off",
"unicorn/prefer-type-error": "off"
}

@@ -110,0 +119,0 @@ },

@@ -142,3 +142,3 @@ # hast-to-hyperscript

[cross-site scripting (XSS)][xss] attack if the hast tree is unsafe.
Use [`hast-util-santize`][sanitize] to make the hast tree safe.
Use [`hast-util-sanitize`][sanitize] to make the hast tree safe.

@@ -196,5 +196,5 @@ ## Related

[chat-badge]: https://img.shields.io/badge/chat-spectrum-7b16ff.svg
[chat-badge]: https://img.shields.io/badge/chat-discussions-success.svg
[chat]: https://spectrum.chat/unified/syntax-tree
[chat]: https://github.com/syntax-tree/unist/discussions

@@ -207,9 +207,9 @@ [npm]: https://docs.npmjs.com/cli/install

[contributing]: https://github.com/syntax-tree/.github/blob/master/contributing.md
[contributing]: https://github.com/syntax-tree/.github/blob/HEAD/contributing.md
[support]: https://github.com/syntax-tree/.github/blob/master/support.md
[support]: https://github.com/syntax-tree/.github/blob/HEAD/support.md
[coc]: https://github.com/syntax-tree/.github/blob/master/code-of-conduct.md
[coc]: https://github.com/syntax-tree/.github/blob/HEAD/code-of-conduct.md
[vdom]: https://github.com/Matt-Esch/virtual-dom/tree/master/virtual-hyperscript
[vdom]: https://github.com/Matt-Esch/virtual-dom/tree/HEAD/virtual-hyperscript

@@ -216,0 +216,0 @@ [hyperscript]: https://github.com/hyperhype/hyperscript

@@ -14,3 +14,3 @@ // Minimum TypeScript Version: 3.2

name: string,
attributes: {[key: string]: any},
attributes: Record<string, any>,
children: any[]

@@ -17,0 +17,0 @@ ) => any

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc