npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@northscaler/ymlx

v1.0.1

Published

Command-line YAML processing tool

Downloads

13

Readme

Command-line YAML processing tool

Features

  • Plain JavaScript to manipulate document(s)

Install

$ npm install -g ymlx

Usage

Pipe into ymlx any YAML and anonymous function for reducing it.

$ cat my.yaml | ymlx [code ...]

Anonymous function

Use an anonymous function as reducer which gets YAML as an object and processes it:

$ echo 'foo: [bar: value]' | ymlx 'x => x.foo[0].bar'
value

this Binding

If you don't pass anonymous function param => ..., code will be automatically transformed into anonymous function. And you can get access to YAML by this keyword:

$ echo 'foo: [bar: value]' | ymlx 'this.foo[0].bar'
value

Multiple Documents

You can pass a YAML file with multiple documents (using the --- separator), and your commands will be applied to each document.

# test.yml
---
foo:
- bar: value
---
foo:
- bar: another
$ cat test.yml | ymlx 'this.foo[0].bar'
---
value
---
another

Chain

You can pass any number of anonymous functions for reducing JSON:

$ echo 'foo: [bar: value]' | ymlx 'x => x.foo' 'this[0]' 'this.bar'
value

Generator

If passed code contains yield keyword, generator expression will be used:

$ curl ... | ymlx 'for (let user of this) if (user.login.startsWith("a")) yield user'

Access to YAML through this keyword:

# test.yml
- a
- b
$ cat test.yml | ymlx 'yield* this'
- a
- b
$ cat test.yml | ymlx 'yield* this; yield "c";'
- a
- b
- c

Update

You can update existing YAML using spread operator:

$ echo 'count: 0' | ymlx '{...this, count: 1}'
count: 1

Use npm package

Use any npm package by installing globally or in the current working directory:

$ npm install lodash # -g if you want
$ cat 'count: 0' | ymlx 'require("lodash").keys(this)'
- count

Formatting

$ echo '[1,2,3]' | ymlx 'this.reduce((a,n) => a += n.toString(), "concat: ")'
'concat: 123'

Inspiration

ymlx was inspired by fx

Related

  • jq – cli JSON processor on C
  • jsawk – like awk, but for JSON
  • json – another JSON manipulating cli library
  • jl – functional sed for JSON on Haskell

License

MIT