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

jquery-cli2

Package Overview
Dependencies
Maintainers
1
Versions
4
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

jquery-cli2 - npm Package Compare versions

Comparing version 0.1.1 to 0.2.0

43

lib/cli.js

@@ -14,4 +14,2 @@ // Generated by CoffeeScript 1.8.0

input = '';
program = require('commander');

@@ -21,4 +19,6 @@

program.usage('[--text \'selector\']').option('-t, --text [selector]', 'Output inner text of items, matching the selector').option('-h, --html [selector]', 'Output HTML content of items, matching the selector').option('-c, --count [selector]', 'Output count if items, matching the selector').option('--no-trailing-line-break', 'Don\'t output training line break').version(package_json.version).parse(process.argv);
input = '';
program.option('-s, --selector [selector]', 'Output inner text of items, matching the selector').option('-t, --text', 'Output inner text of items, matching the selector').option('-h, --html', 'Output HTML content of items, matching the selector').option('-c, --count', 'Output count if items, matching the selector').option('-a, --attr [name]', 'Return specific attr value of matched elements').option('-f, --format [name]', 'Allowed formats are \'text\' or \'json\'').option('--no-trailing-line-break', 'Don\'t output training line break').version(package_json.version).parse(process.argv);
process.stdin.setEncoding('utf8');

@@ -35,11 +35,34 @@

process.stdin.on('end', function() {
return jsdom.env(input, ["../node_modules/jquery/dist/jquery.js"], function(errors, window) {
if (program.text != null) {
process.stdout.write(String((window.$(program.text)).text()));
return jsdom.env(input, ['../node_modules/jquery/dist/jquery.js'], function(errors, window) {
var items, result;
if (program.selector == null) {
throw new Error('Please specify a selector. Use -h to show usage information');
}
if (program.html != null) {
process.stdout.write(String((window.$(program.html)).html()));
items = window.$(program.selector);
result = [];
if (items.length > 0) {
items.each(function() {
if (program.count != null) {
result.push((window.$(this)).length);
}
if (program.text != null) {
result.push((window.$(this)).text());
}
if (program.html != null) {
result.push((window.$(this)).html());
}
if (program.attr != null) {
return result.push((window.$(this)).attr(program.attr));
}
});
}
if (program.count != null) {
process.stdout.write(String((window.$(program.count)).length));
switch (program.format) {
case 'json':
process.stdout.write(JSON.stringify(result));
break;
default:
result.map(function(item) {
return (String(item)).replace(/(\r\n|\n|\r)/gm, '');
});
process.stdout.write(result.join('\n'));
}

@@ -46,0 +69,0 @@ if (program.trailingLineBreak) {

{
"name": "jquery-cli2",
"description": "Query HTML",
"version": "0.1.1",
"version": "0.2.0",
"repository": "https://github.com/muchweb/jquery-cli2",

@@ -6,0 +6,0 @@ "license": "GPL-3.0+",

@@ -16,2 +16,12 @@ # jquery-cli2 [![Build Status](https://travis-ci.org/muchweb/jquery-cli2.svg)](https://travis-ci.org/muchweb/jquery-cli2) [![NPM version](https://badge.fury.io/js/jquery-cli2.svg)](http://badge.fury.io/js/jquery-cli2) ![License: GPLv3+](http://img.shields.io/badge/license-GPLv3%2B-brightgreen.svg)

- Counting items
```bash
cat categories.htm | jquery-cli2 --selector '#menu > ul > li > a' -c | paste -s -d+ | bc
```
```bash
cat categories.htm | jquery-cli2 --selector '#menu > ul > li > a' -c | wc -l
```
- Parse file on disk

@@ -18,0 +28,0 @@

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