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

attodom

Package Overview
Dependencies
Maintainers
1
Versions
29
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

attodom - npm Package Compare versions

Comparing version 0.12.0 to 0.13.0

.eslintrc.json

6

CHANGELOG.md

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

<!-- markdownlint-disable MD004 MD007 MD010 MD041 MD022 MD024 MD031 MD032 MD036 -->
# Change Log

@@ -9,2 +10,6 @@

## [0.13.0]
### Changed
- cjs => esm
## [0.12.0]

@@ -16,3 +21,2 @@ ### Fix

## [0.11.0]

@@ -19,0 +23,0 @@ ### Removed

2

css.js

@@ -5,3 +5,3 @@ /**

*/
module.exports = function(cssRuleText) {
export default function(cssRuleText) {
/**@type {CSSStyleSheet} */

@@ -8,0 +8,0 @@ //@ts-ignore

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

var EVENTS = require('./src/events')
import EVENTS from './src/events.js'

@@ -17,3 +17,3 @@ var htmlProps = {

*/
module.exports = function(tagName) {
export default function(tagName) {
//@ts-ignore

@@ -20,0 +20,0 @@ var node = tagName.nodeType === 1 ? tagName : document.createElement(tagName)

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

module.exports = function(start, test, until) {
export default function(start, test, until) {
var spot = start,

@@ -3,0 +3,0 @@ last = until || null

// @ts-check
/* eslint-disable global-require */
module.exports = {
el: require('./el'),
svg: require('./svg'),
list: require('./list')
}
export { default as el } from './el.js'
export { default as svg } from './svg.js'
export { default as list } from './list.js'
export { default as find } from './find.js'
export { default as css } from './css.js'

@@ -7,3 +7,3 @@ /**

*/
module.exports = function(parent, factory, options) {
export default function(parent, factory, options) {
return {

@@ -10,0 +10,0 @@ parent: parent,

{
"name": "attodom",
"version": "0.12.0",
"version": "0.13.0",
"type": "module",
"main": "./index.js",
"module": "./index.js",
"description": "yet another small DOM component library",

@@ -16,15 +18,9 @@ "keywords": [

"devDependencies": {
"@hugov/cjs-to-iife": "^0.1.1",
"@types/node": "^10.5.2",
"cotest": "^2.1.1"
"assert-op": "^0.5.1",
"jsdom": "^16.2.2"
},
"scripts": {
"test": "cotest tst",
"iife": "npm run node:iife -- ./index.js ./bld/iife.js",
"min": "google-closure-compiler-js --compilationLevel ADVANCED --languageIn ES5 --languageOut ES5 --useTypesForOptimization true ./bld/iife.js > ./bld/iife.min.js",
"gzip": "npm run node:gzip -- ./bld/iife.min.js ./bld/iife.gz",
"build": "npm run iife && npm run min && npm run gzip",
"prepublishOnly": "npm test",
"node:iife": "node -e \"require('@hugov/cjs-to-iife')(process.argv[1]).then(code => fs.writeFileSync(process.argv[2], code))\"",
"node:gzip": "node -e \"fs.writeFileSync(process.argv[2], zlib.gzipSync(fs.readFileSync(process.argv[1])))\""
"test": "node ./tst/el & node ./tst/svg & node ./tst/list & node ./tst/css & node ./tst/find",
"prepublishOnly": "npm test"
},

@@ -31,0 +27,0 @@ "repository": {

@@ -0,8 +1,8 @@

<!-- markdownlint-disable MD004 MD007 MD010 MD041 MD022 MD024 MD032 MD036 -->
# attodom
*yet another experimental small DOM component library, < 1kb*
*yet another small DOM component library, < 1kb*
• [Why](#why) • [API](#api) • [License](#license)
• Why](#why) • [API](#api) • [License](#license)
## Why

@@ -12,3 +12,2 @@

### Features

@@ -25,3 +24,2 @@

### Limitations

@@ -31,3 +29,2 @@

## API

@@ -45,3 +42,2 @@

### Synthetic Events

@@ -53,3 +49,2 @@

### Lists

@@ -69,2 +64,3 @@ * `list(parent:Node, factory, options): List`

```javascript
import {el, svg, list} from 'attodom'
var ol = el('ol'),

@@ -71,0 +67,0 @@ bullets = list(ol, (v, i) => el('li', i + ':' + v))

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

module.exports = {}
export default {}

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

var EVENTS = require('./src/events')
import EVENTS from './src/events.js'

@@ -7,3 +7,3 @@ /**

*/
module.exports = function(tagName) {
export default function(tagName) {
//@ts-ignore

@@ -10,0 +10,0 @@ var node = tagName.nodeType === 1 ? tagName : document.createElementNS('http://www.w3.org/2000/svg', tagName)

@@ -1,28 +0,27 @@

/* global document */
var JSDOM = require('jsdom').JSDOM
import css from '../css.js'
import jsdom from 'jsdom'
import t from 'assert-op'
//@ts-ignore
global.document = (new JSDOM).window.document
global.document = (new jsdom.JSDOM).window.document
var ct = require('cotest'),
css = require('../css')
//css - add rule
var sheets = document.styleSheets,
sheet = null,
match = /myClass/,
found = false
ct('css - add rule', function() {
var sheets = document.styleSheets,
sheet = null,
match = /myClass/,
found = false
css('.myClass { color: white }')
css('.myClass { color: white }')
// get existing sheet
for (var i=0; i<sheets.length && !found; ++i) {
sheet = sheets[i]
// get existing sheet
for (var i=0; i<sheets.length && !found; ++i) {
sheet = sheets[i]
//@ts-ignore
for (var j=0; j<sheet.cssRules.length && !found; ++j) {
//@ts-ignore
for (var j=0; j<sheet.cssRules.length && !found; ++j) {
//@ts-ignore
found = match.test(sheet.cssRules[i].cssText)
}
found = match.test(sheet.cssRules[i].cssText)
}
}
ct('!!', found)
})
t('!!', found)

@@ -1,77 +0,66 @@

/* global document */
var JSDOM = require('jsdom').JSDOM
import el from '../el.js'
import jsdom from 'jsdom'
import t from 'assert-op'
var JSDOM = jsdom.JSDOM
var window = (new JSDOM).window
//@ts-ignore
global.document = window.document
var ct = require('cotest'),
el = require('../').el,
updateChildren = require('../').updateChildren
// element-nodeType
t('===', el('div').nodeType, 1)
t('===', el('p').nodeType, 1)
t('===', el(document.createElement('p')).nodeType, 1)
ct('element-nodeType', function() {
ct('===', el('div').nodeType, 1)
ct('===', el('p').nodeType, 1)
ct('===', el(document.createElement('p')).nodeType, 1)
})
// element-properties
t('===', el('div').attributes.length, 0)
t('===', el('div', {id: 'id'}).id, 'id')
t('===', el('div', {className: 'className'}).className, 'className')
t('===', el('input', {value: 'value'}).value, 'value')
t('===', el('p', {textContent: 'textContent'}).textContent, 'textContent')
ct('element-properties', function() {
ct('===', el('div').attributes.length, 0)
ct('===', el('div', {id: 'id'}).id, 'id')
ct('===', el('div', {className: 'className'}).className, 'className')
//@ts-ignore
ct('===', el('input', {value: 'value'}).value, 'value')
ct('===', el('p', {textContent: 'textContent'}).textContent, 'textContent')
})
// element-attributes
t('===', el('div').attributes.length, 0)
t('===', el('div', {class: 'class'}).attributes.length, 1)
t('===', el('div', {style: 'style'}).attributes.length, 1)
t('===', el('div', {'data-set': 'data-set'}).attributes.length, 1)
t('===', el('div', {value: 'value'}).attributes.length, 0)
ct('element-attributes', function() {
ct('===', el('div').attributes.length, 0)
ct('===', el('div', {class: 'class'}).attributes.length, 1)
ct('===', el('div', {style: 'style'}).attributes.length, 1)
ct('===', el('div', {'data-set': 'data-set'}).attributes.length, 1)
ct('===', el('div', {value: 'value'}).attributes.length, 0)
})
// element - mixed children
t('===', el('p', [0, el('p'), el('p'), el('p')]).childNodes.length, 4)
t('===', el('p', el('p'), [], el('p'), [el('p'), 0]).childNodes.length, 4)
t('===', el('p', [el('p'), 0, [el('p'), el('p')]]).childNodes.length, 3)
ct('element - mixed children', function() {
ct('===', el('p', [0, el('p'), el('p'), el('p')]).childNodes.length, 4)
ct('===', el('p', el('p'), [], el('p'), [el('p'), 0]).childNodes.length, 4)
ct('===', el('p', [el('p'), 0, [el('p'), el('p')]]).childNodes.length, 3)
})
// el - event
var kin = el('h1', {onclick: function(e) { this.textContent += e.target.tagName }})
kin.dispatchEvent(new window.Event('click', {bubbles:true}))
t('===', kin.textContent, 'H1')
ct('el - event', function() {
var kin = el('h1', {onclick: function(e) { this.textContent += e.target.tagName }})
kin.dispatchEvent(new window.Event('click', {bubbles:true}))
ct('===', kin.textContent, 'H1')
})
// el - synthetic event
var h2 = el('h2'),
h1 = el('h1', {onClick: function(e) { this.textContent = e.target.tagName }}, h2)
document.body.appendChild(h1)
h1.dispatchEvent(new window.Event('click', {bubbles:false}))
t('===', h1.textContent, '')
h2.dispatchEvent(new window.Event('click', {bubbles:true}))
t('===', h1.textContent, 'H2')
h1.dispatchEvent(new window.Event('click', {bubbles:true}))
t('===', h1.textContent, 'H1')
ct('el - synthetic event', function() {
var h2 = el('h2'),
h1 = el('h1', {onClick: function(e) { this.textContent = e.target.tagName }}, h2)
document.body.appendChild(h1)
h1.dispatchEvent(new window.Event('click', {bubbles:false}))
ct('===', h1.textContent, '')
h2.dispatchEvent(new window.Event('click', {bubbles:true}))
ct('===', h1.textContent, 'H2')
h1.dispatchEvent(new window.Event('click', {bubbles:true}))
ct('===', h1.textContent, 'H1')
})
// element - update
kin = el('span', 'b', {update: function(v) { this.textContent = v.toUpperCase() }})
t('===', kin.textContent, 'b')
//@ts-ignore
kin.update('abc')
t('===', kin.textContent, 'ABC')
ct('element - update', function() {
var kin = el('span', 'b', {update: function(v) { this.textContent = v.toUpperCase() }})
ct('===', kin.textContent, 'b')
//@ts-ignore
kin.update('abc')
ct('===', kin.textContent, 'ABC')
// element - nested reference
var kid = el('span', 'b')
kin = el('h1', el('h2', el('h3', el('h4', kid))), {
__kid: kid,
update: function(v) { this.__kid.textContent = v }
})
ct('element - nested reference', function() {
var kid = el('span', 'b'),
kin = el('h1', el('h2', el('h3', el('h4', kid))), {
__kid: kid,
update: function(v) { this.__kid.textContent = v }
})
ct('===', kid.textContent, 'b')
//@ts-ignore
kin.update('B')
ct('===', kid.textContent, 'B')
})
t('===', kid.textContent, 'b')
//@ts-ignore
kin.update('B')
t('===', kid.textContent, 'B')

@@ -1,25 +0,24 @@

/* global document */
var JSDOM = require('jsdom').JSDOM
//@ts-ignore
global.document = (new JSDOM).window.document
import el from '../el.js'
import find from '../find.js'
import jsdom from 'jsdom'
import t from 'assert-op'
var ct = require('cotest'),
el = require('../el'),
find = require('../find')
var JSDOM = jsdom.JSDOM
var window = (new JSDOM).window
global.document = window.document
ct('find', function() {
var h01 = el('h2', 'H01'),
h0 = el('h1', ['H0', el('h2', 'H00'), h01]),
h10 = el('h2', 'H10'),
h1 = el('h1', 'H1', h10, el('h2', 'H11')),
h = el('div', ['H', h0, h1])
// find
var h01 = el('h2', 'H01'),
h0 = el('h1', ['H0', el('h2', 'H00'), h01]),
h10 = el('h2', 'H10'),
h1 = el('h1', 'H1', h10, el('h2', 'H11')),
h = el('div', ['H', h0, h1])
ct('===', find(h, c=>c.textContent === 'H10'), h10)
ct('===', find(h, c=>c.textContent === 'H10'), h10)
t('===', find(h, c=>c.textContent === 'H10'), h10)
t('===', find(h, c=>c.textContent === 'H10'), h10)
ct('===', find(h, c=>c.textContent === 'H10', h10), h10)
ct('===', find(h, c=>c.textContent === 'H10', h10), h10)
t('===', find(h, c=>c.textContent === 'H10', h10), h10)
t('===', find(h, c=>c.textContent === 'H10', h10), h10)
ct('===', find(h, c=>c.textContent === 'H10', h01), null)
ct('===', find(h, c=>c.textContent === 'H10', h01), null)
})
t('===', find(h, c=>c.textContent === 'H10', h01), null)
t('===', find(h, c=>c.textContent === 'H10', h01), null)

@@ -1,9 +0,9 @@

/* global document */
var JSDOM = require('jsdom').JSDOM
//@ts-ignore
global.document = (new JSDOM).window.document
import el from '../el.js'
import ls from '../list.js'
import jsdom from 'jsdom'
import t from 'assert-op'
var ct = require('cotest'),
el = require('../').el,
ls = require('../').list
var JSDOM = jsdom.JSDOM
var window = (new JSDOM).window
global.document = window.document

@@ -15,74 +15,69 @@ function toString(nodes) {

}
function upperKid(t) {
return el('p', t.toUpperCase(), {update: function(t) { this.textContent = t }})
function upperKid(s) {
return el('p', s.toUpperCase(), {update: function(x) { this.textContent = x }})
}
ct('list - empty parent', function() {
var kin = el('div'),
list = ls(kin, upperKid)
ct('===', toString(kin.childNodes), '')
list.update(['a'])
ct('===', toString(kin.childNodes), 'A')
list.update(['a', 'b'])
ct('===', toString(kin.childNodes), 'aB')
list.update(['a'])
ct('===', toString(kin.childNodes), 'a')
list.update([])
ct('===', kin.childNodes.length, 0)
ct('===', Object.keys(list.map).length, 0)
})
// list - empty parent
var kin = el('div'),
list = ls(kin, upperKid)
t('===', toString(kin.childNodes), '')
list.update(['a'])
t('===', toString(kin.childNodes), 'A')
list.update(['a', 'b'])
t('===', toString(kin.childNodes), 'aB')
list.update(['a'])
t('===', toString(kin.childNodes), 'a')
list.update([])
t('===', kin.childNodes.length, 0)
t('===', Object.keys(list.map).length, 0)
ct('list mounted with next', function() {
var kin = el('div', '$'),
list = ls(kin, upperKid, {before: kin.firstChild})
ct('===', toString(kin.childNodes), '$')
list.update(['a'])
ct('===', toString(kin.childNodes), 'A$')
list.update(['a', 'b'])
ct('===', toString(kin.childNodes), 'aB$')
list.update(['a'])
ct('===', toString(list.parent.childNodes), 'a$')
})
// list mounted with next
kin = el('div', '$')
list = ls(kin, upperKid, {before: kin.firstChild})
t('===', toString(kin.childNodes), '$')
list.update(['a'])
t('===', toString(kin.childNodes), 'A$')
list.update(['a', 'b'])
t('===', toString(kin.childNodes), 'aB$')
list.update(['a'])
t('===', toString(list.parent.childNodes), 'a$')
ct('list function key getter', function() {
var kin = el('h0'),
list = ls(
kin,
function(o) { return el('p', o.v, {update: function(v) { this.textContent = v.v.toUpperCase() }}) },
{key: function(o) { return o.k }}
)
ct('===', toString(kin.childNodes), '')
list.update([{k: 'a', v:'a'}, {k: 'b', v:'b'}, {k: 'c', v:'c'}])
ct('===', toString(kin.childNodes), 'abc')
list.update([{k: 'c', v:'c'}, {k: 'd', v:'d'}, {k: 'e', v:'e'}, ])
ct('===', toString(kin.childNodes), 'Cde')
list.update([{k: 'a', v:'a'}, {k: 'b', v:'b'}, {k: 'c', v:'c'}])
ct('===', toString(kin.childNodes), 'abC')
})
// list function key getter
kin = el('h0')
list = ls(
kin,
function(o) { return el('p', o.v, {update: function(v) { this.textContent = v.v.toUpperCase() }}) },
{key: function(o) { return o.k }}
)
t('===', toString(kin.childNodes), '')
list.update([{k: 'a', v:'a'}, {k: 'b', v:'b'}, {k: 'c', v:'c'}])
t('===', toString(kin.childNodes), 'abc')
list.update([{k: 'c', v:'c'}, {k: 'd', v:'d'}, {k: 'e', v:'e'}, ])
t('===', toString(kin.childNodes), 'Cde')
list.update([{k: 'a', v:'a'}, {k: 'b', v:'b'}, {k: 'c', v:'c'}])
t('===', toString(kin.childNodes), 'abC')
ct('list string key getter', function() {
var kin = el('h0'),
list = ls(
kin,
function(o) { return el('p', o.v, {update: function(v) { this.textContent = v.v.toUpperCase() }}) },
{key: 'k'}
)
ct('===', toString(kin.childNodes), '')
list.update([{k: 'a', v:'a'}, {k: 'b', v:'b'}, {k: 'c', v:'c'}])
ct('===', toString(kin.childNodes), 'abc')
list.update([{k: 'c', v:'c'}, {k: 'd', v:'d'}, {k: 'e', v:'e'}, ])
ct('===', toString(kin.childNodes), 'Cde')
list.update([{k: 'a', v:'a'}, {k: 'b', v:'b'}, {k: 'c', v:'c'}])
ct('===', toString(kin.childNodes), 'abC')
})
// list string key getter
kin = el('h0')
list = ls(
kin,
function(o) { return el('p', o.v, {update: function(v) { this.textContent = v.v.toUpperCase() }}) },
{key: 'k'}
)
t('===', toString(kin.childNodes), '')
list.update([{k: 'a', v:'a'}, {k: 'b', v:'b'}, {k: 'c', v:'c'}])
t('===', toString(kin.childNodes), 'abc')
list.update([{k: 'c', v:'c'}, {k: 'd', v:'d'}, {k: 'e', v:'e'}, ])
t('===', toString(kin.childNodes), 'Cde')
list.update([{k: 'a', v:'a'}, {k: 'b', v:'b'}, {k: 'c', v:'c'}])
t('===', toString(kin.childNodes), 'abC')
ct('list multiple', function() {
var kin = el('div', '$'),
ls1 = ls(kin, upperKid, {before: kin.firstChild}),
ls2 = ls(kin, upperKid, {after: kin.firstChild})
ct('===', toString(kin.childNodes), '$')
ls1.update(['a'])
ct('===', toString(kin.childNodes), 'A$')
ls2.update(['a', 'b'])
ct('===', toString(kin.childNodes), 'A$AB')
})
// list multiple
kin = el('div', '$')
var ls1 = ls(kin, upperKid, {before: kin.firstChild}),
ls2 = ls(kin, upperKid, {after: kin.firstChild})
t('===', toString(kin.childNodes), '$')
ls1.update(['a'])
t('===', toString(kin.childNodes), 'A$')
ls2.update(['a', 'b'])
t('===', toString(kin.childNodes), 'A$AB')

@@ -1,39 +0,32 @@

/* global document */
var JSDOM = require('jsdom').JSDOM
import svg from '../svg.js'
import jsdom from 'jsdom'
import t from 'assert-op'
var JSDOM = jsdom.JSDOM
var window = (new JSDOM).window
//@ts-ignore
global.document = window.document
// svg
t('===', svg('svg').nodeType, 1)
t('===', svg('path').nodeType, 1)
var ct = require('cotest'),
svg = require('../svg')
t('===', svg('path').attributes.length, 0)
t('===', svg('path', {d: 'm37', stroke: 'green'}).attributes.length, 2)
t('===', svg('path', {d: 'm37'}, {stroke: 'green'}).attributes.length, 2)
ct('svg', function() {
ct('===', svg('svg').nodeType, 1)
ct('===', svg('path').nodeType, 1)
t('===', svg('g').childNodes.length, 0)
t('===', svg('svg', svg('g'), svg('g')).childNodes.length, 2)
ct('===', svg('path').attributes.length, 0)
ct('===', svg('path', {d: 'm37', stroke: 'green'}).attributes.length, 2)
ct('===', svg('path', {d: 'm37'}, {stroke: 'green'}).attributes.length, 2)
// svg - event
var kin = svg('path', {onclick: function(e) { this.textContent += e.target.tagName }})
kin.dispatchEvent(new window.Event('click', {bubbles:true}))
t('===', kin.textContent, 'path')
ct('===', svg('g').childNodes.length, 0)
ct('===', svg('svg', svg('g'), svg('g')).childNodes.length, 2)
})
ct('svg - event', function() {
var kin = svg('path', {onclick: function(e) { this.textContent += e.target.tagName }})
kin.dispatchEvent(new window.Event('click', {bubbles:true}))
ct('===', kin.textContent, 'path')
})
ct('svg - synthetic event', function() {
var h2 = svg('path'),
h1 = svg('svg', {onClick: function(e) { this.textContent = e.target.tagName }}, h2)
document.body.appendChild(h1)
h2.dispatchEvent(new window.Event('click', {bubbles:true}))
ct('===', h1.textContent, 'path')
h1.dispatchEvent(new window.Event('click', {bubbles:true}))
ct('===', h1.textContent, 'svg')
})
// svg - synthetic event
var h2 = svg('path'),
h1 = svg('svg', {onClick: function(e) { this.textContent = e.target.tagName }}, h2)
document.body.appendChild(h1)
h2.dispatchEvent(new window.Event('click', {bubbles:true}))
t('===', h1.textContent, 'path')
h1.dispatchEvent(new window.Event('click', {bubbles:true}))
t('===', h1.textContent, 'svg')
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