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

typed-dom

Package Overview
Dependencies
Maintainers
1
Versions
350
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

typed-dom - npm Package Compare versions

Comparing version 0.0.13 to 0.0.14

16

dist/typed-dom.js

@@ -1,2 +0,2 @@

/*! typed-dom v0.0.13 https://github.com/falsandtru/typed-dom | (c) 2016, falsandtru | MIT License */
/*! typed-dom v0.0.14 https://github.com/falsandtru/typed-dom | (c) 2016, falsandtru | MIT License */
require = function e(t, n, r) {

@@ -50,3 +50,3 @@ function s(o, u) {

void Object.keys(contents).forEach(function (k) {
return void raw.appendChild(contents[k].raw);
return void raw.appendChild(contents[k].raw || document.createTextNode(contents[k]));
});

@@ -68,7 +68,11 @@ contents = Array.isArray(contents) ? Object.freeze(contents) : observe(contents);

return os;
}, contents.slice()).forEach(function (a) {
return void a.raw.remove();
}, contents.slice()).map(function (a) {
return a.raw || document.createTextNode(a);
}).forEach(function (a) {
return void a.remove();
});
void cs.forEach(function (c) {
return void raw.appendChild(c.raw);
void cs.map(function (a) {
return a.raw || document.createTextNode(a);
}).forEach(function (c) {
return void raw.appendChild(c);
});

@@ -75,0 +79,0 @@ } else {

@@ -1,2 +0,2 @@

/*! typed-dom v0.0.13 https://github.com/falsandtru/typed-dom | (c) 2016, falsandtru | MIT License */
require=function e(r,t,n){function o(u,a){if(!t[u]){if(!r[u]){var c="function"==typeof require&&require;if(!a&&c)return c(u,!0);if(i)return i(u,!0);var d=new Error("Cannot find module '"+u+"'");throw d.code="MODULE_NOT_FOUND",d}var f=t[u]={exports:{}};r[u][0].call(f.exports,function(e){var t=r[u][1][e];return o(t?t:e)},f,f.exports,e,r,t,n)}return t[u].exports}for(var i="function"==typeof require&&require,u=0;u<n.length;u++)o(n[u]);return o}({1:[function(e,r,t){},{}],2:[function(e,r,t){arguments[4][1][0].apply(t,arguments)},{dup:1}],3:[function(e,r,t){"use strict";function n(e,r,t){function n(e){var r={};return Object.keys(e).reduce(function(e,t){return r[t]=e[t],Object.defineProperty(e,t,{get:function(){return r[t]},set:function(e){var n=r[t];r[t]=e,o.replaceChild(e.raw,n.raw)}}),e},e)}void 0===t&&(t=[]);var o=e();return void Object.keys(r).forEach(function(e){return o.setAttribute(e,r[e]||"")}),void Object.keys(t).forEach(function(e){return void o.appendChild(t[e].raw)}),t=Array.isArray(t)?Object.freeze(t):n(t),Object.freeze({raw:o,get contents(){return t},set contents(e){Array.isArray(t)?(e=Object.freeze(e),void e.reduce(function(e,r){var t=e.indexOf(r);return t===-1?e:(void e.splice(t,1),e)},t.slice()).forEach(function(e){return void e.raw.remove()}),void e.forEach(function(e){return void o.appendChild(e.raw)})):(void Object.keys(e).forEach(function(r){return void o.replaceChild(e[r].raw,t[r].raw)}),e=n(e)),t=e}})}t.build=n},{}],4:[function(e,r,t){"use strict";var n=e("./builder");t.TypedHTML=["a","abbr","acronym","address","applet","area","article","aside","audio","b","base","basefont","bdo","big","blockquote","body","br","button","canvas","caption","center","cite","code","col","colgroup","datalist","dd","del","dfn","dir","div","dl","dt","em","embed","fieldset","figcaption","figure","font","footer","form","frame","frameset","h1","h2","h3","h4","h5","h6","head","header","hgroup","hr","html","i","iframe","img","input","ins","isindex","kbd","keygen","label","legend","li","link","listing","map","mark","marquee","menu","meta","nav","nextid","nobr","noframes","noscript","object","ol","optgroup","option","p","param","picture","plaintext","pre","progress","q","rt","ruby","s","samp","script","section","select","small","source","span","strike","strong","style","sub","sup","table","tbody","td","template","textarea","tfoot","th","thead","title","tr","track","tt","u","ul","var","video","wbr","xmp","custom"].reduce(function(e,r){return e[r]=function(e,t,o){return t&&"function"!=typeof t||(o=t,t=e,e={}),n.build(o||function(){return document.createElement(r)},e,t)},e},{})},{"./builder":3}],5:[function(e,r,t){"use strict";var n=e("./dom/html");t.default=n.TypedHTML},{"./dom/html":4}],6:[function(e,r,t){arguments[4][1][0].apply(t,arguments)},{dup:1}],"typed-dom":[function(e,r,t){"use strict";function n(e){for(var r in e)t.hasOwnProperty(r)||(t[r]=e[r])}n(e("./src/export"));var o=e("./src/export");t.default=o.default,t.__esModule=!0},{"./src/export":5}]},{},[1,2,6,"typed-dom"]);
/*! typed-dom v0.0.14 https://github.com/falsandtru/typed-dom | (c) 2016, falsandtru | MIT License */
require=function e(t,r,n){function o(u,c){if(!r[u]){if(!t[u]){var a="function"==typeof require&&require;if(!c&&a)return a(u,!0);if(i)return i(u,!0);var d=new Error("Cannot find module '"+u+"'");throw d.code="MODULE_NOT_FOUND",d}var f=r[u]={exports:{}};t[u][0].call(f.exports,function(e){var r=t[u][1][e];return o(r?r:e)},f,f.exports,e,t,r,n)}return r[u].exports}for(var i="function"==typeof require&&require,u=0;u<n.length;u++)o(n[u]);return o}({1:[function(e,t,r){},{}],2:[function(e,t,r){arguments[4][1][0].apply(r,arguments)},{dup:1}],3:[function(e,t,r){"use strict";function n(e,t,r){function n(e){var t={};return Object.keys(e).reduce(function(e,r){return t[r]=e[r],Object.defineProperty(e,r,{get:function(){return t[r]},set:function(e){var n=t[r];t[r]=e,o.replaceChild(e.raw,n.raw)}}),e},e)}void 0===r&&(r=[]);var o=e();return void Object.keys(t).forEach(function(e){return o.setAttribute(e,t[e]||"")}),void Object.keys(r).forEach(function(e){return void o.appendChild(r[e].raw||document.createTextNode(r[e]))}),r=Array.isArray(r)?Object.freeze(r):n(r),Object.freeze({raw:o,get contents(){return r},set contents(e){Array.isArray(r)?(e=Object.freeze(e),void e.reduce(function(e,t){var r=e.indexOf(t);return r===-1?e:(void e.splice(r,1),e)},r.slice()).map(function(e){return e.raw||document.createTextNode(e)}).forEach(function(e){return void e.remove()}),void e.map(function(e){return e.raw||document.createTextNode(e)}).forEach(function(e){return void o.appendChild(e)})):(void Object.keys(e).forEach(function(t){return void o.replaceChild(e[t].raw,r[t].raw)}),e=n(e)),r=e}})}r.build=n},{}],4:[function(e,t,r){"use strict";var n=e("./builder");r.TypedHTML=["a","abbr","acronym","address","applet","area","article","aside","audio","b","base","basefont","bdo","big","blockquote","body","br","button","canvas","caption","center","cite","code","col","colgroup","datalist","dd","del","dfn","dir","div","dl","dt","em","embed","fieldset","figcaption","figure","font","footer","form","frame","frameset","h1","h2","h3","h4","h5","h6","head","header","hgroup","hr","html","i","iframe","img","input","ins","isindex","kbd","keygen","label","legend","li","link","listing","map","mark","marquee","menu","meta","nav","nextid","nobr","noframes","noscript","object","ol","optgroup","option","p","param","picture","plaintext","pre","progress","q","rt","ruby","s","samp","script","section","select","small","source","span","strike","strong","style","sub","sup","table","tbody","td","template","textarea","tfoot","th","thead","title","tr","track","tt","u","ul","var","video","wbr","xmp","custom"].reduce(function(e,t){return e[t]=function(e,r,o){return r&&"function"!=typeof r||(o=r,r=e,e={}),n.build(o||function(){return document.createElement(t)},e,r)},e},{})},{"./builder":3}],5:[function(e,t,r){"use strict";var n=e("./dom/html");r.default=n.TypedHTML},{"./dom/html":4}],6:[function(e,t,r){arguments[4][1][0].apply(r,arguments)},{dup:1}],"typed-dom":[function(e,t,r){"use strict";function n(e){for(var t in e)r.hasOwnProperty(t)||(r[t]=e[t])}n(e("./src/export"));var o=e("./src/export");r.default=o.default,r.__esModule=!0},{"./src/export":5}]},{},[1,2,6,"typed-dom"]);
{
"name": "typed-dom",
"version": "0.0.13",
"version": "0.0.14",
"description": "Static typed html dom builder.",

@@ -5,0 +5,0 @@ "private": false,

@@ -10,10 +10,15 @@ # typed-dom

const struct = TypedHTML.div({
title: TypedHTML.h1(),
list: TypedHTML.ul([TypedHTML.li()])
const component = TypedHTML.article({
title: TypedHTML.h1(['title']),
content: TypedHTML.ul([
TypedHTML.li(['item']),
TypedHTML.li(['item']),
])
});
assert(struct.raw.nodeName === 'DIV');
assert(struct.contents.title.raw.nodeName === 'H1');
assert(struct.contents.list.raw.nodeName === 'UL');
assert(struct.contents.list.contents[0].raw.nodeName === 'LI');
assert(component.raw.nodeName === 'ARTICLE');
assert(component.raw.outerHTML === '<article><h1>title</h1><ul><li>item</li><li>item</li></ul></article>');
assert(component.contents.title.raw.nodeName === 'H1');
assert(component.contents.title.raw.outerHTML === '<h1>title</h1>');
assert(component.contents.content.raw.nodeName === 'UL');
assert(component.contents.content.raw.outerHTML === '<ul><li>item</li><li>item</li></ul>');
```

@@ -11,3 +11,3 @@ import { TypedHTML, TypedHTMLContents } from 'typed-dom';

void Object.keys(contents)
.forEach(k => void raw.appendChild(contents[k].raw));
.forEach(k => void raw.appendChild(contents[k].raw || document.createTextNode(contents[k])));
contents = Array.isArray(contents)

@@ -25,4 +25,4 @@ // https://github.com/Microsoft/TypeScript/issues/8563

cs = Object.freeze(cs);
void (<TypedHTML<string, T, any>[]>cs)
.reduce<TypedHTML<string, T, any>[]>((os, n) => {
void (<Array<TypedHTML<string, T, any> | string>>cs)
.reduce<Array<TypedHTML<string, T, any> | string>>((os, n) => {
const i = os.indexOf(n);

@@ -33,6 +33,8 @@ if (i === -1) return os;

}, contents.slice())
.map(a => (<TypedHTML<string, T, any>>a).raw || document.createTextNode(<string>a))
.forEach(a =>
void a.raw.remove());
void (<TypedHTML<string, T, any>[]>cs)
.forEach(c => void raw.appendChild(c.raw));
void a.remove());
void (<Array<TypedHTML<string, T, any> | string>>cs)
.map(a => (<TypedHTML<string, T, any>>a).raw || document.createTextNode(<string>a))
.forEach(c => void raw.appendChild(c));
}

@@ -39,0 +41,0 @@ else {

@@ -10,7 +10,2 @@ import { Sequence } from 'spica';

describe('spec', function () {
function text<T extends { raw: HTMLElement; }>(el: T, str: string): T {
el.raw.textContent = str;
return el;
}
it('attr with array', function () {

@@ -52,9 +47,7 @@ const dom = TypedHTML.script({ id: 'test', src: './' }, []);

const struct = TypedHTML.article({
title: TypedHTML.h1(),
title: TypedHTML.h1(['<text>']),
content: TypedHTML.p([TypedHTML.a()])
});
assert(struct.raw.nodeName === 'ARTICLE');
assert(struct.contents.title.raw.nodeName === 'H1');
assert(struct.raw.outerHTML === '<article><h1>&lt;text&gt;</h1><p><a></a></p></article>');
assert(struct.contents.title.raw === struct.raw.firstChild);
assert(struct.contents.content.raw.nodeName === 'P');
assert(struct.contents.content.raw === struct.raw.lastChild);

@@ -65,6 +58,6 @@ });

const struct = TypedHTML.article({
title: text(TypedHTML.h1(), 'a')
title: TypedHTML.h1(['a'])
});
struct.contents = {
title: text(TypedHTML.h1(), 'b')
title: TypedHTML.h1(['b'])
};

@@ -77,5 +70,5 @@ assert(struct.contents.title.raw.textContent === 'b');

const struct = TypedHTML.article({
title: text(TypedHTML.h1(), 'a')
title: TypedHTML.h1(['a'])
});
struct.contents.title = text(TypedHTML.h1(), 'b');
struct.contents.title = TypedHTML.h1(['b']);
assert(struct.contents.title.raw.textContent === 'b');

@@ -87,12 +80,9 @@ assert(struct.contents.title.raw === struct.raw.firstChild);

const collection = TypedHTML.ul([
TypedHTML.li(),
TypedHTML.li()
TypedHTML.li(['1']),
TypedHTML.li(['2'])
]);
assert(collection.raw.nodeName === 'UL');
assert(collection.contents[0].raw.nodeName === 'LI');
assert(collection.raw.outerHTML === '<ul><li>1</li><li>2</li></ul>');
assert(collection.contents.length === collection.raw.children.length);
assert(collection.contents[0].raw === collection.raw.children[0]);
assert(collection.contents[1].raw.nodeName === 'LI');
assert(collection.contents[1].raw === collection.raw.children[1]);
assert(collection.contents[2] === void 0);
assert(collection.raw.children[2] === void 0);
});

@@ -108,6 +98,4 @@

];
assert(collection.contents[0].raw.nodeName === 'LI');
assert(collection.contents.length === collection.raw.children.length);
assert(collection.contents[0].raw === collection.raw.children[0]);
assert(collection.contents[1] === void 0);
assert(collection.raw.children[1] === void 0);
});

@@ -114,0 +102,0 @@

@@ -16,3 +16,3 @@ /**

}
export type TypedHTMLContents<T extends HTMLElement> = never[] | TypedHTML<string, T, any>[] | { [name: string]: TypedHTML<string, T, any>; };
export type TypedHTMLContents<T extends HTMLElement> = never[] | string[] | TypedHTML<string, T, any>[] | { [name: string]: TypedHTML<string, T, any>; };
interface TypedHTMLBuilder<T extends HTMLElement, S extends string> {

@@ -19,0 +19,0 @@ (): TypedHTML<S, T, never[]>;

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