Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

a) haystack operators; b) multiline queries #56

Closed
wants to merge 4 commits into from

Conversation

Kevin-Prichard
Copy link
Contributor

@Kevin-Prichard Kevin-Prichard commented Oct 16, 2016

@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

Kevin Prichard added 4 commits October 11, 2016 18:23
…e use.

Seems clear that nested predicates are intended, but they aren't mentioned as a feature -- that's what this commit is for.

Nested predicates gives jspath some additional power that may not be obvious, more than all the other JSON query languages at http://www.jsonquerytool.com/
1) isWhiteSpace() expanded to ' \r\n\t' -allows for multiline queries, because es6 & node.js>4 add the backtick char as a multiline string delimiter)
2) Add ~= / ~== for "left string is substring within right string", plus test and doc.
@dfilatov
Copy link
Owner

Hi, @Kevin-Prichard!

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

@dfilatov
Copy link
Owner

dfilatov commented Jan 6, 2018

All these features implemented in 0.4.0

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants