Skip to content

Commit 28e7dab

Browse files
committed
Merge pull request #24 from hbi99/insensitive-contains
Insensitive contains
2 parents d21e43e + 5e8d754 commit 28e7dab

File tree

12 files changed

+879
-50
lines changed

12 files changed

+879
-50
lines changed

README.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,3 +60,7 @@ console.log( res );
6060
// The Usual Suspects<br>Pulp Fiction<br>Independence Day<br>
6161
</script>
6262
```
63+
64+
### Changelog
65+
* `1.2.2` The XPath method 'contains' is automatically case insensitive
66+
* `1.2.0` Added snapshot search feature

demo/json-search-5.htm

Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
<!doctype html>
2+
<html>
3+
<head>
4+
<meta charset="utf-8">
5+
<meta http-equiv="X-UA-Compatible" content="IE=10">
6+
<title>Defiant.js</title>
7+
<script type="text/javascript" src="/defiant.js/src/defiant.js"></script>
8+
<script type="text/javascript" src="/defiant.js/src/string.js"></script>
9+
<script type="text/javascript" src="/defiant.js/src/ie.polyfill.js"></script>
10+
<script type="text/javascript" src="/defiant.js/src/json.js"></script>
11+
<script type="text/javascript" src="/defiant.js/src/json.search.js"></script>
12+
<script type="text/javascript" src="/defiant.js/src/json.toXML.js"></script>
13+
<script type="text/javascript" src="/defiant.js/src/json.mtrace.js"></script>
14+
<script type="text/javascript" src="/defiant.js/src/node.toJSON.js"></script>
15+
<script type="text/javascript" src="/defiant.js/src/node.select.js"></script>
16+
<script type="text/javascript" src="/defiant.js/src/node.serialize.js"></script>
17+
</head>
18+
<body>
19+
20+
<script type="text/javascript">
21+
22+
var test = {
23+
init: function(data) {
24+
var found;
25+
26+
// instead of writing this XPath
27+
found = JSON.search(data, "//*[contains(translate(title, 'ABCDEFGHIJKLMNOPQRSTUVWXYZ', 'abcdefghijklmnopqrstuvwxyz'), 'rings')]/title");
28+
// ...do like this instead. Defiant will make 'contains' case insensitive automatically
29+
found = JSON.search(data, "//*[contains(title, 'rings')]/title");
30+
31+
console.log( found );
32+
33+
34+
// case insensitive 'contains' on keys
35+
found = JSON.search(data, "//*[contains(name(), 'title')]");
36+
37+
console.log( found );
38+
}
39+
};
40+
41+
test.init({
42+
"store": {
43+
"book": [
44+
{
45+
"@price": 12.99,
46+
"title": "Sword of Honour",
47+
"category": "fiction",
48+
"author": "Evelyn Waugh"
49+
},
50+
{
51+
"@price": 8.99,
52+
"title": "Moby Dick",
53+
"category": "fiction",
54+
"author": "Herman Melville",
55+
"isbn": "0-553-21311-3"
56+
},
57+
{
58+
"@price": 8.95,
59+
"Title": "Sayings of the Century", // <-- notice that the key starts with uppercase character
60+
"category": "reference",
61+
"author": "Nigel Rees"
62+
},
63+
{
64+
"@price": 22.99,
65+
"title": "The Lord of the Rings",
66+
"category": "fiction",
67+
"author": "J. R. R. Tolkien",
68+
"isbn": "0-395-19395-8"
69+
}
70+
],
71+
"bicycle": {
72+
"@price": 19.95,
73+
"brand": "Cannondale",
74+
"color": "red"
75+
}
76+
}
77+
});
78+
79+
</script>
80+
81+
</body>
82+
</html>

demo/tmp.js

Lines changed: 35 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -1,37 +1,37 @@
11
test.init({
2-
"store": {
3-
"book": [
4-
{
5-
"@price": 12.99,
6-
"title": "Sword of Honour",
7-
"category": "fiction",
8-
"author": "Evelyn Waugh"
9-
},
10-
{
11-
"@price": 8.99,
12-
"title": "Moby Dick",
13-
"category": "fiction",
14-
"author": "Herman Melville",
15-
"isbn": "0-553-21311-3"
16-
},
17-
{
18-
"@price": 8.95,
19-
"title": "Sayings of the Century",
20-
"category": "reference",
21-
"author": "Nigel Rees"
22-
},
23-
{
24-
"@price": 22.99,
25-
"title": "The Lord of the Rings",
26-
"category": "fiction",
27-
"author": "J. R. R. Tolkien",
28-
"isbn": "0-395-19395-8"
29-
}
30-
],
31-
"bicycle": {
32-
"@price": 19.95,
33-
"brand": "Cannondale",
34-
"color": "red"
35-
}
36-
}
2+
"store": {
3+
"book": [
4+
{
5+
"@price": 12.99,
6+
"title": "Sword of Honour",
7+
"category": "fiction",
8+
"author": "Evelyn Waugh"
9+
},
10+
{
11+
"@price": 8.99,
12+
"title": "Moby Dick",
13+
"category": "fiction",
14+
"author": "Herman Melville",
15+
"isbn": "0-553-21311-3"
16+
},
17+
{
18+
"@price": 8.95,
19+
"title": "Sayings of the Century",
20+
"category": "reference",
21+
"author": "Nigel Rees"
22+
},
23+
{
24+
"@price": 22.99,
25+
"title": "The Lord of the Rings",
26+
"category": "fiction",
27+
"author": "J. R. R. Tolkien",
28+
"isbn": "0-395-19395-8"
29+
}
30+
],
31+
"bicycle": {
32+
"@price": 19.95,
33+
"brand": "Cannondale",
34+
"color": "red"
35+
}
36+
}
3737
});

0 commit comments

Comments
 (0)