From 0dc49e0ff6723c87d421f0506d8bc0dda7c9a4c3 Mon Sep 17 00:00:00 2001 From: bglee Date: Sun, 20 May 2018 20:45:03 +0900 Subject: [PATCH] requirement down --- CHANGELOG.md | 4 ++++ README.md | 4 +--- index.ts | 12 ++---------- package.json | 4 ++-- yarn.lock | 16 +++++----------- 5 files changed, 14 insertions(+), 26 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 42d808e..69c6e62 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,7 @@ +## 1.1.0 + +requirement: Node 10 => Node 8 + ## 1.0.0 :tada: diff --git a/README.md b/README.md index 6f28f7f..89ec4b8 100644 --- a/README.md +++ b/README.md @@ -3,8 +3,6 @@ ![hosejs](https://github.com/deptno/hosejs/raw/master/asset/hosejs.gif) -> Required node > v10 - Transform JSON data with just **JavaScript** in terminal `jq`? javascript is clearly better option for people already use javascript. @@ -27,7 +25,7 @@ npm -g install hosejs ## usage -``` +```bash $ cat some.json | j '_.map(x => x.timestamp)' $ cat some.json | j '_.map(x => x.timestamp)' --tab 4 $ cat some.json | j '_.map(x => x.timestamp)' --file pre.js --tab 2 diff --git a/index.ts b/index.ts index 104d6d7..612a75b 100644 --- a/index.ts +++ b/index.ts @@ -1,10 +1,10 @@ #!/usr/bin/env node -import {chomp, chunksToLinesAsync} from '@rauschma/stringio' import {createContext, runInContext} from 'vm' import * as meow from 'meow' import * as fs from 'fs' import {promisify} from 'util' +import * as stdin from 'get-stdin' const program = meow(` HoseJS @@ -29,24 +29,16 @@ const program = meow(` async function main() { const {input, flags} = program const readFile = promisify(fs.readFile) - const stream = process.stdin as any - const lines = [] - if (flags.file) { input.unshift((await readFile(flags.file)).toString()) } - for await (const line of chunksToLinesAsync(stream)) { - lines.push(chomp(line)) - } - try { - const _ = JSON.parse(lines.join('')) + const _ = JSON.parse(await stdin()) const sandbox = {_} createContext(sandbox) runInContext(input.map(c => `_ = ${c}`).join(';'), sandbox) - print(sandbox._, parseInt(flags.tab)) } catch (e) { console.error('🚫', e) diff --git a/package.json b/package.json index 1f75615..32a76b1 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "hosejs", - "version": "1.0.0", + "version": "1.1.0", "description": "javascript pipe, jq alternative", "main": "index.js", "bin": { @@ -14,7 +14,7 @@ "author": "Bonggyun Lee ", "license": "MIT", "dependencies": { - "@rauschma/stringio": "^1.4.0", + "get-stdin": "^6.0.0", "meow": "^5.0.0" }, "devDependencies": { diff --git a/yarn.lock b/yarn.lock index 6855548..c52dc1f 100644 --- a/yarn.lock +++ b/yarn.lock @@ -2,12 +2,6 @@ # yarn lockfile v1 -"@rauschma/stringio@^1.4.0": - version "1.4.0" - resolved "https://registry.yarnpkg.com/@rauschma/stringio/-/stringio-1.4.0.tgz#0b667bea726652a10a48dfc1dadc89e0ec51e269" - dependencies: - "@types/node" "^10.0.3" - "@types/meow@^4.0.1": version "4.0.1" resolved "https://registry.yarnpkg.com/@types/meow/-/meow-4.0.1.tgz#cb80b9f0b8695df7ac15f0165585bcd2d0a6d94f" @@ -24,14 +18,10 @@ version "1.2.0" resolved "https://registry.yarnpkg.com/@types/minimist/-/minimist-1.2.0.tgz#69a23a3ad29caf0097f06eda59b361ee2f0639f6" -"@types/node@^10.0.3", "@types/node@^10.1.0": +"@types/node@^10.1.0": version "10.1.2" resolved "https://registry.yarnpkg.com/@types/node/-/node-10.1.2.tgz#1b928a0baa408fc8ae3ac012cc81375addc147c6" -"@types/ramda@^0.25.28": - version "0.25.29" - resolved "https://registry.yarnpkg.com/@types/ramda/-/ramda-0.25.29.tgz#05a58a3ba728344ecc9d99e37beb2adf822fb01c" - array-find-index@^1.0.1: version "1.0.2" resolved "https://registry.yarnpkg.com/array-find-index/-/array-find-index-1.0.2.tgz#df010aa1287e164bbda6f9723b0a96a1ec4187a1" @@ -85,6 +75,10 @@ find-up@^2.0.0: dependencies: locate-path "^2.0.0" +get-stdin@^6.0.0: + version "6.0.0" + resolved "https://registry.yarnpkg.com/get-stdin/-/get-stdin-6.0.0.tgz#9e09bf712b360ab9225e812048f71fde9c89657b" + graceful-fs@^4.1.2: version "4.1.11" resolved "https://registry.yarnpkg.com/graceful-fs/-/graceful-fs-4.1.11.tgz#0e8bdfe4d1ddb8854d64e04ea7c00e2a026e5658"