Coder Social home page Coder Social logo

kosu's Introduction

Kosu

Filter streams according to SIQL queries

Overview

Kosu is an implementation of SIQL in JavaScript, for filtering Node.JS-style streams.

It compiles SIQL queries to JavaScript functions, and wraps them in a duplex stream that filters its input according to the query provided.

A command-line tool is also provided which can filter streams of JSON according to a query. It is intuitively named kosu.

Installation

Available via npm:

$ npm install kosu

Or via git:

$ npm install git://github.com/deoxxa/kosu.git

NOTE: if you want the command-line tool as well, you'll want to add the -g flag to your npm install command.

CLI Tool

$ kosu <query> [input]

The kosu command requires at least a query argument. This argument is JSON, so must be quoted/escaped according to your shell's rules. By default, kosu will read from stdin:

$ cat log.json | kosu '{"condition":{"type":"eq","left":"x","right":5}}'

By supplying a second argument, you can tell kosu to read from a file instead:

$ kosu '{"condition":{"type":"eq","left":"x","right":5}}' ~/log.json

Easy as pie!

API

constructor

Constructs a new Kosu object based on a query.

new Kosu(query);
var kosu = new Kosu({
  condition: {
    type: "eq",
    left: "x",
    right: 1,
  }
});

Arguments

  • query - an object specifying a SIQL query

Example

Also see example.js.

var Kosu = require("kosu");

var query = {
  fields: {
    x: true,
    y: true,
  },
  condition: {type: "and", data: [
    {type: "eq", left: "x", right: 3},
    {type: "and", data: [
      {type: "gt", left: "info.time", right: "2012-08-24T00:00:00.000Z"},
      {type: "lt", left: "info.time", right: "2012-08-24T23:59:59.999Z"},
    ]},
  ]},
};

var kosu = new Kosu(query);

console.warn("compiled filter function:");
console.warn("");
console.warn(kosu.filter.toString());
console.warn("");

console.warn("matching data:");
console.warn("");

kosu.on("data", function(e) {
  console.log(e);
});

kosu.write({x: 3, y: 6});
kosu.write({x: 3, y: 7, info: {time: "2012-08-24T10:00:00.000Z"}});

Output:

compiled filter function:

function anonymous(obj) {
return true && (obj && obj['x']) === 3 && (true && (obj && obj['info'] && obj['info']['time']) > '2012-08-24T00:00:00.000Z' && (obj && obj['info'] && obj['info']['time']) < '2012-08-24T23:59:59.999Z');
}

matching data:

{ x: 3, y: 7 }

License

3-clause BSD. A copy is included with the source.

Contact

kosu's People

Contributors

deoxxa avatar

Stargazers

Eugene Ware avatar

Watchers

 avatar James Cloos avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.