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 10.0.0 to 10.0.1

12

index.d.ts

@@ -11,3 +11,3 @@ /**

tree: Element | Root,
options?: string | boolean | Options
options?: string | boolean | Options | undefined
): ReturnType<H>

@@ -22,6 +22,4 @@ export type Element = import('hast').Element

name: string,
attributes?: {
[x: string]: any
},
children?: Array<string | any>
attributes: any,
children?: any[] | undefined
) => any

@@ -40,4 +38,4 @@ export type Context = {

export type Options = {
prefix?: string | null
space?: 'html' | 'svg'
prefix?: string | null | undefined
space?: 'html' | 'svg' | undefined
}

@@ -12,3 +12,3 @@ /**

* @param {string} name
* @param {Object<string, any>} [attributes]
* @param {any} attributes
* @param {Array.<string|any>} [children]

@@ -35,16 +35,19 @@ * @returns {any}

import style from 'style-to-object'
import {webNamespaces as ns} from 'web-namespaces'
import {webNamespaces} from 'web-namespaces'
import {convert} from 'unist-util-is'
var own = {}.hasOwnProperty
const ns = /** @type {Record<string, string>} */ (webNamespaces)
const toReact = /** @type {Record<string, string>} */ (hastToReact)
const own = {}.hasOwnProperty
/** @type {AssertRoot} */
// @ts-ignore it’s correct.
var root = convert('root')
// @ts-expect-error it’s correct.
const root = convert('root')
/** @type {AssertElement} */
// @ts-ignore it’s correct.
var element = convert('element')
// @ts-expect-error it’s correct.
const element = convert('element')
/** @type {AssertText} */
// @ts-ignore it’s correct.
var text = convert('text')
// @ts-expect-error it’s correct.
const text = convert('text')

@@ -63,9 +66,9 @@ /**

var r = react(h)
var v = vue(h)
var vd = vdom(h)
/** @type {string|boolean} */
var prefix
const r = react(h)
const v = vue(h)
const vd = vdom(h)
/** @type {string|boolean|null|undefined} */
let prefix
/** @type {Element} */
var node
let node

@@ -81,3 +84,3 @@ if (typeof options === 'string' || typeof options === 'boolean') {

if (root(tree)) {
// @ts-ignore Allow `doctypes` in there, we’ll filter them out later.
// @ts-expect-error Allow `doctypes` in there, we’ll filter them out later.
node =

@@ -96,3 +99,3 @@ tree.children.length === 1 && element(tree.children[0])

throw new Error(
// @ts-ignore runtime.
// @ts-expect-error runtime.
'Expected root or element, not `' + ((tree && tree.type) || tree) + '`'

@@ -131,14 +134,12 @@ )

function transform(h, node, ctx) {
var parentSchema = ctx.schema
var schema = parentSchema
var name = node.tagName
/** @type {Object.<string, unknown>} */
var attributes = {}
const parentSchema = ctx.schema
let schema = parentSchema
let name = node.tagName
/** @type {Record<string, unknown>} */
const attributes = {}
/** @type {Array.<ReturnType<H>|string>} */
var nodes = []
var index = -1
const nodes = []
let index = -1
/** @type {string} */
var key
/** @type {Element['children'][number]} */
var value
let key

@@ -151,3 +152,3 @@ if (parentSchema.space === 'html' && name.toLowerCase() === 'svg') {

for (key in node.properties) {
if (own.call(node.properties, key)) {
if (node.properties && own.call(node.properties, key)) {
addAttribute(attributes, key, node.properties[key], ctx, name)

@@ -160,3 +161,3 @@ }

name = name.toUpperCase()
} else {
} else if (schema.space) {
attributes.namespace = ns[schema.space]

@@ -173,3 +174,3 @@ }

while (++index < node.children.length) {
value = node.children[index]
const value = node.children[index]

@@ -195,3 +196,3 @@ if (element(value)) {

/**
* @param {Object.<string, unknown>} props
* @param {Record<string, unknown>} props
* @param {string} prop

@@ -204,5 +205,5 @@ * @param {unknown} value

function addAttribute(props, prop, value, ctx, name) {
var info = find(ctx.schema, prop)
/** @type {string} */
var subprop
const info = find(ctx.schema, prop)
/** @type {string|undefined} */
let subprop

@@ -252,6 +253,7 @@ // Ignore nullish and `NaN` values.

if (subprop) {
if (!props[subprop]) props[subprop] = {}
props[subprop][info.attribute] = value
props[subprop] = Object.assign(props[subprop] || {}, {
[info.attribute]: value
})
} else if (info.space && ctx.react) {
props[hastToReact[info.property] || info.property] = value
props[toReact[info.property] || info.property] = value
} else {

@@ -270,8 +272,8 @@ props[info.attribute] = value

/** @type {unknown} */
var node = h('div')
const node = h('div', {})
return Boolean(
node &&
// @ts-ignore Looks like a React node.
// @ts-expect-error Looks like a React node.
('_owner' in node || '_store' in node) &&
// @ts-ignore Looks like a React node.
// @ts-expect-error Looks like a React node.
(node.key === undefined || node.key === null)

@@ -299,4 +301,4 @@ )

/** @type {unknown} */
var node = h('div')
// @ts-ignore Looks like a vnode.
const node = h('div', {})
// @ts-expect-error Looks like a vnode.
return node.type === 'VirtualNode'

@@ -313,4 +315,4 @@ }

/** @type {unknown} */
var node = h('div')
// @ts-ignore Looks like a Vue node.
const node = h('div', {})
// @ts-expect-error Looks like a Vue node.
return Boolean(node && node.context && node.context._isVue)

@@ -322,10 +324,23 @@ }

* @param {string} tagName
* @returns {Object.<string, string>}
* @returns {Record<string, string>}
*/
function parseStyle(value, tagName) {
/** @type {Object.<string, string>} */
var result = {}
/** @type {Record<string, string>} */
const result = {}
try {
style(value, iterator)
style(value, (name, value) => {
if (name.slice(0, 4) === '-ms-') name = 'ms-' + name.slice(4)
result[
name.replace(
/-([a-z])/g,
/**
* @param {string} _
* @param {string} $1
* @returns {string}
*/ (_, $1) => $1.toUpperCase()
)
] = value
})
} catch (error) {

@@ -338,21 +353,2 @@ error.message =

return result
/**
* @param {string} name
* @param {string} value
* @returns {void}
*/
function iterator(name, value) {
if (name.slice(0, 4) === '-ms-') name = 'ms-' + name.slice(4)
result[name.replace(/-([a-z])/g, styleReplacer)] = value
}
}
/**
* @param {string} _
* @param {string} $1
* @returns {string}
*/
function styleReplacer(_, $1) {
return $1.toUpperCase()
}
{
"name": "hast-to-hyperscript",
"version": "10.0.0",
"version": "10.0.1",
"description": "hast utility to transform to something else (react, vue, etc) through a hyperscript DSL",

@@ -75,3 +75,3 @@ "license": "MIT",

"vue-server-renderer": "^2.0.0",
"xo": "^0.39.0"
"xo": "^0.42.0"
},

@@ -95,7 +95,3 @@ "scripts": {

"xo": {
"prettier": true,
"rules": {
"no-var": "off",
"prefer-arrow-callback": "off"
}
"prettier": true
},

@@ -102,0 +98,0 @@ "remarkConfig": {

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

var tree = {
const tree = {
type: 'element',

@@ -49,3 +49,3 @@ tagName: 'p',

// Transform (`hyperscript` needs `outerHTML` to serialize):
var doc = toH(h, tree).outerHTML
const doc = toH(h, tree).outerHTML

@@ -52,0 +52,0 @@ console.log(doc)

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