Socket
Socket
Sign inDemoInstall

jiq

Package Overview
Dependencies
3
Maintainers
1
Versions
10
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 0.0.2 to 0.0.3

2

build/index.js

@@ -78,3 +78,3 @@ #!/usr/bin/env node

;
commander_1.program.version("0.0.2");
commander_1.program.version("0.0.3");
commander_1.program

@@ -81,0 +81,0 @@ .option('--json', 'tell the program it\'s json content')

@@ -35,2 +35,3 @@ "use strict";

fs_1.writeFileSync(filename, yaml_1.default.stringify(data));
return;
}

@@ -37,0 +38,0 @@ let text = '';

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

let out = '';
if (command[0] === '.') {
if (command[0] === '.' || command[0] === '[') {
command = '$' + command;

@@ -9,0 +9,0 @@ }

{
"name": "jiq",
"version": "0.0.2",
"version": "0.0.3",
"description": "Use existing javascript knowledge to query or mutate data",
"keywords": ["javascript inline query", "json query", "json inline query", "json", "yaml", "query"],
"keywords": [
"javascript inline query",
"json query",
"json inline query",
"json",
"yaml",
"query"
],
"main": "build/index.js",

@@ -7,0 +14,0 @@ "author": {

# Javascript Inline Query (jiq)
#### JSON querying with javascript and lodash
## Installation
## Installation
npm -g install jiq
or

@@ -11,7 +12,5 @@

> Concept: use existing javascript knowledge to query or mutate data
## Let's start

@@ -24,8 +23,133 @@

### Use Case
We have a file
package.json
```json
{
"name": "jiq",
"version": "0.0.2",
"description": "Use existing javascript knowledge to query or mutate data",
"keywords": ["javascript inline query", "json query", "json inline query", "json", "yaml", "query"],
"main": "build/index.js",
"author": {
"name": "Adil",
"email": "adil.sudo@gmail.com",
"url": "https://md-adil.github.io"
},
"homepage": "https://md-adil.github.io/jiq/",
"repository": {
"url": "https://md-adil.github.io/jiq/",
"type": "git"
},
"license": "MIT",
"scripts": {
"watch": "tsc -w",
"build": "tsc",
"start": "node ./build"
},
"devDependencies": {
"@types/lodash": "^4.14.165",
"@types/node": "^14.14.6"
},
"dependencies": {
"commander": "^6.2.0",
"lodash": "^4.17.20",
"yaml": "^1.10.0"
},
"bin": "./build/index.js"
}
```
Getting name property
jiq '.name' package.json
output
jiq
Getting all dependencies
jiq '.dependencies' package.json
output
```json
{
"commander": "^6.2.0",
"lodash": "^4.17.20",
"yaml": "^1.10.0"
}
```
Getting keys of dependencies object as an array with the help of pipes
jiq '.dependencies|keys' package.json
output
commander
lodash
yaml
Chain with native javascript array functions on output array
jiq '.dependencies|keys|.map(v => v.uppercase)' package.json
output
COMMANDER
LODASH
YAML
Save output to a file
jiq '.dependencies|keys|.map(v => v.uppercase)' package.json --save deps.json
or
jiq '.dependencies|keys|.map(v => v.uppercase)' package.json --save deps.yaml
> data will be converted according to file extension
Some built in helper function for array and string
Getting 2 items from top
jiq '.keywords.head(2)' package.json
output
javascript inline query
json query
### Using `$`
`$` hold current parsed value object
jiq '$' package.json --save package.yaml
Successfully converted json to yaml
## Working on remote files using
curl https://api.github.com/users | jiq --json '.map(x => x.login)'
### explained:
* `curl <url>` to get data from remote
* `jiq --json` to tell jiq the file content is json
* `'.map(x => x.login)'` iterate over array, get the login key and build a new array on top of that.
## Query with lodash
Use `_` as global variable
curl https://api.github.com/users | jiq --json '.map(x => x.login).map(_.upperFirsst)'
curl https://api.github.com/users | jiq --json '.map(x => x.login).map(_.upperFirst)'
## Supported data types
* YAML

@@ -36,25 +160,32 @@ * JSON

### Pipes
keys
values
* keys
* values
### Globals
$ (passed data)
_ (lodash)
* $ (passed data)
* _ (lodash)
### String functions
uppercase
lowercase
camelcase
upperfirst
capitalize
kebabcase
snakecase
limit
words
* uppercase
`'.map(v => v.uppercase)'`
* lowercase `.map(v => v.lowercase)`
* camelcase `.map(v => v.camelcase)`
* upperfirst `.map(v => v.upperfirst)`
* capitalize `.map(v => v.capitalize)`
* kebabcase `.map(v => v.kebabcase)`
* snakecase
* limit `.map(v => v.limit(10))` return max 10 chars
* words
### Array functions
first
last
head
tail
nth
* first
* last
* head(x) get x values from top
* tail(x) get x values from bottom
* nth(x) get x position eg: nth(-2) second last item
Read full [documentation](https://md-adil.github.io/jiq/) here.

@@ -80,3 +80,3 @@ #!/usr/bin/env node

program.version("0.0.2");
program.version("0.0.3");
program

@@ -83,0 +83,0 @@ .option('--json', 'tell the program it\'s json content')

@@ -31,2 +31,3 @@ import { Readable } from "stream";

writeFileSync(filename, YAML.stringify(data));
return;
}

@@ -33,0 +34,0 @@ let text = '';

@@ -5,3 +5,3 @@ import { LoDashStatic } from "lodash";

let out = '';
if (command[0] === '.') {
if (command[0] === '.' || command[0] === '[') {
command = '$' + command;

@@ -8,0 +8,0 @@ }

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc