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

unist-util-select

Package Overview
Dependencies
Maintainers
1
Versions
21
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

unist-util-select - npm Package Compare versions

Comparing version 1.3.0 to 1.4.0

23

index.js
'use strict';
var parseSelector = require('./lib/selector'),
select = require('./lib/select');
matchSelector = require('./lib/select');

@@ -9,3 +9,3 @@ var debug = require('debug')('unist-util-select');

module.exports = function (ast, selector) {
var select = function select (ast, selector) {
debug('Selector: %j', selector);

@@ -15,3 +15,20 @@ selector = parseSelector(selector);

JSON.stringify(selector, null, 2).replace(/(^|\n)/g, '\n '));
return selector ? select[selector.type](selector, ast) : [];
return selector ? matchSelector[selector.type](selector, ast) : [];
};
select.one = function selectOne (ast, selector) {
var nodes = select(ast, selector);
if (!nodes.length) {
throw Error('Node not found by ' + JSON.stringify(selector));
}
if (nodes.length > 1) {
throw Error('Node matched by ' + JSON.stringify(selector) + ' is not unique');
}
return nodes[0];
};
module.exports = select;

5

package.json
{
"name": "unist-util-select",
"version": "1.3.0",
"version": "1.4.0",
"description": "Select unist nodes using css-like selectors",

@@ -48,4 +48,5 @@ "author": "Eugene Sharygin <eush77@gmail.com>",

"devDependencies": {
"tape": "^4.2.0"
"tape": "^4.2.0",
"unist-builder": "^1.0.1"
}
}

@@ -7,4 +7,6 @@ [![npm](https://nodei.co/npm/unist-util-select.png)](https://npmjs.com/package/unist-util-select)

Select unist nodes using css-like selectors.
Select [Unist] nodes with CSS-like selectors.
[unist]: https://github.com/wooorm/unist
[travis]: https://travis-ci.org/eush77/unist-util-select

@@ -30,3 +32,3 @@ [travis-badge]: https://travis-ci.org/eush77/unist-util-select.svg?branch=master

[`mdast`][mdast] takes this Markdown as an input and returns unist syntax tree. After that, we use `unist-util-select` to extract the required parts:
[remark] takes this Markdown as an input and returns unist syntax tree. After that, we use `unist-util-select` to extract the required parts:

@@ -37,3 +39,3 @@ ```js

var markdown = fs.readFileSync('example.md', 'utf8');
var ast = mdast.parse(markdown);
var ast = remark.parse(markdown);

@@ -48,6 +50,10 @@ select(ast, 'list text[value*=TODO]')

[mdast]: https://github.com/wooorm/mdast
[remark]: https://github.com/wooorm/remark
## Features
All the relevant parts of [Selectors Level 3][spec]:
[spec]: http://www.w3.org/TR/css3-selectors/
- [x] Type selectors: `paragraph`

@@ -87,2 +93,8 @@ - [x] Descendant selectors: `paragraph text`

#### `select.one(ast, selector)`
Returns a single node matching `selector`.
Throws an error if node is not found or not unique.
## Install

@@ -89,0 +101,0 @@

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