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

hastscript

Package Overview
Dependencies
Maintainers
2
Versions
21
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

hastscript - npm Package Compare versions

Comparing version 8.0.0 to 9.0.0

index.d.ts.map

1

index.d.ts

@@ -5,1 +5,2 @@ export type Child = import('./lib/index.js').Child;

export { h, s } from "./lib/index.js";
//# sourceMappingURL=index.d.ts.map
export * from "./jsx-automatic.js";
export const Fragment: null;
export const jsx: {
/**
* @overload
* @param {null} type
* @param {{children?: Child}} props
* @param {string} [key]
* @returns {Root}
*
* @overload
* @param {string} type
* @param {JSXProps} props
* @param {string} [key]
* @returns {Element}
*
* @param {string | null} type
* Element name or `null` to get a root.
* @param {Properties & {children?: Child}} props
* Properties.
* @returns {Result}
* Result.
*/
(type: null, props: {
children?: import("./create-h.js").Child;
}, key?: string | undefined): import("hast").Root;
/**
* @overload
* @param {null} type
* @param {{children?: Child}} props
* @param {string} [key]
* @returns {Root}
*
* @overload
* @param {string} type
* @param {JSXProps} props
* @param {string} [key]
* @returns {Element}
*
* @param {string | null} type
* Element name or `null` to get a root.
* @param {Properties & {children?: Child}} props
* Properties.
* @returns {Result}
* Result.
*/
(type: string, props: import("./create-automatic-runtime.js").JSXProps, key?: string | undefined): import("hast").Element;
};
export const jsxDEV: {
/**
* @overload
* @param {null} type
* @param {{children?: Child}} props
* @param {string} [key]
* @returns {Root}
*
* @overload
* @param {string} type
* @param {JSXProps} props
* @param {string} [key]
* @returns {Element}
*
* @param {string | null} type
* Element name or `null` to get a root.
* @param {Properties & {children?: Child}} props
* Properties.
* @returns {Result}
* Result.
*/
(type: null, props: {
children?: import("./create-h.js").Child;
}, key?: string | undefined): import("hast").Root;
/**
* @overload
* @param {null} type
* @param {{children?: Child}} props
* @param {string} [key]
* @returns {Root}
*
* @overload
* @param {string} type
* @param {JSXProps} props
* @param {string} [key]
* @returns {Element}
*
* @param {string | null} type
* Element name or `null` to get a root.
* @param {Properties & {children?: Child}} props
* Properties.
* @returns {Result}
* Result.
*/
(type: string, props: import("./create-automatic-runtime.js").JSXProps, key?: string | undefined): import("hast").Element;
};
export const jsxs: {
/**
* @overload
* @param {null} type
* @param {{children?: Child}} props
* @param {string} [key]
* @returns {Root}
*
* @overload
* @param {string} type
* @param {JSXProps} props
* @param {string} [key]
* @returns {Element}
*
* @param {string | null} type
* Element name or `null` to get a root.
* @param {Properties & {children?: Child}} props
* Properties.
* @returns {Result}
* Result.
*/
(type: null, props: {
children?: import("./create-h.js").Child;
}, key?: string | undefined): import("hast").Root;
/**
* @overload
* @param {null} type
* @param {{children?: Child}} props
* @param {string} [key]
* @returns {Root}
*
* @overload
* @param {string} type
* @param {JSXProps} props
* @param {string} [key]
* @returns {Element}
*
* @param {string | null} type
* Element name or `null` to get a root.
* @param {Properties & {children?: Child}} props
* Properties.
* @returns {Result}
* Result.
*/
(type: string, props: import("./create-automatic-runtime.js").JSXProps, key?: string | undefined): import("hast").Element;
};
//# sourceMappingURL=automatic-runtime-html.d.ts.map
export * from "./jsx-automatic.js";
export const Fragment: null;
export const jsx: {
/**
* @overload
* @param {null} type
* @param {{children?: Child}} props
* @param {string} [key]
* @returns {Root}
*
* @overload
* @param {string} type
* @param {JSXProps} props
* @param {string} [key]
* @returns {Element}
*
* @param {string | null} type
* Element name or `null` to get a root.
* @param {Properties & {children?: Child}} props
* Properties.
* @returns {Result}
* Result.
*/
(type: null, props: {
children?: import("./create-h.js").Child;
}, key?: string | undefined): import("hast").Root;
/**
* @overload
* @param {null} type
* @param {{children?: Child}} props
* @param {string} [key]
* @returns {Root}
*
* @overload
* @param {string} type
* @param {JSXProps} props
* @param {string} [key]
* @returns {Element}
*
* @param {string | null} type
* Element name or `null` to get a root.
* @param {Properties & {children?: Child}} props
* Properties.
* @returns {Result}
* Result.
*/
(type: string, props: import("./create-automatic-runtime.js").JSXProps, key?: string | undefined): import("hast").Element;
};
export const jsxDEV: {
/**
* @overload
* @param {null} type
* @param {{children?: Child}} props
* @param {string} [key]
* @returns {Root}
*
* @overload
* @param {string} type
* @param {JSXProps} props
* @param {string} [key]
* @returns {Element}
*
* @param {string | null} type
* Element name or `null` to get a root.
* @param {Properties & {children?: Child}} props
* Properties.
* @returns {Result}
* Result.
*/
(type: null, props: {
children?: import("./create-h.js").Child;
}, key?: string | undefined): import("hast").Root;
/**
* @overload
* @param {null} type
* @param {{children?: Child}} props
* @param {string} [key]
* @returns {Root}
*
* @overload
* @param {string} type
* @param {JSXProps} props
* @param {string} [key]
* @returns {Element}
*
* @param {string | null} type
* Element name or `null` to get a root.
* @param {Properties & {children?: Child}} props
* Properties.
* @returns {Result}
* Result.
*/
(type: string, props: import("./create-automatic-runtime.js").JSXProps, key?: string | undefined): import("hast").Element;
};
export const jsxs: {
/**
* @overload
* @param {null} type
* @param {{children?: Child}} props
* @param {string} [key]
* @returns {Root}
*
* @overload
* @param {string} type
* @param {JSXProps} props
* @param {string} [key]
* @returns {Element}
*
* @param {string | null} type
* Element name or `null` to get a root.
* @param {Properties & {children?: Child}} props
* Properties.
* @returns {Result}
* Result.
*/
(type: null, props: {
children?: import("./create-h.js").Child;
}, key?: string | undefined): import("hast").Root;
/**
* @overload
* @param {null} type
* @param {{children?: Child}} props
* @param {string} [key]
* @returns {Root}
*
* @overload
* @param {string} type
* @param {JSXProps} props
* @param {string} [key]
* @returns {Element}
*
* @param {string | null} type
* Element name or `null` to get a root.
* @param {Properties & {children?: Child}} props
* Properties.
* @returns {Result}
* Result.
*/
(type: string, props: import("./create-automatic-runtime.js").JSXProps, key?: string | undefined): import("hast").Element;
};
//# sourceMappingURL=automatic-runtime-svg.d.ts.map

@@ -12,17 +12,137 @@ /**

jsx: {
/**
* @overload
* @param {null} type
* @param {{children?: Child}} props
* @param {string} [key]
* @returns {Root}
*
* @overload
* @param {string} type
* @param {JSXProps} props
* @param {string} [key]
* @returns {Element}
*
* @param {string | null} type
* Element name or `null` to get a root.
* @param {Properties & {children?: Child}} props
* Properties.
* @returns {Result}
* Result.
*/
(type: null, props: {
children?: Child;
}, key?: string | undefined): Root;
/**
* @overload
* @param {null} type
* @param {{children?: Child}} props
* @param {string} [key]
* @returns {Root}
*
* @overload
* @param {string} type
* @param {JSXProps} props
* @param {string} [key]
* @returns {Element}
*
* @param {string | null} type
* Element name or `null` to get a root.
* @param {Properties & {children?: Child}} props
* Properties.
* @returns {Result}
* Result.
*/
(type: string, props: JSXProps, key?: string | undefined): Element;
};
jsxDEV: {
/**
* @overload
* @param {null} type
* @param {{children?: Child}} props
* @param {string} [key]
* @returns {Root}
*
* @overload
* @param {string} type
* @param {JSXProps} props
* @param {string} [key]
* @returns {Element}
*
* @param {string | null} type
* Element name or `null` to get a root.
* @param {Properties & {children?: Child}} props
* Properties.
* @returns {Result}
* Result.
*/
(type: null, props: {
children?: Child;
}, key?: string | undefined): Root;
/**
* @overload
* @param {null} type
* @param {{children?: Child}} props
* @param {string} [key]
* @returns {Root}
*
* @overload
* @param {string} type
* @param {JSXProps} props
* @param {string} [key]
* @returns {Element}
*
* @param {string | null} type
* Element name or `null` to get a root.
* @param {Properties & {children?: Child}} props
* Properties.
* @returns {Result}
* Result.
*/
(type: string, props: JSXProps, key?: string | undefined): Element;
};
jsxs: {
/**
* @overload
* @param {null} type
* @param {{children?: Child}} props
* @param {string} [key]
* @returns {Root}
*
* @overload
* @param {string} type
* @param {JSXProps} props
* @param {string} [key]
* @returns {Element}
*
* @param {string | null} type
* Element name or `null` to get a root.
* @param {Properties & {children?: Child}} props
* Properties.
* @returns {Result}
* Result.
*/
(type: null, props: {
children?: Child;
}, key?: string | undefined): Root;
/**
* @overload
* @param {null} type
* @param {{children?: Child}} props
* @param {string} [key]
* @returns {Root}
*
* @overload
* @param {string} type
* @param {JSXProps} props
* @param {string} [key]
* @returns {Element}
*
* @param {string | null} type
* Element name or `null` to get a root.
* @param {Properties & {children?: Child}} props
* Properties.
* @returns {Result}
* Result.
*/
(type: string, props: JSXProps, key?: string | undefined): Element;

@@ -40,1 +160,2 @@ };

export type JSXProps = Record<string, Child | PropertyValue | Style>;
//# sourceMappingURL=create-automatic-runtime.d.ts.map

@@ -12,4 +12,88 @@ /**

export function createH(schema: Schema, defaultTagName: string, caseSensitive?: Array<string> | undefined): {
/**
* Hyperscript compatible DSL for creating virtual hast trees.
*
* @overload
* @param {null | undefined} [selector]
* @param {...Child} children
* @returns {Root}
*
* @overload
* @param {string} selector
* @param {Properties} properties
* @param {...Child} children
* @returns {Element}
*
* @overload
* @param {string} selector
* @param {...Child} children
* @returns {Element}
*
* @param {string | null | undefined} [selector]
* Selector.
* @param {Child | Properties | null | undefined} [properties]
* Properties (or first child) (default: `undefined`).
* @param {...Child} children
* Children.
* @returns {Result}
* Result.
*/
(selector?: null | undefined, ...children: Child[]): Root;
/**
* Hyperscript compatible DSL for creating virtual hast trees.
*
* @overload
* @param {null | undefined} [selector]
* @param {...Child} children
* @returns {Root}
*
* @overload
* @param {string} selector
* @param {Properties} properties
* @param {...Child} children
* @returns {Element}
*
* @overload
* @param {string} selector
* @param {...Child} children
* @returns {Element}
*
* @param {string | null | undefined} [selector]
* Selector.
* @param {Child | Properties | null | undefined} [properties]
* Properties (or first child) (default: `undefined`).
* @param {...Child} children
* Children.
* @returns {Result}
* Result.
*/
(selector: string, properties: Properties, ...children: Child[]): Element;
/**
* Hyperscript compatible DSL for creating virtual hast trees.
*
* @overload
* @param {null | undefined} [selector]
* @param {...Child} children
* @returns {Root}
*
* @overload
* @param {string} selector
* @param {Properties} properties
* @param {...Child} children
* @returns {Element}
*
* @overload
* @param {string} selector
* @param {...Child} children
* @returns {Element}
*
* @param {string | null | undefined} [selector]
* Selector.
* @param {Child | Properties | null | undefined} [properties]
* Properties (or first child) (default: `undefined`).
* @param {...Child} children
* Children.
* @returns {Result}
* Result.
*/
(selector: string, ...children: Child[]): Element;

@@ -69,1 +153,2 @@ };

export type Child = (import("hast").Nodes | PrimitiveChild | ArrayChildNested)[] | Nodes | PrimitiveChild;
//# sourceMappingURL=create-h.d.ts.map

62

lib/create-h.js

@@ -43,4 +43,2 @@ /**

const buttonTypes = new Set(['button', 'menu', 'reset', 'submit'])
const own = {}.hasOwnProperty

@@ -108,3 +106,5 @@

// Handle props.
if (isProperties(properties, node.tagName)) {
if (isChild(properties)) {
children.unshift(properties)
} else {
/** @type {string} */

@@ -118,4 +118,2 @@ let key

}
} else {
children.unshift(properties)
}

@@ -145,30 +143,44 @@ }

* Value to check.
* @param {string} name
* Tag name.
* @returns {value is Properties}
* Whether `value` is a properties object.
* @returns {value is Child}
* Whether `value` is definitely a child.
*/
function isProperties(value, name) {
if (
value === null ||
value === undefined ||
typeof value !== 'object' ||
Array.isArray(value)
) {
return false
function isChild(value) {
// Never properties if not an object.
if (value === null || typeof value !== 'object' || Array.isArray(value)) {
return true
}
if (name === 'input' || !value.type || typeof value.type !== 'string') {
return true
// Never node without `type`; that’s the main discriminator.
if (typeof value.type !== 'string') return false
// Slower check: never property value if object or array with
// non-number/strings.
const record = /** @type {Record<string, unknown>} */ (value)
const keys = Object.keys(value)
for (const key of keys) {
const value = record[key]
if (value && typeof value === 'object') {
if (!Array.isArray(value)) return true
const list = /** @type {Array<unknown>} */ (value)
for (const item of list) {
if (typeof item !== 'number' && typeof item !== 'string') {
return true
}
}
}
}
// Also see empty `children` as a node.
if ('children' in value && Array.isArray(value.children)) {
return false
return true
}
if (name === 'button') {
return buttonTypes.has(value.type.toLowerCase())
}
return !('value' in value)
// Default to properties, someone can always pass an empty object,
// put `data: {}` in a node,
// or wrap it in an array.
return false
}

@@ -175,0 +187,0 @@

@@ -34,1 +34,2 @@ /** @type {ReturnType<createH>} */

import { createH } from './create-h.js';
//# sourceMappingURL=index.d.ts.map
export const svgCaseSensitiveTagNames: string[];
//# sourceMappingURL=svg-case-sensitive-tag-names.d.ts.map
{
"name": "hastscript",
"version": "8.0.0",
"version": "9.0.0",
"description": "hast utility to create trees",

@@ -43,2 +43,3 @@ "license": "MIT",

"lib/",
"index.d.ts.map",
"index.d.ts",

@@ -57,3 +58,3 @@ "index.js"

"acorn-jsx": "^5.0.0",
"c8": "^8.0.0",
"c8": "^9.0.0",
"esast-util-from-js": "^2.0.0",

@@ -66,7 +67,7 @@ "estree-util-build-jsx": "^3.0.0",

"svg-tag-names": "^3.0.0",
"tsd": "^0.28.0",
"tsd": "^0.30.0",
"type-coverage": "^2.0.0",
"typescript": "^5.0.0",
"unist-builder": "^4.0.0",
"xo": "^0.55.0"
"xo": "^0.56.0"
},

@@ -73,0 +74,0 @@ "scripts": {

@@ -63,3 +63,3 @@ # hastscript

```js
import {h} from 'https://esm.sh/hastscript@8'
import {h} from 'https://esm.sh/hastscript@9'
```

@@ -71,3 +71,3 @@

<script type="module">
import {h} from 'https://esm.sh/hastscript@8?bundle'
import {h} from 'https://esm.sh/hastscript@9?bundle'
</script>

@@ -318,3 +318,3 @@ ```

Node.
This means we try to keep the current release line, `hastscript@^8`,
This means we try to keep the current release line, `hastscript@^9`,
compatible with Node.js 16.

@@ -321,0 +321,0 @@

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