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.8 to 0.0.9

17

dist/typed-dom.js

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

/*! typed-dom v0.0.8 https://github.com/falsandtru/typed-dom | (c) 2016, falsandtru | MIT License */
/*! typed-dom v0.0.9 https://github.com/falsandtru/typed-dom | (c) 2016, falsandtru | MIT License */
define = typeof define === 'function' && define.amd

@@ -36,9 +36,6 @@ ? define

'use strict';
function build(factory, contents, attrs) {
function build(factory, attrs, contents) {
if (contents === void 0) {
contents = [];
}
if (attrs === void 0) {
attrs = {};
}
var raw = factory();

@@ -223,9 +220,11 @@ void Object.keys(attrs).forEach(function (name) {

].reduce(function (obj, tag) {
obj[tag] = function (contents, attrs, factory) {
if (!factory && typeof attrs === 'function') {
factory = attrs;
obj[tag] = function (attrs, contents, factory) {
if (!contents || typeof contents === 'function') {
factory = contents;
contents = attrs;
attrs = {};
}
return builder_1.build(factory || function () {
return document.createElement(tag);
}, contents, attrs);
}, attrs, contents);
};

@@ -232,0 +231,0 @@ return obj;

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

/*! typed-dom v0.0.8 https://github.com/falsandtru/typed-dom | (c) 2016, falsandtru | MIT License */
define="function"==typeof define&&define.amd?define:function(){"use strict";var e="typed-dom",t={};return function r(n,i,o){return o?void o.apply(this,i.map(function(e){switch(e){case"require":return"function"==typeof require?require:void 0;case"exports":return n.indexOf("/")===-1?t[n]="undefined"==typeof exports?self[n]=self[n]||{}:exports:t[n]=t.hasOwnProperty(n)?t[n]:{};default:return".d"===e.slice(-2)&&{}||t.hasOwnProperty(e)&&t[e]||"function"==typeof require&&require(e)||self[e]}})):void r(e,n,i)}}(),define("src/dom/builder",["require","exports"],function(e,t){"use strict";function r(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,i.replaceChild(e.raw,n.raw)}}),e},e)}void 0===t&&(t=[]),void 0===r&&(r={});var i=e();return void Object.keys(r).forEach(function(e){return i.setAttribute(e,r[e]||"")}),void Object.keys(t).forEach(function(e){return void i.appendChild(t[e].raw)}),t=t instanceof Array?Object.freeze(t):n(t),Object.freeze({raw:i,get contents(){return t},set contents(e){t instanceof Array?(e=Object.freeze(e),i.innerHTML="",void e.forEach(function(e){return void i.appendChild(e.raw)})):(void Object.keys(e).forEach(function(r){return void i.replaceChild(e[r].raw,t[r].raw)}),e=n(e)),t=e}})}t.build=r}),define("src/dom/html",["require","exports","src/dom/builder"],function(e,t,r){"use strict";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,t){return e[t]=function(e,n,i){return i||"function"!=typeof n||(i=n),r.build(i||function(){return document.createElement(t)},e,n)},e},{})}),define("src/export",["require","exports","src/dom/html"],function(e,t,r){"use strict";t.default=r.TypedHTML}),define("typed-dom",["require","exports","src/export","src/export","./src/import"],function(e,t,r,n){"use strict";function i(e){for(var r in e)t.hasOwnProperty(r)||(t[r]=e[r])}i(r),t.default=n.default});
/*! typed-dom v0.0.9 https://github.com/falsandtru/typed-dom | (c) 2016, falsandtru | MIT License */
define="function"==typeof define&&define.amd?define:function(){"use strict";var e="typed-dom",t={};return function r(n,i,o){return o?void o.apply(this,i.map(function(e){switch(e){case"require":return"function"==typeof require?require:void 0;case"exports":return n.indexOf("/")===-1?t[n]="undefined"==typeof exports?self[n]=self[n]||{}:exports:t[n]=t.hasOwnProperty(n)?t[n]:{};default:return".d"===e.slice(-2)&&{}||t.hasOwnProperty(e)&&t[e]||"function"==typeof require&&require(e)||self[e]}})):void r(e,n,i)}}(),define("src/dom/builder",["require","exports"],function(e,t){"use strict";function r(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,i.replaceChild(e.raw,n.raw)}}),e},e)}void 0===r&&(r=[]);var i=e();return void Object.keys(t).forEach(function(e){return i.setAttribute(e,t[e]||"")}),void Object.keys(r).forEach(function(e){return void i.appendChild(r[e].raw)}),r=r instanceof Array?Object.freeze(r):n(r),Object.freeze({raw:i,get contents(){return r},set contents(e){r instanceof Array?(e=Object.freeze(e),i.innerHTML="",void e.forEach(function(e){return void i.appendChild(e.raw)})):(void Object.keys(e).forEach(function(t){return void i.replaceChild(e[t].raw,r[t].raw)}),e=n(e)),r=e}})}t.build=r}),define("src/dom/html",["require","exports","src/dom/builder"],function(e,t,r){"use strict";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,t){return e[t]=function(e,n,i){return n&&"function"!=typeof n||(i=n,n=e,e={}),r.build(i||function(){return document.createElement(t)},e,n)},e},{})}),define("src/export",["require","exports","src/dom/html"],function(e,t,r){"use strict";t.default=r.TypedHTML}),define("typed-dom",["require","exports","src/export","src/export","./src/import"],function(e,t,r,n){"use strict";function i(e){for(var r in e)t.hasOwnProperty(r)||(t[r]=e[r])}i(r),t.default=n.default});
{
"name": "typed-dom",
"version": "0.0.8",
"version": "0.0.9",
"description": "Static typed html dom builder.",

@@ -32,4 +32,4 @@ "private": false,

"devDependencies": {
"@types/mocha": "^2.2.30",
"@types/power-assert": "0.0.27",
"@types/mocha": "^2.2.32",
"@types/power-assert": "1.4.29",
"del": "^2.2.2",

@@ -39,9 +39,9 @@ "extend": "^3.0.0",

"gulp-header": "^1.8.8",
"gulp-load-plugins": "^1.2.4",
"gulp-load-plugins": "^1.3.0",
"gulp-mocha": "^3.0.1",
"gulp-rename": "^1.2.2",
"gulp-typescript": "^2.13.6",
"gulp-typescript": "^3.0.1",
"gulp-uglify": "^2.0.0",
"gulp-unassert": "^1.0.0",
"karma": "1.2.0",
"karma": "1.3.0",
"karma-chrome-launcher": "^2.0.0",

@@ -53,8 +53,8 @@ "karma-coverage": "^1.1.1",

"karma-ie-launcher": "^1.0.0",
"karma-mocha": "^1.1.1",
"mocha": "^3.0.2",
"karma-mocha": "^1.2.0",
"mocha": "^3.1.0",
"npm-check-updates": "^2.8.0",
"power-assert": "^1.4.1",
"run-sequence": "^1.2.2",
"typescript": "^2.1.0-dev.20160823"
"typescript": "2.1.0-dev.20160930"
},

@@ -61,0 +61,0 @@ "scripts": {

import {TypedHTML, TypedHTMLContents} from 'typed-dom';
export function build<S extends string, T extends HTMLElement, U extends TypedHTMLContents<HTMLElement>>(factory: () => T, contents: U = <any>[], attrs: {} = {}): TypedHTML<S, T, U> {
export function build<S extends string, T extends HTMLElement, U extends TypedHTMLContents<HTMLElement>>(factory: () => T, attrs: {}, contents: U = <any>[]): TypedHTML<S, T, U> {
const raw = factory();

@@ -5,0 +5,0 @@ void Object.keys(attrs)

@@ -134,10 +134,12 @@ import {TypedHTML as ITypedHTML, TypedHTMLContents} from 'typed-dom';

<T extends TypedHTMLContents<HTMLElement>>
(contents?: T, attrs?: { [name: string]: string; }, factory?: () => HTMLElement)
(attrs: { [name: string]: string; }, contents?: T, factory?: () => HTMLElement)
: TypedHTML<string, HTMLElement, T> => {
if (!factory && typeof attrs === 'function') {
factory = <any>attrs;
if (!contents || typeof contents === 'function') {
factory = <any>contents;
contents = <any>attrs;
attrs = {};
}
return build(factory || (() => document.createElement(tag)), contents, attrs);
return build(factory || (() => document.createElement(tag)), attrs, contents);
}
return obj;
}, <TypedHTML<string, HTMLElement, TypedHTMLContents<HTMLElement>>>{});

@@ -10,8 +10,36 @@ import TypedHTML from 'typed-dom';

it('attr', function () {
const dom = TypedHTML.script([], { id: 'test', src: './' });
it('attr with array', function () {
const dom = TypedHTML.script({ id: 'test', src: './' }, []);
assert(dom.raw.id === 'test');
assert(dom.raw.getAttribute('src') === './');
assert.deepStrictEqual(dom.contents, []);
});
it('attr with object', function () {
const dom = TypedHTML.script({ id: 'test', src: './' }, {});
assert(dom.raw.id === 'test');
assert(dom.raw.getAttribute('src') === './');
assert.deepStrictEqual(dom.contents, {});
});
it('factory with array', function () {
const dom = TypedHTML.script([], () => {
const el = document.createElement('script');
el.id = 'test';
return el;
});
assert(dom.raw.id === 'test');
assert.deepStrictEqual(dom.contents, []);
});
it('factory with object', function () {
const dom = TypedHTML.script({}, () => {
const el = document.createElement('script');
el.id = 'test';
return el;
});
assert(dom.raw.id === 'test');
assert.deepStrictEqual(dom.contents, {});
});
it('struct', function () {

@@ -82,4 +110,3 @@ const struct = TypedHTML.article({

assert.throws(() => collection.contents[0] = TypedHTML.li());
// IE doesn't throw an error here.
//assert.throws(() => collection.contents[1] = TypedHTML.li());
assert.throws(() => collection.contents[1] = TypedHTML.li());
assert.throws(() => collection.contents.push(TypedHTML.li()));

@@ -86,0 +113,0 @@ assert.throws(() => collection.contents.pop());

@@ -11,18 +11,2 @@ import TypedHTML from 'typed-dom';

describe('power-assert', function () {
it('assertion self-check', function (done) {
setTimeout(function () {
try {
console.log(assert(!false === !true), assert); // LOG: undefined, function powerAssert() { ... }
}
catch (e) {
done();
return;
}
throw new Error('WARNING!: assert function does not work.');
}, 1);
});
});
});

@@ -20,3 +20,3 @@ /**

<U extends TypedHTMLContents<HTMLElement>>(contents: U, factory?: () => T): TypedHTML<S, T, U>;
<U extends TypedHTMLContents<HTMLElement>>(contents: U, attrs: { [name: string]: string; }, factory?: () => T): TypedHTML<S, T, U>;
<U extends TypedHTMLContents<HTMLElement>>(attrs: { [name: string]: string; }, contents: U, factory?: () => T): TypedHTML<S, T, U>;
}

@@ -23,0 +23,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