hastscript
Advanced tools
Comparing version 5.0.0 to 5.0.1
@@ -14,3 +14,3 @@ 'use strict' | ||
/* Hyperscript compatible DSL for creating virtual HAST trees. */ | ||
// Hyperscript compatible DSL for creating virtual hast trees. | ||
function h(selector, properties) { | ||
@@ -47,3 +47,3 @@ var node = parseSelector(selector, defaultTagName) | ||
/* Ignore nully and NaN values. */ | ||
// Ignore nully and NaN values. | ||
if (value === null || value === undefined || value !== value) { | ||
@@ -57,3 +57,3 @@ return | ||
/* Handle list values. */ | ||
// Handle list values. | ||
if (typeof result === 'string') { | ||
@@ -69,3 +69,3 @@ if (info.spaceSeparated) { | ||
/* Accept `object` on style. */ | ||
// Accept `object` on style. | ||
if (property === 'style' && typeof value !== 'string') { | ||
@@ -75,3 +75,3 @@ result = style(result) | ||
/* Class-names (which can be added both on the `selector` and here). */ | ||
// Class-names (which can be added both on the `selector` and here). | ||
if (property === 'className' && properties.className) { | ||
@@ -145,3 +145,3 @@ result = properties.className.concat(result) | ||
/* Parse a (list of) primitives. */ | ||
// Parse a (list of) primitives. | ||
function parsePrimitives(info, name, value) { | ||
@@ -167,3 +167,3 @@ var index | ||
/* Parse a single primitives. */ | ||
// Parse a single primitives. | ||
function parsePrimitive(info, name, value) { | ||
@@ -177,3 +177,3 @@ var result = value | ||
} else if (info.boolean || info.overloadedBoolean) { | ||
/* Accept `boolean` and `string`. */ | ||
// Accept `boolean` and `string`. | ||
if ( | ||
@@ -180,0 +180,0 @@ typeof result === 'string' && |
{ | ||
"name": "hastscript", | ||
"version": "5.0.0", | ||
"description": "Hyperscript compatible DSL for creating virtual HAST trees", | ||
"version": "5.0.1", | ||
"description": "Hyperscript compatible DSL for creating virtual hast trees", | ||
"license": "MIT", | ||
@@ -36,12 +36,12 @@ "keywords": [ | ||
"browserify": "^16.0.0", | ||
"nyc": "^13.0.0", | ||
"prettier": "^1.13.5", | ||
"nyc": "^14.0.0", | ||
"prettier": "^1.0.0", | ||
"remark-cli": "^6.0.0", | ||
"remark-preset-wooorm": "^4.0.0", | ||
"remark-preset-wooorm": "^5.0.0", | ||
"tape": "^4.0.0", | ||
"tinyify": "^2.4.3", | ||
"xo": "^0.23.0" | ||
"tinyify": "^2.0.0", | ||
"xo": "^0.24.0" | ||
}, | ||
"scripts": { | ||
"format": "remark . -qfo && prettier --write '**/*.js' && xo --fix", | ||
"format": "remark . -qfo && prettier --write \"**/*.js\" && xo --fix", | ||
"build-bundle": "browserify . -s hastscript > hastscript.js", | ||
@@ -48,0 +48,0 @@ "build-mangle": "browserify . -s hastscript -p tinyify > hastscript.min.js", |
172
readme.md
@@ -1,11 +0,21 @@ | ||
# hastscript [![Build][build-badge]][build] [![Coverage][coverage-badge]][coverage] [![Downloads][downloads-badge]][downloads] [![Size][size-badge]][size] [![Chat][chat-badge]][chat] | ||
# hastscript | ||
[Hyperscript][] (and [`virtual-hyperscript`][virtual-hyperscript]) | ||
compatible DSL for creating virtual [HAST][] trees in HTML and SVG. | ||
[![Build][build-badge]][build] | ||
[![Coverage][coverage-badge]][coverage] | ||
[![Downloads][downloads-badge]][downloads] | ||
[![Size][size-badge]][size] | ||
[![Sponsors][sponsors-badge]][collective] | ||
[![Backers][backers-badge]][collective] | ||
[![Chat][chat-badge]][chat] | ||
## Installation | ||
[**hast**][hast] utility to create [*trees*][tree] in HTML or SVG. | ||
Similar to [hyperscript][] (and [`virtual-hyperscript`][virtual-hyperscript]) | ||
but for [**hast**][hast]. | ||
## Install | ||
[npm][]: | ||
```bash | ||
```sh | ||
npm install hastscript | ||
@@ -16,7 +26,7 @@ ``` | ||
```javascript | ||
```js | ||
var h = require('hastscript') | ||
var s = require('hastscript/svg') | ||
// Child nodes as an array | ||
// Children as an array: | ||
console.log( | ||
@@ -33,3 +43,3 @@ h('.foo#some-id', [ | ||
// Child nodes as arguments | ||
// Children as arguments: | ||
console.log( | ||
@@ -45,2 +55,3 @@ h( | ||
// SVG: | ||
console.log( | ||
@@ -57,48 +68,71 @@ s('svg', {xmlns: 'http://www.w3.org/2000/svg', viewbox: '0 0 500 500'}, [ | ||
```js | ||
{ type: 'element', | ||
{ | ||
type: 'element', | ||
tagName: 'div', | ||
properties: { className: [ 'foo' ], id: 'some-id' }, | ||
children: | ||
[ { type: 'element', | ||
tagName: 'span', | ||
properties: {}, | ||
children: [ { type: 'text', value: 'some text' } ] }, | ||
{ type: 'element', | ||
tagName: 'input', | ||
properties: { type: 'text', value: 'foo' }, | ||
children: [] }, | ||
{ type: 'element', | ||
tagName: 'a', | ||
properties: { className: [ 'alpha', 'bravo', 'charlie' ], download: true }, | ||
children: | ||
[ { type: 'text', value: 'delta' }, | ||
{ type: 'text', value: 'echo' } ] } ] } | ||
{ type: 'element', | ||
properties: {className: ['foo'], id: 'some-id'}, | ||
children: [ | ||
{ | ||
type: 'element', | ||
tagName: 'span', | ||
properties: {}, | ||
children: [{type: 'text', value: 'some text'}] | ||
}, | ||
{ | ||
type: 'element', | ||
tagName: 'input', | ||
properties: {type: 'text', value: 'foo'}, | ||
children: [] | ||
}, | ||
{ | ||
type: 'element', | ||
tagName: 'a', | ||
properties: {className: ['alpha', 'bravo', 'charlie'], download: true}, | ||
children: [{type: 'text', value: 'delta'}, {type: 'text', value: 'echo'}] | ||
} | ||
] | ||
} | ||
{ | ||
type: 'element', | ||
tagName: 'form', | ||
properties: { method: 'POST' }, | ||
children: | ||
[ { type: 'element', | ||
tagName: 'input', | ||
properties: { type: 'text', name: 'foo' }, | ||
children: [] }, | ||
{ type: 'element', | ||
tagName: 'input', | ||
properties: { type: 'text', name: 'bar' }, | ||
children: [] }, | ||
{ type: 'element', | ||
tagName: 'input', | ||
properties: { type: 'submit', value: 'send' }, | ||
children: [] } ] } | ||
{ type: 'element', | ||
properties: {method: 'POST'}, | ||
children: [ | ||
{ | ||
type: 'element', | ||
tagName: 'input', | ||
properties: {type: 'text', name: 'foo'}, | ||
children: [] | ||
}, | ||
{ | ||
type: 'element', | ||
tagName: 'input', | ||
properties: {type: 'text', name: 'bar'}, | ||
children: [] | ||
}, | ||
{ | ||
type: 'element', | ||
tagName: 'input', | ||
properties: {type: 'submit', value: 'send'}, | ||
children: [] | ||
} | ||
] | ||
} | ||
{ | ||
type: 'element', | ||
tagName: 'svg', | ||
properties: { xmlns: 'http://www.w3.org/2000/svg', viewBox: '0 0 500 500' }, | ||
children: | ||
[ { type: 'element', | ||
tagName: 'title', | ||
properties: {}, | ||
children: [ { type: 'text', value: 'SVG `<circle>` element' } ] }, | ||
{ type: 'element', | ||
tagName: 'circle', | ||
properties: { cx: 120, cy: 120, r: 100 }, | ||
children: [] } ] } | ||
properties: {xmlns: 'http://www.w3.org/2000/svg', viewBox: '0 0 500 500'}, | ||
children: [ | ||
{ | ||
type: 'element', | ||
tagName: 'title', | ||
properties: {}, | ||
children: [{type: 'text', value: 'SVG `<circle>` element'}] | ||
}, | ||
{ | ||
type: 'element', | ||
tagName: 'circle', | ||
properties: {cx: 120, cy: 120, r: 100}, | ||
children: [] | ||
} | ||
] | ||
} | ||
``` | ||
@@ -118,4 +152,4 @@ | ||
Simple CSS selector (`string`, optional). Can contain a tag name (`foo`), IDs | ||
(`#bar`), and classes (`.baz`). | ||
Simple CSS selector (`string`, optional). | ||
Can contain a tag name (`foo`), IDs (`#bar`), and classes (`.baz`). | ||
If there is no tag name in the selector, `h` defaults to a `div` element, | ||
@@ -131,3 +165,3 @@ and `s` to a `g` element. | ||
(Lists of) child nodes (`string`, `Node`, `Array.<string|Node>`, optional). | ||
When strings are encountered, they are normalised to [`text`][text] nodes. | ||
When strings are encountered, they are mapped to [`text`][text] nodes. | ||
@@ -140,7 +174,9 @@ ##### Returns | ||
See [`contributing.md` in `syntax-tree/hast`][contributing] for ways to get | ||
See [`contributing.md` in `syntax-tree/.github`][contributing] for ways to get | ||
started. | ||
See [`support.md`][support] for ways to get help. | ||
This organisation has a [Code of Conduct][coc]. By interacting with this | ||
repository, organisation, or community you agree to abide by its terms. | ||
This project has a [Code of Conduct][coc]. | ||
By interacting with this repository, organisation, or community you agree to | ||
abide by its terms. | ||
@@ -169,5 +205,11 @@ ## License | ||
[sponsors-badge]: https://opencollective.com/unified/sponsors/badge.svg | ||
[backers-badge]: https://opencollective.com/unified/backers/badge.svg | ||
[collective]: https://opencollective.com/unified | ||
[chat-badge]: https://img.shields.io/badge/join%20the%20community-on%20spectrum-7b16ff.svg | ||
[chat]: https://spectrum.chat/unified/rehype | ||
[chat]: https://spectrum.chat/unified/syntax-tree | ||
@@ -180,6 +222,8 @@ [npm]: https://docs.npmjs.com/cli/install | ||
[hast]: https://github.com/syntax-tree/hast | ||
[contributing]: https://github.com/syntax-tree/.github/blob/master/contributing.md | ||
[element]: https://github.com/syntax-tree/hast#element | ||
[support]: https://github.com/syntax-tree/.github/blob/master/support.md | ||
[coc]: https://github.com/syntax-tree/.github/blob/master/code-of-conduct.md | ||
[virtual-hyperscript]: https://github.com/Matt-Esch/virtual-dom/tree/master/virtual-hyperscript | ||
@@ -189,6 +233,8 @@ | ||
[text]: https://github.com/syntax-tree/unist#text | ||
[tree]: https://github.com/syntax-tree/unist#tree | ||
[contributing]: https://github.com/syntax-tree/hast/blob/master/contributing.md | ||
[hast]: https://github.com/syntax-tree/hast | ||
[coc]: https://github.com/syntax-tree/hast/blob/master/code-of-conduct.md | ||
[element]: https://github.com/syntax-tree/hast#element | ||
[text]: https://github.com/syntax-tree/hast#text |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
13081
231