Skip to content

A nodejs wasm interface for jaq

License

Notifications You must be signed in to change notification settings

TylerZeroMaster/jaq-node

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

jaq-node

jaq-node is a nodejs wasm interface for jaq.

This interface was adapted from jaq-play.

Usage

import { run } from './jaq_node';

export interface Settings {
  raw_input?: boolean;
  slurp?: boolean;
  null_input?: boolean;
  raw_output?: boolean;
  compact?: boolean;
  indent?: number;
  tab?: boolean;
}

export const newJaqFilter = (settings: Settings = {}) => ({
  query: (filter: string, ...input: unknown[]) =>
    run(filter, input.map((i) => JSON.stringify(i)).join('\n'), settings).map(
      (result: string) => JSON.parse(result),
    ),
  queryRaw: (filter: string, input: string) => run(filter, input, settings),
});

const jaq = newJaqFilter({ compact: true });

const obj = {
  a: {
    b: {
      c: {
        d: 1
      }
    }
  }
};

const d = jaq.query('.. | select(.d? != null)', obj);

console.log(d); // {"d": 1}

You can pass multiple inputs too: an array of outputs is returned.

const firstItems = jaq.query('.[0]', [0], [1], [2], [3]);
console.log(firstItems); // [0,1,2,3]

Build

The build script contains the options I use.

You will need rustc, wasm-pack, and rust-std-wasm32-unknown-unknown.

The Dockerfile should have everything you need. You can run the build script with docker/podman by running ./docker/bash ./scripts/build.bash.

The build script accepts a single argument: the profile (dev or release).

About

A nodejs wasm interface for jaq

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors