1.1.3
This commit is contained in:
parent
01ca521789
commit
c30ed398e3
14 changed files with 962 additions and 33 deletions
10
README.md
10
README.md
|
@ -48,22 +48,26 @@ Simpler version of search using a custom function in the chain.
|
||||||
|
|
||||||
#### Sort
|
#### Sort
|
||||||
|
|
||||||
|
```
|
||||||
|
.sort((a, b) => a > b)
|
||||||
|
```
|
||||||
|
|
||||||
##### By Boolean
|
##### By Boolean
|
||||||
|
|
||||||
```javascript
|
```javascript
|
||||||
.sort('isActiveUser', true)
|
.sortBy('isActiveUser')
|
||||||
```
|
```
|
||||||
|
|
||||||
##### By String
|
##### By String
|
||||||
|
|
||||||
```javascript
|
```javascript
|
||||||
.sort('name')
|
.sortBy('name')
|
||||||
```
|
```
|
||||||
|
|
||||||
##### By Number
|
##### By Number
|
||||||
|
|
||||||
```javascript
|
```javascript
|
||||||
.sort('netWorth')
|
.sortBy('netWorth')
|
||||||
```
|
```
|
||||||
|
|
||||||
#### Pagination
|
#### Pagination
|
||||||
|
|
38
coverage/clover.xml
Normal file
38
coverage/clover.xml
Normal file
|
@ -0,0 +1,38 @@
|
||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<coverage generated="1519920665551" clover="3.2.0">
|
||||||
|
<project timestamp="1519920665551" name="All files">
|
||||||
|
<metrics statements="28" coveredstatements="28" conditionals="12" coveredconditionals="11" methods="12" coveredmethods="12" elements="52" coveredelements="51" complexity="0" loc="28" ncloc="28" packages="1" files="1" classes="1">
|
||||||
|
<file name="index.js" path="/Users/sharpshark28/web/json-query-chain/index.js">
|
||||||
|
<metrics statements="28" coveredstatements="28" conditionals="12" coveredconditionals="11" methods="12" coveredmethods="12"/>
|
||||||
|
<line num="1" count="1" type="stmt"/>
|
||||||
|
<line num="3" count="12" type="stmt"/>
|
||||||
|
<line num="4" count="108" type="stmt"/>
|
||||||
|
<line num="5" count="108" type="stmt"/>
|
||||||
|
<line num="10" count="12" type="stmt"/>
|
||||||
|
<line num="14" count="1" type="stmt"/>
|
||||||
|
<line num="15" count="1" type="stmt"/>
|
||||||
|
<line num="19" count="9" type="stmt"/>
|
||||||
|
<line num="20" count="1" type="stmt"/>
|
||||||
|
<line num="24" count="3" type="cond" truecount="2" falsecount="0"/>
|
||||||
|
<line num="26" count="18" type="stmt"/>
|
||||||
|
<line num="27" count="2" type="stmt"/>
|
||||||
|
<line num="29" count="1" type="stmt"/>
|
||||||
|
<line num="30" count="9" type="stmt"/>
|
||||||
|
<line num="31" count="9" type="cond" truecount="2" falsecount="0"/>
|
||||||
|
<line num="32" count="9" type="stmt"/>
|
||||||
|
<line num="33" count="9" type="stmt"/>
|
||||||
|
<line num="35" count="1" type="stmt"/>
|
||||||
|
<line num="37" count="3" type="stmt"/>
|
||||||
|
<line num="41" count="4" type="stmt"/>
|
||||||
|
<line num="42" count="48" type="cond" truecount="2" falsecount="0"/>
|
||||||
|
<line num="43" count="38" type="cond" truecount="2" falsecount="0"/>
|
||||||
|
<line num="44" count="11" type="stmt"/>
|
||||||
|
<line num="46" count="4" type="stmt"/>
|
||||||
|
<line num="50" count="4" type="stmt"/>
|
||||||
|
<line num="51" count="4" type="stmt"/>
|
||||||
|
<line num="52" count="4" type="stmt"/>
|
||||||
|
<line num="53" count="4" type="stmt"/>
|
||||||
|
</file>
|
||||||
|
</metrics>
|
||||||
|
</project>
|
||||||
|
</coverage>
|
2
coverage/coverage-final.json
Normal file
2
coverage/coverage-final.json
Normal file
File diff suppressed because one or more lines are too long
212
coverage/lcov-report/base.css
Normal file
212
coverage/lcov-report/base.css
Normal file
|
@ -0,0 +1,212 @@
|
||||||
|
body, html {
|
||||||
|
margin:0; padding: 0;
|
||||||
|
height: 100%;
|
||||||
|
}
|
||||||
|
body {
|
||||||
|
font-family: Helvetica Neue, Helvetica, Arial;
|
||||||
|
font-size: 14px;
|
||||||
|
color:#333;
|
||||||
|
}
|
||||||
|
.small { font-size: 12px; }
|
||||||
|
*, *:after, *:before {
|
||||||
|
-webkit-box-sizing:border-box;
|
||||||
|
-moz-box-sizing:border-box;
|
||||||
|
box-sizing:border-box;
|
||||||
|
}
|
||||||
|
h1 { font-size: 20px; margin: 0;}
|
||||||
|
h2 { font-size: 14px; }
|
||||||
|
pre {
|
||||||
|
font: 12px/1.4 Consolas, "Liberation Mono", Menlo, Courier, monospace;
|
||||||
|
margin: 0;
|
||||||
|
padding: 0;
|
||||||
|
-moz-tab-size: 2;
|
||||||
|
-o-tab-size: 2;
|
||||||
|
tab-size: 2;
|
||||||
|
}
|
||||||
|
a { color:#0074D9; text-decoration:none; }
|
||||||
|
a:hover { text-decoration:underline; }
|
||||||
|
.strong { font-weight: bold; }
|
||||||
|
.space-top1 { padding: 10px 0 0 0; }
|
||||||
|
.pad2y { padding: 20px 0; }
|
||||||
|
.pad1y { padding: 10px 0; }
|
||||||
|
.pad2x { padding: 0 20px; }
|
||||||
|
.pad2 { padding: 20px; }
|
||||||
|
.pad1 { padding: 10px; }
|
||||||
|
.space-left2 { padding-left:55px; }
|
||||||
|
.space-right2 { padding-right:20px; }
|
||||||
|
.center { text-align:center; }
|
||||||
|
.clearfix { display:block; }
|
||||||
|
.clearfix:after {
|
||||||
|
content:'';
|
||||||
|
display:block;
|
||||||
|
height:0;
|
||||||
|
clear:both;
|
||||||
|
visibility:hidden;
|
||||||
|
}
|
||||||
|
.fl { float: left; }
|
||||||
|
@media only screen and (max-width:640px) {
|
||||||
|
.col3 { width:100%; max-width:100%; }
|
||||||
|
.hide-mobile { display:none!important; }
|
||||||
|
}
|
||||||
|
|
||||||
|
.quiet {
|
||||||
|
color: #7f7f7f;
|
||||||
|
color: rgba(0,0,0,0.5);
|
||||||
|
}
|
||||||
|
.quiet a { opacity: 0.7; }
|
||||||
|
|
||||||
|
.fraction {
|
||||||
|
font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace;
|
||||||
|
font-size: 10px;
|
||||||
|
color: #555;
|
||||||
|
background: #E8E8E8;
|
||||||
|
padding: 4px 5px;
|
||||||
|
border-radius: 3px;
|
||||||
|
vertical-align: middle;
|
||||||
|
}
|
||||||
|
|
||||||
|
div.path a:link, div.path a:visited { color: #333; }
|
||||||
|
table.coverage {
|
||||||
|
border-collapse: collapse;
|
||||||
|
margin: 10px 0 0 0;
|
||||||
|
padding: 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
table.coverage td {
|
||||||
|
margin: 0;
|
||||||
|
padding: 0;
|
||||||
|
vertical-align: top;
|
||||||
|
}
|
||||||
|
table.coverage td.line-count {
|
||||||
|
text-align: right;
|
||||||
|
padding: 0 5px 0 20px;
|
||||||
|
}
|
||||||
|
table.coverage td.line-coverage {
|
||||||
|
text-align: right;
|
||||||
|
padding-right: 10px;
|
||||||
|
min-width:20px;
|
||||||
|
}
|
||||||
|
|
||||||
|
table.coverage td span.cline-any {
|
||||||
|
display: inline-block;
|
||||||
|
padding: 0 5px;
|
||||||
|
width: 100%;
|
||||||
|
}
|
||||||
|
.missing-if-branch {
|
||||||
|
display: inline-block;
|
||||||
|
margin-right: 5px;
|
||||||
|
border-radius: 3px;
|
||||||
|
position: relative;
|
||||||
|
padding: 0 4px;
|
||||||
|
background: #333;
|
||||||
|
color: yellow;
|
||||||
|
}
|
||||||
|
|
||||||
|
.skip-if-branch {
|
||||||
|
display: none;
|
||||||
|
margin-right: 10px;
|
||||||
|
position: relative;
|
||||||
|
padding: 0 4px;
|
||||||
|
background: #ccc;
|
||||||
|
color: white;
|
||||||
|
}
|
||||||
|
.missing-if-branch .typ, .skip-if-branch .typ {
|
||||||
|
color: inherit !important;
|
||||||
|
}
|
||||||
|
.coverage-summary {
|
||||||
|
border-collapse: collapse;
|
||||||
|
width: 100%;
|
||||||
|
}
|
||||||
|
.coverage-summary tr { border-bottom: 1px solid #bbb; }
|
||||||
|
.keyline-all { border: 1px solid #ddd; }
|
||||||
|
.coverage-summary td, .coverage-summary th { padding: 10px; }
|
||||||
|
.coverage-summary tbody { border: 1px solid #bbb; }
|
||||||
|
.coverage-summary td { border-right: 1px solid #bbb; }
|
||||||
|
.coverage-summary td:last-child { border-right: none; }
|
||||||
|
.coverage-summary th {
|
||||||
|
text-align: left;
|
||||||
|
font-weight: normal;
|
||||||
|
white-space: nowrap;
|
||||||
|
}
|
||||||
|
.coverage-summary th.file { border-right: none !important; }
|
||||||
|
.coverage-summary th.pct { }
|
||||||
|
.coverage-summary th.pic,
|
||||||
|
.coverage-summary th.abs,
|
||||||
|
.coverage-summary td.pct,
|
||||||
|
.coverage-summary td.abs { text-align: right; }
|
||||||
|
.coverage-summary td.file { white-space: nowrap; }
|
||||||
|
.coverage-summary td.pic { min-width: 120px !important; }
|
||||||
|
.coverage-summary tfoot td { }
|
||||||
|
|
||||||
|
.coverage-summary .sorter {
|
||||||
|
height: 10px;
|
||||||
|
width: 7px;
|
||||||
|
display: inline-block;
|
||||||
|
margin-left: 0.5em;
|
||||||
|
background: url(sort-arrow-sprite.png) no-repeat scroll 0 0 transparent;
|
||||||
|
}
|
||||||
|
.coverage-summary .sorted .sorter {
|
||||||
|
background-position: 0 -20px;
|
||||||
|
}
|
||||||
|
.coverage-summary .sorted-desc .sorter {
|
||||||
|
background-position: 0 -10px;
|
||||||
|
}
|
||||||
|
.status-line { height: 10px; }
|
||||||
|
/* dark red */
|
||||||
|
.red.solid, .status-line.low, .low .cover-fill { background:#C21F39 }
|
||||||
|
.low .chart { border:1px solid #C21F39 }
|
||||||
|
/* medium red */
|
||||||
|
.cstat-no, .fstat-no, .cbranch-no, .cbranch-no { background:#F6C6CE }
|
||||||
|
/* light red */
|
||||||
|
.low, .cline-no { background:#FCE1E5 }
|
||||||
|
/* light green */
|
||||||
|
.high, .cline-yes { background:rgb(230,245,208) }
|
||||||
|
/* medium green */
|
||||||
|
.cstat-yes { background:rgb(161,215,106) }
|
||||||
|
/* dark green */
|
||||||
|
.status-line.high, .high .cover-fill { background:rgb(77,146,33) }
|
||||||
|
.high .chart { border:1px solid rgb(77,146,33) }
|
||||||
|
|
||||||
|
|
||||||
|
.medium .chart { border:1px solid #666; }
|
||||||
|
.medium .cover-fill { background: #666; }
|
||||||
|
|
||||||
|
.cbranch-no { background: yellow !important; color: #111; }
|
||||||
|
|
||||||
|
.cstat-skip { background: #ddd; color: #111; }
|
||||||
|
.fstat-skip { background: #ddd; color: #111 !important; }
|
||||||
|
.cbranch-skip { background: #ddd !important; color: #111; }
|
||||||
|
|
||||||
|
span.cline-neutral { background: #eaeaea; }
|
||||||
|
.medium { background: #eaeaea; }
|
||||||
|
|
||||||
|
.cover-fill, .cover-empty {
|
||||||
|
display:inline-block;
|
||||||
|
height: 12px;
|
||||||
|
}
|
||||||
|
.chart {
|
||||||
|
line-height: 0;
|
||||||
|
}
|
||||||
|
.cover-empty {
|
||||||
|
background: white;
|
||||||
|
}
|
||||||
|
.cover-full {
|
||||||
|
border-right: none !important;
|
||||||
|
}
|
||||||
|
pre.prettyprint {
|
||||||
|
border: none !important;
|
||||||
|
padding: 0 !important;
|
||||||
|
margin: 0 !important;
|
||||||
|
}
|
||||||
|
.com { color: #999 !important; }
|
||||||
|
.ignore-none { color: #999; font-weight: normal; }
|
||||||
|
|
||||||
|
.wrapper {
|
||||||
|
min-height: 100%;
|
||||||
|
height: auto !important;
|
||||||
|
height: 100%;
|
||||||
|
margin: 0 auto -48px;
|
||||||
|
}
|
||||||
|
.footer, .push {
|
||||||
|
height: 48px;
|
||||||
|
}
|
93
coverage/lcov-report/index.html
Normal file
93
coverage/lcov-report/index.html
Normal file
|
@ -0,0 +1,93 @@
|
||||||
|
<!doctype html>
|
||||||
|
<html lang="en">
|
||||||
|
<head>
|
||||||
|
<title>Code coverage report for All files</title>
|
||||||
|
<meta charset="utf-8" />
|
||||||
|
<link rel="stylesheet" href="prettify.css" />
|
||||||
|
<link rel="stylesheet" href="base.css" />
|
||||||
|
<meta name="viewport" content="width=device-width, initial-scale=1">
|
||||||
|
<style type='text/css'>
|
||||||
|
.coverage-summary .sorter {
|
||||||
|
background-image: url(sort-arrow-sprite.png);
|
||||||
|
}
|
||||||
|
</style>
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
<div class='wrapper'>
|
||||||
|
<div class='pad1'>
|
||||||
|
<h1>
|
||||||
|
All files
|
||||||
|
</h1>
|
||||||
|
<div class='clearfix'>
|
||||||
|
<div class='fl pad1y space-right2'>
|
||||||
|
<span class="strong">100% </span>
|
||||||
|
<span class="quiet">Statements</span>
|
||||||
|
<span class='fraction'>32/32</span>
|
||||||
|
</div>
|
||||||
|
<div class='fl pad1y space-right2'>
|
||||||
|
<span class="strong">91.67% </span>
|
||||||
|
<span class="quiet">Branches</span>
|
||||||
|
<span class='fraction'>11/12</span>
|
||||||
|
</div>
|
||||||
|
<div class='fl pad1y space-right2'>
|
||||||
|
<span class="strong">100% </span>
|
||||||
|
<span class="quiet">Functions</span>
|
||||||
|
<span class='fraction'>12/12</span>
|
||||||
|
</div>
|
||||||
|
<div class='fl pad1y space-right2'>
|
||||||
|
<span class="strong">100% </span>
|
||||||
|
<span class="quiet">Lines</span>
|
||||||
|
<span class='fraction'>28/28</span>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div class='status-line high'></div>
|
||||||
|
<div class="pad1">
|
||||||
|
<table class="coverage-summary">
|
||||||
|
<thead>
|
||||||
|
<tr>
|
||||||
|
<th data-col="file" data-fmt="html" data-html="true" class="file">File</th>
|
||||||
|
<th data-col="pic" data-type="number" data-fmt="html" data-html="true" class="pic"></th>
|
||||||
|
<th data-col="statements" data-type="number" data-fmt="pct" class="pct">Statements</th>
|
||||||
|
<th data-col="statements_raw" data-type="number" data-fmt="html" class="abs"></th>
|
||||||
|
<th data-col="branches" data-type="number" data-fmt="pct" class="pct">Branches</th>
|
||||||
|
<th data-col="branches_raw" data-type="number" data-fmt="html" class="abs"></th>
|
||||||
|
<th data-col="functions" data-type="number" data-fmt="pct" class="pct">Functions</th>
|
||||||
|
<th data-col="functions_raw" data-type="number" data-fmt="html" class="abs"></th>
|
||||||
|
<th data-col="lines" data-type="number" data-fmt="pct" class="pct">Lines</th>
|
||||||
|
<th data-col="lines_raw" data-type="number" data-fmt="html" class="abs"></th>
|
||||||
|
</tr>
|
||||||
|
</thead>
|
||||||
|
<tbody><tr>
|
||||||
|
<td class="file high" data-value="index.js"><a href="index.js.html">index.js</a></td>
|
||||||
|
<td data-value="100" class="pic high"><div class="chart"><div class="cover-fill cover-full" style="width: 100%;"></div><div class="cover-empty" style="width:0%;"></div></div></td>
|
||||||
|
<td data-value="100" class="pct high">100%</td>
|
||||||
|
<td data-value="32" class="abs high">32/32</td>
|
||||||
|
<td data-value="91.67" class="pct high">91.67%</td>
|
||||||
|
<td data-value="12" class="abs high">11/12</td>
|
||||||
|
<td data-value="100" class="pct high">100%</td>
|
||||||
|
<td data-value="12" class="abs high">12/12</td>
|
||||||
|
<td data-value="100" class="pct high">100%</td>
|
||||||
|
<td data-value="28" class="abs high">28/28</td>
|
||||||
|
</tr>
|
||||||
|
|
||||||
|
</tbody>
|
||||||
|
</table>
|
||||||
|
</div><div class='push'></div><!-- for sticky footer -->
|
||||||
|
</div><!-- /wrapper -->
|
||||||
|
<div class='footer quiet pad2 space-top1 center small'>
|
||||||
|
Code coverage
|
||||||
|
generated by <a href="https://istanbul.js.org/" target="_blank">istanbul</a> at Thu Mar 01 2018 10:11:05 GMT-0600 (CST)
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<script src="prettify.js"></script>
|
||||||
|
<script>
|
||||||
|
window.onload = function () {
|
||||||
|
if (typeof prettyPrint === 'function') {
|
||||||
|
prettyPrint();
|
||||||
|
}
|
||||||
|
};
|
||||||
|
</script>
|
||||||
|
<script src="sorter.js"></script>
|
||||||
|
</body>
|
||||||
|
</html>
|
230
coverage/lcov-report/index.js.html
Normal file
230
coverage/lcov-report/index.js.html
Normal file
|
@ -0,0 +1,230 @@
|
||||||
|
<!doctype html>
|
||||||
|
<html lang="en">
|
||||||
|
<head>
|
||||||
|
<title>Code coverage report for index.js</title>
|
||||||
|
<meta charset="utf-8" />
|
||||||
|
<link rel="stylesheet" href="prettify.css" />
|
||||||
|
<link rel="stylesheet" href="base.css" />
|
||||||
|
<meta name="viewport" content="width=device-width, initial-scale=1">
|
||||||
|
<style type='text/css'>
|
||||||
|
.coverage-summary .sorter {
|
||||||
|
background-image: url(sort-arrow-sprite.png);
|
||||||
|
}
|
||||||
|
</style>
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
<div class='wrapper'>
|
||||||
|
<div class='pad1'>
|
||||||
|
<h1>
|
||||||
|
<a href="index.html">All files</a> index.js
|
||||||
|
</h1>
|
||||||
|
<div class='clearfix'>
|
||||||
|
<div class='fl pad1y space-right2'>
|
||||||
|
<span class="strong">100% </span>
|
||||||
|
<span class="quiet">Statements</span>
|
||||||
|
<span class='fraction'>32/32</span>
|
||||||
|
</div>
|
||||||
|
<div class='fl pad1y space-right2'>
|
||||||
|
<span class="strong">91.67% </span>
|
||||||
|
<span class="quiet">Branches</span>
|
||||||
|
<span class='fraction'>11/12</span>
|
||||||
|
</div>
|
||||||
|
<div class='fl pad1y space-right2'>
|
||||||
|
<span class="strong">100% </span>
|
||||||
|
<span class="quiet">Functions</span>
|
||||||
|
<span class='fraction'>12/12</span>
|
||||||
|
</div>
|
||||||
|
<div class='fl pad1y space-right2'>
|
||||||
|
<span class="strong">100% </span>
|
||||||
|
<span class="quiet">Lines</span>
|
||||||
|
<span class='fraction'>28/28</span>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div class='status-line high'></div>
|
||||||
|
<pre><table class="coverage">
|
||||||
|
<tr><td class="line-count quiet">1
|
||||||
|
2
|
||||||
|
3
|
||||||
|
4
|
||||||
|
5
|
||||||
|
6
|
||||||
|
7
|
||||||
|
8
|
||||||
|
9
|
||||||
|
10
|
||||||
|
11
|
||||||
|
12
|
||||||
|
13
|
||||||
|
14
|
||||||
|
15
|
||||||
|
16
|
||||||
|
17
|
||||||
|
18
|
||||||
|
19
|
||||||
|
20
|
||||||
|
21
|
||||||
|
22
|
||||||
|
23
|
||||||
|
24
|
||||||
|
25
|
||||||
|
26
|
||||||
|
27
|
||||||
|
28
|
||||||
|
29
|
||||||
|
30
|
||||||
|
31
|
||||||
|
32
|
||||||
|
33
|
||||||
|
34
|
||||||
|
35
|
||||||
|
36
|
||||||
|
37
|
||||||
|
38
|
||||||
|
39
|
||||||
|
40
|
||||||
|
41
|
||||||
|
42
|
||||||
|
43
|
||||||
|
44
|
||||||
|
45
|
||||||
|
46
|
||||||
|
47
|
||||||
|
48
|
||||||
|
49
|
||||||
|
50
|
||||||
|
51
|
||||||
|
52
|
||||||
|
53
|
||||||
|
54
|
||||||
|
55
|
||||||
|
56</td><td class="line-coverage quiet"><span class="cline-any cline-yes">1x</span>
|
||||||
|
<span class="cline-any cline-neutral"> </span>
|
||||||
|
<span class="cline-any cline-yes">12x</span>
|
||||||
|
<span class="cline-any cline-yes">108x</span>
|
||||||
|
<span class="cline-any cline-yes">108x</span>
|
||||||
|
<span class="cline-any cline-neutral"> </span>
|
||||||
|
<span class="cline-any cline-neutral"> </span>
|
||||||
|
<span class="cline-any cline-neutral"> </span>
|
||||||
|
<span class="cline-any cline-neutral"> </span>
|
||||||
|
<span class="cline-any cline-yes">12x</span>
|
||||||
|
<span class="cline-any cline-neutral"> </span>
|
||||||
|
<span class="cline-any cline-neutral"> </span>
|
||||||
|
<span class="cline-any cline-neutral"> </span>
|
||||||
|
<span class="cline-any cline-yes">1x</span>
|
||||||
|
<span class="cline-any cline-yes">1x</span>
|
||||||
|
<span class="cline-any cline-neutral"> </span>
|
||||||
|
<span class="cline-any cline-neutral"> </span>
|
||||||
|
<span class="cline-any cline-neutral"> </span>
|
||||||
|
<span class="cline-any cline-yes">9x</span>
|
||||||
|
<span class="cline-any cline-yes">1x</span>
|
||||||
|
<span class="cline-any cline-neutral"> </span>
|
||||||
|
<span class="cline-any cline-neutral"> </span>
|
||||||
|
<span class="cline-any cline-neutral"> </span>
|
||||||
|
<span class="cline-any cline-yes">3x</span>
|
||||||
|
<span class="cline-any cline-neutral"> </span>
|
||||||
|
<span class="cline-any cline-yes">18x</span>
|
||||||
|
<span class="cline-any cline-yes">2x</span>
|
||||||
|
<span class="cline-any cline-neutral"> </span>
|
||||||
|
<span class="cline-any cline-yes">1x</span>
|
||||||
|
<span class="cline-any cline-yes">9x</span>
|
||||||
|
<span class="cline-any cline-yes">9x</span>
|
||||||
|
<span class="cline-any cline-yes">9x</span>
|
||||||
|
<span class="cline-any cline-yes">9x</span>
|
||||||
|
<span class="cline-any cline-neutral"> </span>
|
||||||
|
<span class="cline-any cline-yes">1x</span>
|
||||||
|
<span class="cline-any cline-neutral"> </span>
|
||||||
|
<span class="cline-any cline-yes">3x</span>
|
||||||
|
<span class="cline-any cline-neutral"> </span>
|
||||||
|
<span class="cline-any cline-neutral"> </span>
|
||||||
|
<span class="cline-any cline-neutral"> </span>
|
||||||
|
<span class="cline-any cline-yes">4x</span>
|
||||||
|
<span class="cline-any cline-yes">48x</span>
|
||||||
|
<span class="cline-any cline-yes">38x</span>
|
||||||
|
<span class="cline-any cline-yes">11x</span>
|
||||||
|
<span class="cline-any cline-neutral"> </span>
|
||||||
|
<span class="cline-any cline-yes">4x</span>
|
||||||
|
<span class="cline-any cline-neutral"> </span>
|
||||||
|
<span class="cline-any cline-neutral"> </span>
|
||||||
|
<span class="cline-any cline-neutral"> </span>
|
||||||
|
<span class="cline-any cline-yes">4x</span>
|
||||||
|
<span class="cline-any cline-yes">4x</span>
|
||||||
|
<span class="cline-any cline-yes">4x</span>
|
||||||
|
<span class="cline-any cline-yes">4x</span>
|
||||||
|
<span class="cline-any cline-neutral"> </span>
|
||||||
|
<span class="cline-any cline-neutral"> </span>
|
||||||
|
<span class="cline-any cline-neutral"> </span></td><td class="text"><pre class="prettyprint lang-js">module.exports = class Query {
|
||||||
|
constructor (data) {
|
||||||
|
this.data = data.map(item => {
|
||||||
|
item.sortScore = 0
|
||||||
|
return item
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
get results () {
|
||||||
|
return this.data
|
||||||
|
}
|
||||||
|
|
||||||
|
filter (func) {
|
||||||
|
this.data = this.data.filter(func)
|
||||||
|
return this
|
||||||
|
}
|
||||||
|
|
||||||
|
filterBy (key, func) {
|
||||||
|
this.data = this.data.filter(item => func(item[key]))
|
||||||
|
return this
|
||||||
|
}
|
||||||
|
|
||||||
|
search (key, term, score = 0) {
|
||||||
|
switch (typeof term) {
|
||||||
|
case 'boolean':
|
||||||
|
this.data = this.data.filter(item => item[key] === term)
|
||||||
|
break
|
||||||
|
case 'string':
|
||||||
|
this.data = this.data.filter(item => {
|
||||||
|
let regFind = new RegExp(term, 'gi')
|
||||||
|
let termMatches = (item[key].match(regFind) || []).length
|
||||||
|
item.sortScore += termMatches
|
||||||
|
return termMatches
|
||||||
|
})
|
||||||
|
break
|
||||||
|
}
|
||||||
|
return this
|
||||||
|
}
|
||||||
|
|
||||||
|
sort (key = <span class="branch-0 cbranch-no" title="branch not covered" >'sortScore')</span> {
|
||||||
|
this.data = this.data.sort((a, b) => {
|
||||||
|
if (a[key] < b[key]) return -1
|
||||||
|
if (a[key] > b[key]) return 1
|
||||||
|
return 0
|
||||||
|
})
|
||||||
|
return this
|
||||||
|
}
|
||||||
|
|
||||||
|
paginate (page = 1, perPage = 10) {
|
||||||
|
let min = page * perPage - perPage
|
||||||
|
let max = min + perPage
|
||||||
|
this.data = this.data.slice(min, max)
|
||||||
|
return this
|
||||||
|
}
|
||||||
|
}
|
||||||
|
</pre></td></tr>
|
||||||
|
</table></pre>
|
||||||
|
<div class='push'></div><!-- for sticky footer -->
|
||||||
|
</div><!-- /wrapper -->
|
||||||
|
<div class='footer quiet pad2 space-top1 center small'>
|
||||||
|
Code coverage
|
||||||
|
generated by <a href="https://istanbul.js.org/" target="_blank">istanbul</a> at Thu Mar 01 2018 10:11:05 GMT-0600 (CST)
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<script src="prettify.js"></script>
|
||||||
|
<script>
|
||||||
|
window.onload = function () {
|
||||||
|
if (typeof prettyPrint === 'function') {
|
||||||
|
prettyPrint();
|
||||||
|
}
|
||||||
|
};
|
||||||
|
</script>
|
||||||
|
<script src="sorter.js"></script>
|
||||||
|
</body>
|
||||||
|
</html>
|
1
coverage/lcov-report/prettify.css
Normal file
1
coverage/lcov-report/prettify.css
Normal file
|
@ -0,0 +1 @@
|
||||||
|
.pln{color:#000}@media screen{.str{color:#080}.kwd{color:#008}.com{color:#800}.typ{color:#606}.lit{color:#066}.pun,.opn,.clo{color:#660}.tag{color:#008}.atn{color:#606}.atv{color:#080}.dec,.var{color:#606}.fun{color:red}}@media print,projection{.str{color:#060}.kwd{color:#006;font-weight:bold}.com{color:#600;font-style:italic}.typ{color:#404;font-weight:bold}.lit{color:#044}.pun,.opn,.clo{color:#440}.tag{color:#006;font-weight:bold}.atn{color:#404}.atv{color:#060}}pre.prettyprint{padding:2px;border:1px solid #888}ol.linenums{margin-top:0;margin-bottom:0}li.L0,li.L1,li.L2,li.L3,li.L5,li.L6,li.L7,li.L8{list-style-type:none}li.L1,li.L3,li.L5,li.L7,li.L9{background:#eee}
|
1
coverage/lcov-report/prettify.js
Normal file
1
coverage/lcov-report/prettify.js
Normal file
File diff suppressed because one or more lines are too long
BIN
coverage/lcov-report/sort-arrow-sprite.png
Normal file
BIN
coverage/lcov-report/sort-arrow-sprite.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 209 B |
158
coverage/lcov-report/sorter.js
Normal file
158
coverage/lcov-report/sorter.js
Normal file
|
@ -0,0 +1,158 @@
|
||||||
|
var addSorting = (function () {
|
||||||
|
"use strict";
|
||||||
|
var cols,
|
||||||
|
currentSort = {
|
||||||
|
index: 0,
|
||||||
|
desc: false
|
||||||
|
};
|
||||||
|
|
||||||
|
// returns the summary table element
|
||||||
|
function getTable() { return document.querySelector('.coverage-summary'); }
|
||||||
|
// returns the thead element of the summary table
|
||||||
|
function getTableHeader() { return getTable().querySelector('thead tr'); }
|
||||||
|
// returns the tbody element of the summary table
|
||||||
|
function getTableBody() { return getTable().querySelector('tbody'); }
|
||||||
|
// returns the th element for nth column
|
||||||
|
function getNthColumn(n) { return getTableHeader().querySelectorAll('th')[n]; }
|
||||||
|
|
||||||
|
// loads all columns
|
||||||
|
function loadColumns() {
|
||||||
|
var colNodes = getTableHeader().querySelectorAll('th'),
|
||||||
|
colNode,
|
||||||
|
cols = [],
|
||||||
|
col,
|
||||||
|
i;
|
||||||
|
|
||||||
|
for (i = 0; i < colNodes.length; i += 1) {
|
||||||
|
colNode = colNodes[i];
|
||||||
|
col = {
|
||||||
|
key: colNode.getAttribute('data-col'),
|
||||||
|
sortable: !colNode.getAttribute('data-nosort'),
|
||||||
|
type: colNode.getAttribute('data-type') || 'string'
|
||||||
|
};
|
||||||
|
cols.push(col);
|
||||||
|
if (col.sortable) {
|
||||||
|
col.defaultDescSort = col.type === 'number';
|
||||||
|
colNode.innerHTML = colNode.innerHTML + '<span class="sorter"></span>';
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return cols;
|
||||||
|
}
|
||||||
|
// attaches a data attribute to every tr element with an object
|
||||||
|
// of data values keyed by column name
|
||||||
|
function loadRowData(tableRow) {
|
||||||
|
var tableCols = tableRow.querySelectorAll('td'),
|
||||||
|
colNode,
|
||||||
|
col,
|
||||||
|
data = {},
|
||||||
|
i,
|
||||||
|
val;
|
||||||
|
for (i = 0; i < tableCols.length; i += 1) {
|
||||||
|
colNode = tableCols[i];
|
||||||
|
col = cols[i];
|
||||||
|
val = colNode.getAttribute('data-value');
|
||||||
|
if (col.type === 'number') {
|
||||||
|
val = Number(val);
|
||||||
|
}
|
||||||
|
data[col.key] = val;
|
||||||
|
}
|
||||||
|
return data;
|
||||||
|
}
|
||||||
|
// loads all row data
|
||||||
|
function loadData() {
|
||||||
|
var rows = getTableBody().querySelectorAll('tr'),
|
||||||
|
i;
|
||||||
|
|
||||||
|
for (i = 0; i < rows.length; i += 1) {
|
||||||
|
rows[i].data = loadRowData(rows[i]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// sorts the table using the data for the ith column
|
||||||
|
function sortByIndex(index, desc) {
|
||||||
|
var key = cols[index].key,
|
||||||
|
sorter = function (a, b) {
|
||||||
|
a = a.data[key];
|
||||||
|
b = b.data[key];
|
||||||
|
return a < b ? -1 : a > b ? 1 : 0;
|
||||||
|
},
|
||||||
|
finalSorter = sorter,
|
||||||
|
tableBody = document.querySelector('.coverage-summary tbody'),
|
||||||
|
rowNodes = tableBody.querySelectorAll('tr'),
|
||||||
|
rows = [],
|
||||||
|
i;
|
||||||
|
|
||||||
|
if (desc) {
|
||||||
|
finalSorter = function (a, b) {
|
||||||
|
return -1 * sorter(a, b);
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
for (i = 0; i < rowNodes.length; i += 1) {
|
||||||
|
rows.push(rowNodes[i]);
|
||||||
|
tableBody.removeChild(rowNodes[i]);
|
||||||
|
}
|
||||||
|
|
||||||
|
rows.sort(finalSorter);
|
||||||
|
|
||||||
|
for (i = 0; i < rows.length; i += 1) {
|
||||||
|
tableBody.appendChild(rows[i]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// removes sort indicators for current column being sorted
|
||||||
|
function removeSortIndicators() {
|
||||||
|
var col = getNthColumn(currentSort.index),
|
||||||
|
cls = col.className;
|
||||||
|
|
||||||
|
cls = cls.replace(/ sorted$/, '').replace(/ sorted-desc$/, '');
|
||||||
|
col.className = cls;
|
||||||
|
}
|
||||||
|
// adds sort indicators for current column being sorted
|
||||||
|
function addSortIndicators() {
|
||||||
|
getNthColumn(currentSort.index).className += currentSort.desc ? ' sorted-desc' : ' sorted';
|
||||||
|
}
|
||||||
|
// adds event listeners for all sorter widgets
|
||||||
|
function enableUI() {
|
||||||
|
var i,
|
||||||
|
el,
|
||||||
|
ithSorter = function ithSorter(i) {
|
||||||
|
var col = cols[i];
|
||||||
|
|
||||||
|
return function () {
|
||||||
|
var desc = col.defaultDescSort;
|
||||||
|
|
||||||
|
if (currentSort.index === i) {
|
||||||
|
desc = !currentSort.desc;
|
||||||
|
}
|
||||||
|
sortByIndex(i, desc);
|
||||||
|
removeSortIndicators();
|
||||||
|
currentSort.index = i;
|
||||||
|
currentSort.desc = desc;
|
||||||
|
addSortIndicators();
|
||||||
|
};
|
||||||
|
};
|
||||||
|
for (i =0 ; i < cols.length; i += 1) {
|
||||||
|
if (cols[i].sortable) {
|
||||||
|
// add the click event handler on the th so users
|
||||||
|
// dont have to click on those tiny arrows
|
||||||
|
el = getNthColumn(i).querySelector('.sorter').parentElement;
|
||||||
|
if (el.addEventListener) {
|
||||||
|
el.addEventListener('click', ithSorter(i));
|
||||||
|
} else {
|
||||||
|
el.attachEvent('onclick', ithSorter(i));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// adds sorting functionality to the UI
|
||||||
|
return function () {
|
||||||
|
if (!getTable()) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
cols = loadColumns();
|
||||||
|
loadData(cols);
|
||||||
|
addSortIndicators();
|
||||||
|
enableUI();
|
||||||
|
};
|
||||||
|
})();
|
||||||
|
|
||||||
|
window.addEventListener('load', addSorting);
|
73
coverage/lcov.info
Normal file
73
coverage/lcov.info
Normal file
|
@ -0,0 +1,73 @@
|
||||||
|
TN:
|
||||||
|
SF:/Users/sharpshark28/web/json-query-chain/index.js
|
||||||
|
FN:2,(anonymous_0)
|
||||||
|
FN:3,(anonymous_1)
|
||||||
|
FN:9,(anonymous_2)
|
||||||
|
FN:13,(anonymous_3)
|
||||||
|
FN:18,(anonymous_4)
|
||||||
|
FN:19,(anonymous_5)
|
||||||
|
FN:23,(anonymous_6)
|
||||||
|
FN:26,(anonymous_7)
|
||||||
|
FN:29,(anonymous_8)
|
||||||
|
FN:40,(anonymous_9)
|
||||||
|
FN:41,(anonymous_10)
|
||||||
|
FN:49,(anonymous_11)
|
||||||
|
FNF:12
|
||||||
|
FNH:12
|
||||||
|
FNDA:12,(anonymous_0)
|
||||||
|
FNDA:108,(anonymous_1)
|
||||||
|
FNDA:12,(anonymous_2)
|
||||||
|
FNDA:1,(anonymous_3)
|
||||||
|
FNDA:1,(anonymous_4)
|
||||||
|
FNDA:9,(anonymous_5)
|
||||||
|
FNDA:3,(anonymous_6)
|
||||||
|
FNDA:18,(anonymous_7)
|
||||||
|
FNDA:9,(anonymous_8)
|
||||||
|
FNDA:4,(anonymous_9)
|
||||||
|
FNDA:48,(anonymous_10)
|
||||||
|
FNDA:4,(anonymous_11)
|
||||||
|
DA:1,1
|
||||||
|
DA:3,12
|
||||||
|
DA:4,108
|
||||||
|
DA:5,108
|
||||||
|
DA:10,12
|
||||||
|
DA:14,1
|
||||||
|
DA:15,1
|
||||||
|
DA:19,9
|
||||||
|
DA:20,1
|
||||||
|
DA:24,3
|
||||||
|
DA:26,18
|
||||||
|
DA:27,2
|
||||||
|
DA:29,1
|
||||||
|
DA:30,9
|
||||||
|
DA:31,9
|
||||||
|
DA:32,9
|
||||||
|
DA:33,9
|
||||||
|
DA:35,1
|
||||||
|
DA:37,3
|
||||||
|
DA:41,4
|
||||||
|
DA:42,48
|
||||||
|
DA:43,38
|
||||||
|
DA:44,11
|
||||||
|
DA:46,4
|
||||||
|
DA:50,4
|
||||||
|
DA:51,4
|
||||||
|
DA:52,4
|
||||||
|
DA:53,4
|
||||||
|
LF:28
|
||||||
|
LH:28
|
||||||
|
BRDA:23,0,0,3
|
||||||
|
BRDA:24,1,0,2
|
||||||
|
BRDA:24,1,1,1
|
||||||
|
BRDA:31,2,0,9
|
||||||
|
BRDA:31,2,1,7
|
||||||
|
BRDA:40,3,0,0
|
||||||
|
BRDA:42,4,0,10
|
||||||
|
BRDA:42,4,1,38
|
||||||
|
BRDA:43,5,0,27
|
||||||
|
BRDA:43,5,1,11
|
||||||
|
BRDA:49,6,0,1
|
||||||
|
BRDA:49,7,0,1
|
||||||
|
BRF:12
|
||||||
|
BRH:11
|
||||||
|
end_of_record
|
35
index.js
35
index.js
|
@ -1,9 +1,6 @@
|
||||||
module.exports = class Query {
|
module.exports = class Query {
|
||||||
constructor (data) {
|
constructor (data) {
|
||||||
this.data = data.map(item => {
|
this.data = data
|
||||||
item.sortScore = 0
|
|
||||||
return item
|
|
||||||
})
|
|
||||||
}
|
}
|
||||||
|
|
||||||
get results () {
|
get results () {
|
||||||
|
@ -16,33 +13,47 @@ module.exports = class Query {
|
||||||
}
|
}
|
||||||
|
|
||||||
filterBy (key, func) {
|
filterBy (key, func) {
|
||||||
|
if (this.data.length && typeof this.data[0] === 'object') {
|
||||||
this.data = this.data.filter(item => func(item[key]))
|
this.data = this.data.filter(item => func(item[key]))
|
||||||
|
} else console.warn('Attempted to use filterBy with a flat array')
|
||||||
return this
|
return this
|
||||||
}
|
}
|
||||||
|
|
||||||
search (key, term, score = 0) {
|
search (term, key) {
|
||||||
switch (typeof term) {
|
switch (typeof term) {
|
||||||
case 'boolean':
|
case 'boolean':
|
||||||
|
if (this.data.length && typeof this.data[0] === 'object') {
|
||||||
this.data = this.data.filter(item => item[key] === term)
|
this.data = this.data.filter(item => item[key] === term)
|
||||||
|
} else console.warn('Attempted to use search by boolean with a flat array')
|
||||||
break
|
break
|
||||||
case 'string':
|
case 'string':
|
||||||
this.data = this.data.filter(item => {
|
|
||||||
let regFind = new RegExp(term, 'gi')
|
let regFind = new RegExp(term, 'gi')
|
||||||
let termMatches = (item[key].match(regFind) || []).length
|
let getMatches = item => {
|
||||||
item.sortScore += termMatches
|
if (typeof item === 'string') {
|
||||||
return termMatches
|
return (item.match(regFind) || []).length
|
||||||
})
|
} else {
|
||||||
|
return (item[key].match(regFind) || []).length
|
||||||
|
}
|
||||||
|
}
|
||||||
|
this.data = [...this.data].sort(getMatches).filter(getMatches)
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
return this
|
return this
|
||||||
}
|
}
|
||||||
|
|
||||||
sort (key = 'sortScore') {
|
sort (func) {
|
||||||
this.data = this.data.sort((a, b) => {
|
this.data = [...this.data].sort(func)
|
||||||
|
return this
|
||||||
|
}
|
||||||
|
|
||||||
|
sortBy (key) {
|
||||||
|
if (this.data.length && typeof this.data[0] === 'object') {
|
||||||
|
this.data = [...this.data].sort((a, b) => {
|
||||||
if (a[key] < b[key]) return -1
|
if (a[key] < b[key]) return -1
|
||||||
if (a[key] > b[key]) return 1
|
if (a[key] > b[key]) return 1
|
||||||
return 0
|
return 0
|
||||||
})
|
})
|
||||||
|
} else console.warn('Attempted to use sortBy with a flat array')
|
||||||
return this
|
return this
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
126
index.test.js
126
index.test.js
|
@ -1,6 +1,8 @@
|
||||||
const Query = require('./index')
|
const Query = require('./index')
|
||||||
const TestData = require('./testdata.json')
|
const TestData = require('./testdata.json')
|
||||||
|
|
||||||
|
const arrayOf100Things = [...Array(100).keys()]
|
||||||
|
|
||||||
test('should not modify passed data without chain alterations', () => {
|
test('should not modify passed data without chain alterations', () => {
|
||||||
let query = new Query(TestData)
|
let query = new Query(TestData)
|
||||||
.results
|
.results
|
||||||
|
@ -8,6 +10,14 @@ test('should not modify passed data without chain alterations', () => {
|
||||||
expect(query).toMatchObject(TestData)
|
expect(query).toMatchObject(TestData)
|
||||||
})
|
})
|
||||||
|
|
||||||
|
test('should paginate with flat array data', () => {
|
||||||
|
let query = new Query(arrayOf100Things)
|
||||||
|
.paginate()
|
||||||
|
.results
|
||||||
|
|
||||||
|
expect(query.length).toBe(10)
|
||||||
|
})
|
||||||
|
|
||||||
test('should paginate with default params', () => {
|
test('should paginate with default params', () => {
|
||||||
let query = new Query(TestData)
|
let query = new Query(TestData)
|
||||||
.paginate()
|
.paginate()
|
||||||
|
@ -34,33 +44,103 @@ test('should paginate to second page with custom page length', () => {
|
||||||
expect(query[0].name).toBe('Howard Buckley')
|
expect(query[0].name).toBe('Howard Buckley')
|
||||||
})
|
})
|
||||||
|
|
||||||
|
test('should search and sort on flat array of strings', () => {
|
||||||
|
let query = new Query(['bar', 'foo', 'foobar', 'foofoobar'])
|
||||||
|
.search('foo')
|
||||||
|
.results
|
||||||
|
|
||||||
|
expect(query[0]).toBe('foofoobar')
|
||||||
|
expect(query).toContain('foo')
|
||||||
|
expect(query).not.toContain('bar')
|
||||||
|
})
|
||||||
|
|
||||||
|
test('should search by flat array by boolean', () => {
|
||||||
|
let consoleWarnSpy = jest.spyOn(global.console, 'warn')
|
||||||
|
consoleWarnSpy.mockImplementation(() => {})
|
||||||
|
|
||||||
|
let query = new Query(arrayOf100Things)
|
||||||
|
.search(true, 'dumbKey')
|
||||||
|
.results
|
||||||
|
|
||||||
|
expect(query).toEqual(arrayOf100Things)
|
||||||
|
expect(consoleWarnSpy).toHaveBeenCalled()
|
||||||
|
|
||||||
|
consoleWarnSpy.mockReset()
|
||||||
|
consoleWarnSpy.mockRestore()
|
||||||
|
})
|
||||||
|
|
||||||
test('should search by boolean isActive', () => {
|
test('should search by boolean isActive', () => {
|
||||||
let query = new Query(TestData)
|
let query = new Query(TestData)
|
||||||
.search('isActive', true)
|
.search(true, 'isActive')
|
||||||
.results
|
.results
|
||||||
|
|
||||||
expect(query.length).toBe(4)
|
expect(query.length).toBe(4)
|
||||||
})
|
})
|
||||||
|
|
||||||
|
test('should search partial matching on strings with flat array', () => {
|
||||||
|
let query = new Query(['foo', 'bar', 'foobar'])
|
||||||
|
.search('foo')
|
||||||
|
.results
|
||||||
|
|
||||||
|
expect(query[0]).toBe('foobar')
|
||||||
|
expect(query[1]).toBe('foo')
|
||||||
|
})
|
||||||
|
|
||||||
test('should search by name', () => {
|
test('should search by name', () => {
|
||||||
let query = new Query(TestData)
|
let query = new Query(TestData)
|
||||||
.search('name', 'steele')
|
.search('steele', 'name')
|
||||||
.results
|
.results
|
||||||
|
|
||||||
expect(query.length).toBe(2)
|
expect(query.length).toBe(2)
|
||||||
})
|
})
|
||||||
|
|
||||||
test('should sort by boolean isActive', () => {
|
test('should sort alphabetically with custom function', () => {
|
||||||
|
let alphabetical = (a, b) => a.name > b.name
|
||||||
|
|
||||||
let query = new Query(TestData)
|
let query = new Query(TestData)
|
||||||
.sort('isActive')
|
.sort(alphabetical)
|
||||||
|
.results
|
||||||
|
|
||||||
|
expect(query[0].name).toBe('Dudley Conner')
|
||||||
|
expect(query[query.length - 1].name).toBe('Wade Steele')
|
||||||
|
})
|
||||||
|
|
||||||
|
test('should sort alphabetically with flat array', () => {
|
||||||
|
let query = new Query(['foo', 'bar', 'foobar'])
|
||||||
|
.sort((a, b) => a > b)
|
||||||
|
.results
|
||||||
|
|
||||||
|
expect(query[0]).toBe('bar')
|
||||||
|
expect(query[1]).toBe('foo')
|
||||||
|
expect(query[2]).toBe('foobar')
|
||||||
|
})
|
||||||
|
|
||||||
|
test('should sortBy do nothing with flat array', () => {
|
||||||
|
let consoleWarnSpy = jest.spyOn(global.console, 'warn')
|
||||||
|
consoleWarnSpy.mockImplementation(() => {})
|
||||||
|
|
||||||
|
let query = new Query(arrayOf100Things)
|
||||||
|
.sortBy('dumbKey')
|
||||||
|
.results
|
||||||
|
|
||||||
|
expect(query).toEqual(arrayOf100Things)
|
||||||
|
expect(consoleWarnSpy).toHaveBeenCalled()
|
||||||
|
|
||||||
|
consoleWarnSpy.mockReset()
|
||||||
|
consoleWarnSpy.mockRestore()
|
||||||
|
})
|
||||||
|
|
||||||
|
test('should sortBy boolean isActive', () => {
|
||||||
|
let query = new Query(TestData)
|
||||||
|
.sortBy('isActive')
|
||||||
.results
|
.results
|
||||||
|
|
||||||
expect(query[0].name).toBe('Katelyn Steele')
|
expect(query[0].name).toBe('Katelyn Steele')
|
||||||
})
|
})
|
||||||
|
|
||||||
test('should sort by number netWorth', () => {
|
test('should sortBy number netWorth', () => {
|
||||||
let query = new Query(TestData)
|
let query = new Query(TestData)
|
||||||
.sort('netWorth')
|
.sortBy('netWorth')
|
||||||
.results
|
.results
|
||||||
|
|
||||||
expect(query[0].name).toBe('Howard Buckley') // Negative
|
expect(query[0].name).toBe('Howard Buckley') // Negative
|
||||||
|
@ -68,14 +148,25 @@ test('should sort by number netWorth', () => {
|
||||||
expect(query[query.length - 1].name).toBe('Newman Mays') // Richest
|
expect(query[query.length - 1].name).toBe('Newman Mays') // Richest
|
||||||
})
|
})
|
||||||
|
|
||||||
test('should sort by string name', () => {
|
test('should sortBy string name', () => {
|
||||||
let query = new Query(TestData)
|
let query = new Query(TestData)
|
||||||
.sort('name')
|
.sortBy('name')
|
||||||
.results
|
.results
|
||||||
|
|
||||||
expect(query[0].name).toBe('Dudley Conner')
|
expect(query[0].name).toBe('Dudley Conner')
|
||||||
})
|
})
|
||||||
|
|
||||||
|
test('should filter a flat array', () => {
|
||||||
|
let isEven = a => !(a % 2)
|
||||||
|
|
||||||
|
let query = new Query(arrayOf100Things)
|
||||||
|
.filter(isEven)
|
||||||
|
.results
|
||||||
|
|
||||||
|
expect(query).toContain(2)
|
||||||
|
expect(query).not.toContain(1)
|
||||||
|
})
|
||||||
|
|
||||||
test('should filter', () => {
|
test('should filter', () => {
|
||||||
let isAgeOver33 = a => a.age > 33
|
let isAgeOver33 = a => a.age > 33
|
||||||
|
|
||||||
|
@ -86,6 +177,21 @@ test('should filter', () => {
|
||||||
expect(query[0].name).toBe('Howard Buckley')
|
expect(query[0].name).toBe('Howard Buckley')
|
||||||
})
|
})
|
||||||
|
|
||||||
|
test('should filter by key, with flat array', () => {
|
||||||
|
let consoleWarnSpy = jest.spyOn(global.console, 'warn')
|
||||||
|
consoleWarnSpy.mockImplementation(() => {})
|
||||||
|
|
||||||
|
let query = new Query(arrayOf100Things)
|
||||||
|
.filterBy('dumbKey', () => {})
|
||||||
|
.results
|
||||||
|
|
||||||
|
expect(query).toEqual(arrayOf100Things)
|
||||||
|
expect(consoleWarnSpy).toHaveBeenCalled()
|
||||||
|
|
||||||
|
consoleWarnSpy.mockReset()
|
||||||
|
consoleWarnSpy.mockRestore()
|
||||||
|
})
|
||||||
|
|
||||||
test('should filter by key', () => {
|
test('should filter by key', () => {
|
||||||
let isNumGT33 = num => num > 33
|
let isNumGT33 = num => num > 33
|
||||||
|
|
||||||
|
@ -98,8 +204,8 @@ test('should filter by key', () => {
|
||||||
|
|
||||||
test('should chain everything together', () => {
|
test('should chain everything together', () => {
|
||||||
let query = new Query(TestData)
|
let query = new Query(TestData)
|
||||||
.search('isActive', true)
|
.search(true, 'isActive')
|
||||||
.sort('name')
|
.sortBy('name')
|
||||||
.paginate(1, 2)
|
.paginate(1, 2)
|
||||||
.results
|
.results
|
||||||
|
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
{
|
{
|
||||||
"name": "json-query-chain",
|
"name": "json-query-chain",
|
||||||
"version": "1.1.2",
|
"version": "1.1.3",
|
||||||
"description": "Chain queries onto POJOs to return precise results.",
|
"description": "Chain queries onto POJOs to return precise results.",
|
||||||
"main": "index.js",
|
"main": "index.js",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
|
|
Loading…
Add table
Reference in a new issue