New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

tree-selector

Package Overview
Dependencies
Maintainers
1
Versions
8
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

tree-selector - npm Package Compare versions

Comparing version 1.2.0 to 2.0.0

.nyc_output/8abf0abee97cbddef5881c45d73b3af2.json

5

lib/cjs/matches.js

@@ -26,5 +26,8 @@ "use strict";

var v = attributes[key][1];
if (!attr) {
if (attr === undefined) {
return false;
}
if (t === 'has') {
return true;
}
if (t === 'exact' && attr !== v) {

@@ -31,0 +34,0 @@ return false;

2

lib/cjs/selectorParser.d.ts

@@ -13,3 +13,3 @@ export interface Selector {

}
export declare type AttributeMatch = 'exact' | 'truthy' | 'startsWith' | 'endsWith' | 'contains' | 'whitespace' | 'dash';
export declare type AttributeMatch = 'exact' | 'has' | 'startsWith' | 'endsWith' | 'contains' | 'whitespace' | 'dash';
export declare type Combinator = 'subtree' | 'child' | 'nextSibling' | 'sibling';

@@ -16,0 +16,0 @@ /**

@@ -78,6 +78,6 @@ "use strict";

var attr = _a[0], op = _a[1], val = _a[2];
var _b;
return (_b = {},
_b[attr] = [getOp(op), val ? parseAttrValue(val) : val],
_b);
var _b;
})

@@ -149,3 +149,3 @@ .reduce(function (acc, curr) { return (__assign({}, acc, curr)); }, {});

default:
return 'truthy';
return 'has';
}

@@ -152,0 +152,0 @@ }

@@ -24,5 +24,8 @@ import { parseSelector } from './selectorParser';

var v = attributes[key][1];
if (!attr) {
if (attr === undefined) {
return false;
}
if (t === 'has') {
return true;
}
if (t === 'exact' && attr !== v) {

@@ -29,0 +32,0 @@ return false;

@@ -13,3 +13,3 @@ export interface Selector {

}
export declare type AttributeMatch = 'exact' | 'truthy' | 'startsWith' | 'endsWith' | 'contains' | 'whitespace' | 'dash';
export declare type AttributeMatch = 'exact' | 'has' | 'startsWith' | 'endsWith' | 'contains' | 'whitespace' | 'dash';
export declare type Combinator = 'subtree' | 'child' | 'nextSibling' | 'sibling';

@@ -16,0 +16,0 @@ /**

@@ -76,6 +76,6 @@ var __assign = (this && this.__assign) || Object.assign || function(t) {

var attr = _a[0], op = _a[1], val = _a[2];
var _b;
return (_b = {},
_b[attr] = [getOp(op), val ? parseAttrValue(val) : val],
_b);
var _b;
})

@@ -146,3 +146,3 @@ .reduce(function (acc, curr) { return (__assign({}, acc, curr)); }, {});

default:
return 'truthy';
return 'has';
}

@@ -149,0 +149,0 @@ }

{
"name": "tree-selector",
"version": "1.2.0",
"version": "2.0.0",
"description": "Use CSS selectors to match nodes in a custom object tree",

@@ -53,3 +53,4 @@ "main": "lib/cjs/index.js",

"@types/mocha": "^5.2.0",
"@types/node": "^9.6.7",
"@types/node": "^9.6.31",
"get-permutations": "^1.0.0",
"mocha": "^5.1.1",

@@ -56,0 +57,0 @@ "nyc": "^11.7.1",

@@ -35,5 +35,8 @@ import { Options } from './types';

if (!attr) {
if (attr === undefined) {
return false;
}
if (t === 'has') {
return true;
}
if (t === 'exact' && attr !== v) {

@@ -40,0 +43,0 @@ return false;

@@ -24,3 +24,3 @@ export interface Selector {

| 'exact'
| 'truthy'
| 'has'
| 'startsWith'

@@ -191,3 +191,3 @@ | 'endsWith'

default:
return 'truthy';
return 'has';
}

@@ -194,0 +194,0 @@ }

@@ -55,2 +55,20 @@ import { createMatches } from '../src/index';

it('should match against a falsy attribute selector', () => {
const testElement = {
tag: 'div',
className: 'foo bar baz',
attributes: {
test: '',
bar: false,
zuz: 'bar loo goo'
}
};
assert.equal(
matches('[test][bar][zuz~="loo"]', testElement),
true
);
});
it('should not match against an attribute selector', () => {

@@ -57,0 +75,0 @@ const testElement = {

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

import * as permutations from 'get-permutations';
import { parseSelector } from '../src/index';
import { permutations } from './utils';
import * as assert from 'assert';
const assert = require('assert');
describe('parseSelector', () => {

@@ -11,6 +10,4 @@ it('should parse all permutations of a selector', () => {

'.class1',
'.class3',
'#id',
'[attr]',
'[attr2="foo"]',
'[attr3*= "foo"]',

@@ -21,11 +18,11 @@ '[ attr4 ]',

const expected = {
classList: ['class1', 'class2', 'class3'],
classList: ['class1', 'class2'],
id: 'id',
tag: '',
pseudos: [],
nextSelector: undefined,
attributes: {
attr: ['truthy', undefined],
attr2: ['exact', 'foo'],
attr: ['has', undefined],
attr3: ['contains', 'foo'],
attr4: ['truthy', undefined],
attr4: ['has', undefined],
attr5: ['dash', ' ']

@@ -58,7 +55,4 @@ }

'.class2',
'.class1',
'.class3',
'#id',
'[attr',
'[attr2="foo"]',
'[attr3*= "foo"]',

@@ -65,0 +59,0 @@ ' attr4 ]',

import { VNode } from './vnode';
export function permutations<T>(arr: T[]): T[][] {
return arr
.map(e => permutations(arr.slice(1)).map(arr => [e].concat(arr)))
.reduce((acc, curr) => acc.concat(curr), []);
}
export function addParents(node: VNode): VNode {

@@ -10,0 +4,0 @@ node.children = !node.children

@@ -13,4 +13,5 @@ {

"include": [
"src/"
"src/",
"custom-typings.d.ts"
]
}

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

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