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

snabbdom-selector

Package Overview
Dependencies
Maintainers
1
Versions
24
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

snabbdom-selector - npm Package Compare versions

Comparing version 0.3.1 to 0.3.2

lib/classNameFromVNode.js

3

CHANGELOG.md

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

# v0.3.2 (2015-12-18)
# v0.3.1 (2015-12-17)

@@ -2,0 +5,0 @@

32

lib/index.js

@@ -15,6 +15,6 @@ 'use strict';

function traverse(vtree, fn) {
fn(vtree);
if (vtree.children) {
vtree.children.forEach(function (child) {
function traverse(vNode, fn) {
fn(vNode);
if (vNode.children) {
vNode.children.forEach(function (child) {
traverse(child, fn);

@@ -25,27 +25,21 @@ });

function wrapVnode(vnode, parent) {
var sel = vnode.sel;
var children = vnode.children;
var data = vnode.data;
var text = vnode.text;
var elm = vnode.elm;
var key = vnode.key;
function wrapVNode(vNode, parent) {
var children = vNode.children;
var wrappedVnode = { sel: sel, data: data, text: text, elm: elm, key: key, parent: parent };
if (children && typeof children.map === 'function') {
children = children.map(function (k) {
return wrapVnode(k, wrappedVnode);
}).filter(Boolean);
return wrapVNode(k, vNode);
});
}
wrappedVnode.children = children;
return wrappedVnode;
vNode.parent = parent;
return vNode;
}
function match(sel, vnode) {
function match(sel, vNode) {
var selector = (0, _language2.default)(sel);
var matched = [];
var wrappedVnode = wrapVnode(vnode);
var wrappedVNode = wrapVNode(vNode);
traverse(wrappedVnode, function (node) {
traverse(wrappedVNode, function (node) {
var result = undefined;

@@ -52,0 +46,0 @@ if (node.data && node.data.vnode) {

@@ -11,52 +11,60 @@ 'use strict';

var _parseSelector = require('./parseSelector');
var _selectorParser = require('./selectorParser');
var _parseSelector2 = _interopRequireDefault(_parseSelector);
var _selectorParser2 = _interopRequireDefault(_selectorParser);
var _getClasses = require('./getClasses');
var _classNameFromVNode = require('./classNameFromVNode');
var _getClasses2 = _interopRequireDefault(_getClasses);
var _classNameFromVNode2 = _interopRequireDefault(_classNameFromVNode);
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
var language = (0, _cssauron2.default)({
tag: function tag(node) {
return (0, _parseSelector2.default)(node.sel).tagName;
},
class: function _class(node) {
return (0, _getClasses2.default)(node);
},
id: function id(node) {
if (node.data && node.data.props && node.data.props.id) {
return node.data.props.id;
}
return (0, _parseSelector2.default)(node.sel).id;
},
children: function children(node) {
return node.children || [];
},
parent: function parent(node) {
return node.parent || node;
},
contents: function contents(node) {
return node.text;
},
attr: function attr(node, _attr) {
if (node.data) {
var _node$data = node.data;
var _node$data$attrs = _node$data.attrs;
var attrs = _node$data$attrs === undefined ? {} : _node$data$attrs;
var _node$data$props = _node$data.props;
var props = _node$data$props === undefined ? {} : _node$data$props;
function LanguageSpecification() {}
if (attrs[_attr]) {
return attrs[_attr];
}
if (props[_attr]) {
return props[_attr];
}
LanguageSpecification.prototype.tag = function tag(vNode) {
return (0, _selectorParser2.default)(vNode.sel).tagName;
};
LanguageSpecification.prototype.class = function klass(vNode) {
return (0, _classNameFromVNode2.default)(vNode);
};
LanguageSpecification.prototype.id = function id(vNode) {
if (vNode.data && vNode.data.props && vNode.data.props.id) {
return vNode.data.props.id;
}
return (0, _selectorParser2.default)(vNode.sel).id;
};
LanguageSpecification.prototype.children = function children(vNode) {
return vNode.children || [];
};
LanguageSpecification.prototype.parent = function parent(vNode) {
return vNode.parent || vNode;
};
LanguageSpecification.prototype.contents = function contents(vNode) {
return vNode.text;
};
LanguageSpecification.prototype.attr = function attributes(vNode, attr) {
if (vNode.data) {
var _vNode$data = vNode.data;
var _vNode$data$attrs = _vNode$data.attrs;
var attrs = _vNode$data$attrs === undefined ? {} : _vNode$data$attrs;
var _vNode$data$props = _vNode$data.props;
var props = _vNode$data$props === undefined ? {} : _vNode$data$props;
if (attrs[attr]) {
return attrs[attr];
}
if (props[attr]) {
return props[attr];
}
}
});
};
var language = (0, _cssauron2.default)(new LanguageSpecification());
exports.default = language;
{
"name": "snabbdom-selector",
"version": "0.3.1",
"version": "0.3.2",
"description": "Snabbdom CSS-Selector",

@@ -5,0 +5,0 @@ "main": "lib/index.js",

import language from './language'
function traverse(vtree, fn) {
fn(vtree)
if (vtree.children) {
vtree.children.forEach(child => {
function traverse(vNode, fn) {
fn(vNode)
if (vNode.children) {
vNode.children.forEach(child => {
traverse(child, fn)

@@ -12,19 +12,18 @@ })

function wrapVnode(vnode, parent) {
let {sel, children, data, text, elm, key} = vnode
let wrappedVnode = {sel, data, text, elm, key, parent}
function wrapVNode(vNode, parent) {
let {children} = vNode
if (children && typeof children.map === `function`) {
children = children.map(k => wrapVnode(k, wrappedVnode)).filter(Boolean)
children = children.map(k => wrapVNode(k, vNode))
}
wrappedVnode.children = children
return wrappedVnode
vNode.parent = parent
return vNode
}
function match(sel, vnode) {
function match(sel, vNode) {
const selector = language(sel)
let matched = []
let wrappedVnode = wrapVnode(vnode)
let wrappedVNode = wrapVNode(vNode)
traverse(wrappedVnode, node => {
traverse(wrappedVNode, node => {
let result

@@ -31,0 +30,0 @@ if (node.data && node.data.vnode) {

import cssauron from 'cssauron'
import parseSelector from './parseSelector'
import getClasses from './getClasses'
import selectorParser from './selectorParser'
import classNameFromVNode from './classNameFromVNode'
const language = cssauron({
tag(node) {
return parseSelector(node.sel).tagName
},
class(node) {
return getClasses(node)
},
id(node) {
if (node.data && node.data.props && node.data.props.id) {
return node.data.props.id
function LanguageSpecification() {}
LanguageSpecification.prototype.tag = function tag(vNode) {
return selectorParser(vNode.sel).tagName
}
LanguageSpecification.prototype.class = function klass(vNode) {
return classNameFromVNode(vNode)
}
LanguageSpecification.prototype.id = function id(vNode) {
if (vNode.data && vNode.data.props && vNode.data.props.id) {
return vNode.data.props.id
}
return selectorParser(vNode.sel).id
}
LanguageSpecification.prototype.children = function children(vNode) {
return vNode.children || []
}
LanguageSpecification.prototype.parent = function parent(vNode) {
return vNode.parent || vNode
}
LanguageSpecification.prototype.contents = function contents(vNode) {
return vNode.text
}
LanguageSpecification.prototype.attr = function attributes(vNode, attr) {
if (vNode.data) {
const {attrs = {}, props = {}} = vNode.data
if (attrs[attr]) {
return attrs[attr]
}
return parseSelector(node.sel).id
},
children(node) {
return node.children || []
},
parent(node) {
return node.parent || node
},
contents(node) {
return node.text
},
attr(node, attr) {
if (node.data) {
const {attrs = {}, props = {}} = node.data
if (attrs[attr]) {
return attrs[attr]
}
if (props[attr]) {
return props[attr]
}
if (props[attr]) {
return props[attr]
}
},
})
}
}
const language = cssauron(new LanguageSpecification())
export default language

@@ -15,2 +15,31 @@ import assert from 'assert'

it('should return a vNode by className from props', done => {
const vNode = h('div', {props: {className: 'test'}}, 'test')
const result = selector('.test', vNode)
assert.strictEqual(result[0].sel, 'div')
assert.strictEqual(result[0].data.props.className, 'test')
assert.strictEqual(result[0].text, 'test')
done()
})
it('should return a vNode by classnNme from class module', done => {
const vNode = h('div', {class: {test: true}}, 'test')
const result = selector('.test', vNode)
assert.strictEqual(result[0].sel, 'div')
assert.strictEqual(result[0].data.class.test, true)
assert.strictEqual(result[0].text, 'test')
done()
})
it('should return a vNode by className from all 3', done => {
const vNode = h('div.test', {
props: {className: 'anotherTest'},
class: {theRealTest: true },
}, 'test')
const result = selector('.test.anotherTest.theRealTest', vNode)
assert.strictEqual(result[0].sel, `div.test`)
assert.strictEqual(result[0].text, 'test')
done()
})
it('should return a vnode by ID from selector', done => {

@@ -17,0 +46,0 @@ const vnode = h('div#test', {}, 'test')

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