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 1.0.1 to 1.1.0

yarn.lock

6

package.json
{
"name": "snabbdom-selector",
"version": "1.0.1",
"version": "1.1.0",
"description": "Snabbdom CSS-Selector",

@@ -37,6 +37,6 @@ "main": "lib/commonjs/index.js",

"mocha": "^3.1.2",
"snabbdom": "^0.5.4",
"snabbdom": "0.6.3",
"ts-node": "^1.6.1",
"tslint": "^3.15.1",
"typescript": "^2.0.6"
"typescript": "2.0.6"
},

@@ -43,0 +43,0 @@ "dependencies": {

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

import * as snabbdom from 'snabbdom';
import { selectorParser } from './selectorParser';
import { VNode } from 'snabbdom/vnode';
import { selectorParser } from './selectorParser';
export function classNameFromVNode(vNode: snabbdom.VNode): string {
export function classNameFromVNode(vNode: VNode): string {
let { className: cn = '' } = selectorParser(vNode);

@@ -6,0 +6,0 @@

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

import * as snabbdom from 'snabbdom';
import { VNode } from 'snabbdom/vnode';
import { Select, Selector } from './types';
export function curry2 (select: Select): Selector {
return function selector (selector: string, vNode: snabbdom.VNode): any {
return function selector (selector: string, vNode: VNode): any {
switch (arguments.length) {
case 0: return select;
case 1: return (_vNode: snabbdom.VNode) => select(selector, _vNode);
case 1: return (_vNode: VNode) => select(selector, _vNode);
default: return select(selector, vNode);

@@ -10,0 +10,0 @@ }

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

import * as snabbdom from 'snabbdom';
import { VNode } from 'snabbdom/vnode';
import { language } from './language';
export function findMatches (cssSelector: string, vNode: snabbdom.VNode): Array<snabbdom.VNode> {
export function findMatches (cssSelector: string, vNode: VNode): Array<VNode> {
const selector = language(cssSelector);
const matches: snabbdom.VNode[] = [];
const matches: VNode[] = [];
traverseVNode(vNode, addParent); // add mapping to the parent selectorParser
traverseVNode(vNode, function (currentNode: snabbdom.VNode) {
traverseVNode(vNode, function (currentNode: VNode) {
const { data } = currentNode;

@@ -39,8 +39,8 @@

function traverseVNode (vNode: snabbdom.VNode,
f: (vNode: snabbdom.VNode,
function traverseVNode (vNode: VNode,
f: (vNode: VNode,
root: boolean,
parent?: snabbdom.VNode) => any): void {
parent?: VNode) => any): void {
function recurse (currentNode: snabbdom.VNode, isParent: boolean, parentVNode?: snabbdom.VNode) {
function recurse (currentNode: VNode, isParent: boolean, parentVNode?: VNode) {
const length = currentNode.children && currentNode.children.length || 0;

@@ -53,3 +53,3 @@

const child = children[i];
recurse(child as snabbdom.VNode, false, currentNode);
recurse(child as VNode, false, currentNode);
}

@@ -64,3 +64,3 @@ }

function addParent (vNode: snabbdom.VNode, isParent: boolean, parent?: snabbdom.VNode): void {
function addParent (vNode: VNode, isParent: boolean, parent?: VNode): void {
if (isParent) { return void 0; }

@@ -67,0 +67,0 @@

import * as cssauron from 'cssauron';
import * as snabbdom from 'snabbdom';
import { VNode } from 'snabbdom/vnode';
import { selectorParser } from './selectorParser';

@@ -7,9 +7,9 @@ import { classNameFromVNode } from './classNameFromVNode';

export const language = cssauron({
tag: (vNode: snabbdom.VNode) => selectorParser(vNode).tagName,
class: (vNode: snabbdom.VNode) => classNameFromVNode(vNode),
id: (vNode: snabbdom.VNode) => selectorParser(vNode).id,
children: (vNode: snabbdom.VNode) => vNode.children || [],
parent: (vNode: snabbdom.VNode) => (vNode.data as any).parent || vNode,
contents: (vNode: snabbdom.VNode) => vNode.text,
attr (vNode: snabbdom.VNode, attr: string) {
tag: (vNode: VNode) => selectorParser(vNode).tagName,
class: (vNode: VNode) => classNameFromVNode(vNode),
id: (vNode: VNode) => selectorParser(vNode).id,
children: (vNode: VNode) => vNode.children || [],
parent: (vNode: VNode) => (vNode.data as any).parent || vNode,
contents: (vNode: VNode) => vNode.text,
attr (vNode: VNode, attr: string) {
if (vNode.data) {

@@ -16,0 +16,0 @@ const { attrs = {}, props = {} } = vNode.data;

@@ -1,12 +0,14 @@

import * as snabbdom from 'snabbdom';
import { VNode } from 'snabbdom/vnode';
export function selectorParser ({ sel }: snabbdom.VNode) {
const hashIdx = sel.indexOf('#');
const dotIdx = sel.indexOf('.', hashIdx);
const hash = hashIdx > 0 ? hashIdx : sel.length;
const dot = dotIdx > 0 ? dotIdx : sel.length;
export function selectorParser ({ sel }: VNode) {
const hashIdx = (sel as string).indexOf('#');
const dotIdx = (sel as string).indexOf('.', hashIdx);
const hash = hashIdx > 0 ? hashIdx : (sel as string).length;
const dot = dotIdx > 0 ? dotIdx : (sel as string).length;
const tagName = hashIdx !== -1 || dotIdx !== -1 ? sel.slice(0, Math.min(hash, dot)) : sel;
const id = hash < dot ? sel.slice(hash + 1, dot) : void 0;
const className = dotIdx > 0 ? sel.slice(dot + 1).replace(/\./g, ' ') : void 0;
const tagName = hashIdx !== -1 || dotIdx !== -1 ?
(sel as string).slice(0, Math.min(hash, dot)) :
sel as string;
const id = hash < dot ? (sel as string).slice(hash + 1, dot) : void 0;
const className = dotIdx > 0 ? (sel as string).slice(dot + 1).replace(/\./g, ' ') : void 0;

@@ -13,0 +15,0 @@ return {

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

import * as snabbdom from 'snabbdom';
import { VNode } from 'snabbdom/vnode';
export interface Selector {
(selector: string, vNode: snabbdom.VNode): Array<snabbdom.VNode>;
(selector: string): (vNode: snabbdom.VNode) => Array<snabbdom.VNode>;
(selector: string, vNode: VNode): Array<VNode>;
(selector: string): (vNode: VNode) => Array<VNode>;
}
export type Select =
(selector: string, vNode: snabbdom.VNode) => snabbdom.VNode[];
(selector: string, vNode: VNode) => Array<VNode>;
import * as assert from 'assert';
import { select } from '../src';
import snabbdom = require('snabbdom');
import { VNode } from 'snabbdom/vnode';
import h from 'snabbdom/h';
import thunk from 'snabbdom/thunk';
type hyperscript =
(selector: string, data: any,
children: snabbdom.VNode[] | string | undefined) => snabbdom.VNode;
const h: hyperscript = require('snabbdom/h');
type thunkHelper =
(selector: string, key: string,
render: (...args: any[]) => snabbdom.VNode,
...args: any[]) => snabbdom.VNode
const thunk: thunkHelper = require('snabbdom/thunk');
function div (children: snabbdom.VNode[] = []): snabbdom.VNode {
function div (children: VNode[] = []): VNode {
return h('div', {}, children);

@@ -61,3 +50,2 @@ }

it('should return a vNode by className from class module', () => {

@@ -120,3 +108,2 @@ const vNode = h('div', { class: { test: true } }, []);

const result = select('div + .foo', vNode);

@@ -149,3 +136,3 @@ assert.strictEqual(result[0].sel, 'p.foo');

const vNode = h('div#test', {}, [
thunk('div', 'thunk', exampleThunk, 7),
thunk('div', 'thunk', exampleThunk, [7]),
]);

@@ -189,3 +176,3 @@

it('should match using `:nth-child`', () => {
let children: snabbdom.VNode[] = [];
let children: VNode[] = [];
for (let i = 0; i < 40; ++i) {

@@ -192,0 +179,0 @@ children[i] = h('p', {}, `${i}`);

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