https://github.com/we-cli/jayin
Piping with js at terminal
https://github.com/we-cli/jayin
cli json lodash pipe
Last synced: 22 days ago
JSON representation
Piping with js at terminal
- Host: GitHub
- URL: https://github.com/we-cli/jayin
- Owner: we-cli
- License: mit
- Created: 2016-05-15T06:37:34.000Z (over 9 years ago)
- Default Branch: dev
- Last Pushed: 2024-11-07T04:03:42.000Z (about 1 year ago)
- Last Synced: 2025-08-24T20:57:16.390Z (4 months ago)
- Topics: cli, json, lodash, pipe
- Language: JavaScript
- Homepage: https://github.com/fritx/jayin
- Size: 40 KB
- Stars: 14
- Watchers: 5
- Forks: 3
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
- awesome-cli-apps-in-a-csv - jayin - Piping with js at terminal. (<a name="data-management-json"></a>Data management - JSON/YAML/etc.)
- awesome-cli-apps - jayin - Piping with js at terminal. (<a name="data-management-json"></a>Data management - JSON/YAML/etc.)
README
# jayin
[](https://github.com/fritx/jayin/actions/workflows/unit-test.yml)
[](https://github.com/fritx/jayin/actions/workflows/unit-test.yml) [](https://github.com/fritx/jayin/actions/workflows/e2e-test.yml)
Let's say you have a gitignore-like file:
```plain
# https://github.com/fritx/dotfiles
# .gitignore
*
!.gitignore
!README.md
!prs-welcome.svg
!.bashrc
!.bash_profile
!.exports
!.aliases
!.editorconfig
```
You want to cp the listed files to another folder.
Do it in bash?
```shell
files=$(cat .gitignore | sed /^\*$/d | sed s/\!//)
for file in $files; do cp $file ./dotfiles/; done
# or even
cat file | sed /^\*$/d | sed s/\!// \
| while read -r file; do cp $file ./dotfiles/; done
# thanks to @congeec, http://v2ex.com/t/278831#reply3
sed /^\*$/d .gitignore | sed s/\!// | xargs -I{} cp {} ./dotfiles/
```
WTF?
As a node.js developer, what if using just js flow/style?
```shell
cat .gitignore | js -ti 'x.trim().split(`\n`).slice(1).map(x => x.slice(1))' \
| js -e 'exec(`cp ${x} ./dotfiles/`)'
# same as
cat .gitignore | js -ti 'x.trim().split(`\n`)' \
| js 'x.slice(1)' \
| js 'x.map(x => x.slice(1))' \
| js -e -c 'cp ${x} ./dotfiles/'
```
```shell
# lodash is also integrated in
# https://github.com/lodash/lodash
echo '[1,2,3,4]' | js '_.filter(x, x => x % 2)' \
| js '_.reverse(x)' \
> file
# or in chain
echo '[1,2,3,4]' \
| js '_(x).filter(x => x % 2).reverse().value()' \
> file
```
Don't forget to take an alias if you want.
```shell
npm install -g jayin
alias js="jayin"
```
- `-ti`: input as text, no more JSON.parse
- `-to`: output as text, no more JSON.stringify
- `-t`: input/output both as text
- `-e`: for each, in chain
- `-c`: shortcut of exec(cmd)
- `x`: current input value
- `i`: current index value (with -e)
- `_`: lodash
- `exec(cmd)`: child_process.execSync(cmd)
jayin is based on [through2](https://github.com/rvagg/through2).
If you've seen anything that is similar to this, don't hesitate to let me know ;)
## Compatibility
| os | Windows | Ubuntu | MacOS |
|:---:|:---:|:---:|:---:|
| supported | ✅ | ✅ | ✅ |
| node | 4 | 6 | 8 | 10 | 12 | 14 | 16 | 18 |
|:---:|:---:|:---:|:---:|:---:|:---:|:---:|:---:|:---:|
| supported | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ |
See also: [.github/workflows/](https://github.com/fritx/jayin/blob/dev/.github/workflows/)
## License
[MIT](https://github.com/fritx/jayin/blob/dev/LICENSE) License
Copyright (c) 2016-Present [Fritz Lin](https://github.com/fritx)
