Launch Week Day 5: Introducing Reachability for PHP.Learn More
Socket
Book a DemoSign in
Socket

h3

Package Overview
Dependencies
Maintainers
1
Versions
139
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

h3 - npm Package Compare versions

Comparing version
1.0.0
to
2.0.0
+2
-10
package.json
{
"name": "h3",
"version": "1.0.0",
"description": "A better HTMLElement constructor",
"homepage": "https://github.com/twhb/h3-js",
"bugs": "https://github.com/twhb/h3-js/issues",
"license": "ISC",
"author": "Tristan Berger <tristanberger@gmail.com>",
"repository": {
"type": "git",
"url": "https://github.com/twhb/h3-js.git"
}
"version": "2.0.0",
"description": "DEPRECATED"
}

@@ -1,38 +0,1 @@

# h3-js
A better HTMLElement constructor
## Example
```javascript
var body = h('div', 'example',
h('h1', null, 'Example'),
h('label', {htmlFor: 'task'},
h('input', {id: 'task', type: 'checkbox', checked: true}),
'Check out h3-js'
)
);
```
## API
### h(tagName, props, ...children)
Creates and returns a new HTMLElement.
Primary interface: `tagName` sets the tag name, each key-value pair of `props` is copied onto the result, and each of `children` is appended to the result.
Conveniences:
- `props.style` sets `result.style.cssText`
- If `props` is falsy then it is ignored
- If `props` is a string then it instead sets `result.className`
- Children that are falsy are ignored
- Children that are strings are converted to `Text` instances
- Children that are Arrays are flattened into `children`
## Setup
Install: `npm install h3`
Import: `const h = require('h3');`
DEPRECATED
'use strict';
var doc = document;
function h(tagName, props) {
if (typeof tagName !== 'string') {
throw Error('tagName must be a string');
}
var el = doc.createElement(tagName);
if (!props) {
// pass
} else if (typeof props === 'string') {
el.className = props;
} else if (typeof props === 'object') {
for (var key in props) {
if (key === 'style') {
el.style.cssText = props[key];
} else {
el[key] = props[key];
}
}
} else {
throw Error('props must be an object, a string, or falsy');
}
var parent = el.content || el;
for (var i = 2, len = arguments.length; i < len; i++) {
append(parent, arguments[i]);
}
return el;
}
function append(parent, child) {
if (child instanceof Node) {
parent.appendChild(child);
} else if (typeof child === 'string') {
parent.appendChild(doc.createTextNode(child));
} else if (!child) {
// pass
} else if (Array.isArray(child)) {
for (var i = 0, len = child.length; i < len; i++) {
append(parent, child[i]);
}
} else {
throw Error('children must be Nodes, strings, Arrays, or falsy');
}
}
module.exports = h;
Copyright (c) 2016, Tristan Berger <tristanberger@gmail.com>
Permission to use, copy, modify, and/or distribute this software for any purpose
with or without fee is hereby granted, provided that the above copyright notice
and this permission notice appear in all copies.
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND
FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS
OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF
THIS SOFTWARE.