-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
25 changed files
with
225 additions
and
79 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,13 @@ | ||
/// A collection of semi-useful non-standard functions for JSONPath. | ||
library fun_extra; | ||
|
||
export 'package:json_path/src/fun/extra/index.dart'; | ||
export 'package:json_path/src/fun/extra/is_array.dart'; | ||
export 'package:json_path/src/fun/extra/is_boolean.dart'; | ||
export 'package:json_path/src/fun/extra/is_number.dart'; | ||
export 'package:json_path/src/fun/extra/is_object.dart'; | ||
export 'package:json_path/src/fun/extra/is_string.dart'; | ||
export 'package:json_path/src/fun/extra/key.dart'; | ||
export 'package:json_path/src/fun/extra/reverse.dart'; | ||
export 'package:json_path/src/fun/extra/siblings.dart'; | ||
export 'package:json_path/src/fun/extra/xor.dart'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
import 'package:json_path/fun_sdk.dart'; | ||
|
||
/// Returns the index under which the node referenced by the argument | ||
/// is found in the parent array. | ||
/// If the parent is not an array, returns [Nothing]. | ||
/// If the argument does not reference a single node, returns [Nothing]. | ||
class Index implements Fun1<Maybe, SingularNodeList> { | ||
const Index(); | ||
|
||
@override | ||
final name = 'index'; | ||
|
||
@override | ||
Maybe call(SingularNodeList nodes) => Just(nodes.node?.index).type<int>(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
import 'package:json_path/fun_sdk.dart'; | ||
|
||
/// Returns the key under which the node referenced by the argument | ||
/// is found in the parent object. | ||
/// If the parent is not an object, returns [Nothing]. | ||
/// If the argument does not reference a single node, returns [Nothing]. | ||
class Key implements Fun1<Maybe, SingularNodeList> { | ||
const Key(); | ||
|
||
@override | ||
final name = 'key'; | ||
|
||
@override | ||
Maybe call(SingularNodeList nodes) => Just(nodes.node?.key).type<String>(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
{ | ||
"tests": [ | ||
{ | ||
"name": "count(siblings(@))", | ||
"selector" : "$..[?count(siblings(@)) == 1]", | ||
"document" : {"a": {"b": "x", "d": "x"}}, | ||
"result": ["x", "x"] | ||
} | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
{ | ||
"tests": [ | ||
{ | ||
"name": "index()", | ||
"selector" : "$[?index(@) == 1]", | ||
"document" : [ "A", "B"], | ||
"result": ["B"] | ||
}, | ||
{ | ||
"name": "index(), does not work on objects", | ||
"selector" : "$[?index(@) == 0]", | ||
"document" : {"0": "A", "1": "B"}, | ||
"result": [] | ||
}, | ||
{ | ||
"name": "index(), non singular", | ||
"selector" : "$[?index(@.*) == 0]", | ||
"invalid_selector": true | ||
} | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
|
||
{ | ||
"tests": [ | ||
{ | ||
"name": "is_array(@)", | ||
"selector" : "$[?is_array(@)]", | ||
"document" : [1, true, {}, [42], "foo", {"a": "b"}], | ||
"result": [[42]] | ||
} | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
{ | ||
"tests": [ | ||
{ | ||
"name": "is_boolean", | ||
"selector" : "$[?is_boolean(@)]", | ||
"document" : [1, true, {}, [42], "foo", {"a": "b"}, false], | ||
"result": [true, false] | ||
} | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
{ | ||
"tests": [ | ||
{ | ||
"name": "is_number", | ||
"selector" : "$[?is_number(@)]", | ||
"document" : [1, true, {}, [42], 3.14, "foo", {"a": "b"}], | ||
"result": [1, 3.14] | ||
} | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
{ | ||
"tests": [ | ||
{ | ||
"name": "is_object(@)", | ||
"selector" : "$[?is_object(@)]", | ||
"document" : [1, true, {}, [42], "foo", {"a": "b"}], | ||
"result": [{}, {"a": "b"}] | ||
} | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
{ | ||
"tests": [ | ||
{ | ||
"name": "is_string", | ||
"selector" : "$[?is_string(@)]", | ||
"document" : [1, true, {}, [42], "foo", {"a": "b"}], | ||
"result": ["foo"] | ||
} | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
{ | ||
"tests": [ | ||
{ | ||
"name": "key()", | ||
"selector" : "$[?key(@) == 'a']", | ||
"document" : {"a": "A", "b": "B"}, | ||
"result": ["A"] | ||
}, | ||
{ | ||
"name": "key(), palindromic keys", | ||
"selector" : "$[?key(@) == reverse(key(@))]", | ||
"document" : {"foo": "FOO", "bar": "BAR", "bab": "BAB", "": "", "a": "A"}, | ||
"result": ["BAB","","A"] | ||
}, | ||
{ | ||
"name": "key(), does not work on arrays", | ||
"selector" : "$[?key(@) == 0]", | ||
"document" : ["A", "B"], | ||
"result": [] | ||
}, | ||
{ | ||
"name": "key(), non singular", | ||
"selector" : "$[?key(@.*) == 'a']", | ||
"invalid_selector": true | ||
} | ||
] | ||
} |
Oops, something went wrong.