dfilatov / jspath

DSL that enables you to navigate and find data within your JSON documents
MIT License
553 stars 40 forks source link

a) haystack operators; b) multiline queries #56

Closed Kevin-Prichard closed 6 years ago

Kevin-Prichard commented 8 years ago

@dfilatov,

a) My intent with ~=/~== is very simple needle/haystack string search, allowing a program using jspath to supply a concatenated list of values as a single string, into which a single property value must match. Tested with string and numeric properties, nothing more complex.

> jspath.apply(".{.id ~= '"+["Abc","def","GHI"].join(";")+"'}.id", [{id: "abc"}, {id:"ghi"}]);
[ 'abc', 'ghi' ]

This was the simple approach; the alternative is actually searching arrays provided by caller. My suggestion is to add ~=/~==, then later consider array search support, perhaps with an "in" operator.

b) Multiline strings are allowed using a single backtick char, in es6/node 4+. My patch simply extends jspath's definition for whitespace to include newline, return, tab -shouldn't harm anything else. Writing long jspath queries is nicer now, since concatenation isn't needed so much. Really basic example-

> var a = ["Abc","def","GHI"].join(";");
> jspath.apply(`
      .{.id ~= $a}.id
      `,
      [{id: "abc"}, {id:"ghi"}],
      {a: a});
[ 'abc', 'ghi' ]

Cheers, Kevin-Prichard

dfilatov commented 8 years ago

Hi, @Kevin-Prichard!

Good job! But could you split your PR to separate ones? One PR per one feature.

dfilatov commented 6 years ago

All these features implemented in 0.4.0