mirror of
https://gitlab.silvrtree.co.uk/martind2000/ft-webplatform.git
synced 2025-01-25 21:16:17 +00:00
390 lines
12 KiB
HTML
390 lines
12 KiB
HTML
<!doctype html>
|
|
<html lang="en">
|
|
<head>
|
|
<title>Code coverage report for lib/sort-utils.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> / <a href="index.html">lib</a> sort-utils.js
|
|
</h1>
|
|
<div class='clearfix'>
|
|
<div class='fl pad1y space-right2'>
|
|
<span class="strong">94.64% </span>
|
|
<span class="quiet">Statements</span>
|
|
<span class='fraction'>53/56</span>
|
|
</div>
|
|
<div class='fl pad1y space-right2'>
|
|
<span class="strong">85.19% </span>
|
|
<span class="quiet">Branches</span>
|
|
<span class='fraction'>46/54</span>
|
|
</div>
|
|
<div class='fl pad1y space-right2'>
|
|
<span class="strong">100% </span>
|
|
<span class="quiet">Functions</span>
|
|
<span class='fraction'>8/8</span>
|
|
</div>
|
|
<div class='fl pad1y space-right2'>
|
|
<span class="strong">94% </span>
|
|
<span class="quiet">Lines</span>
|
|
<span class='fraction'>47/50</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
|
|
57
|
|
58
|
|
59
|
|
60
|
|
61
|
|
62
|
|
63
|
|
64
|
|
65
|
|
66
|
|
67
|
|
68
|
|
69
|
|
70
|
|
71
|
|
72
|
|
73
|
|
74
|
|
75
|
|
76
|
|
77
|
|
78
|
|
79
|
|
80
|
|
81
|
|
82
|
|
83
|
|
84
|
|
85
|
|
86
|
|
87
|
|
88
|
|
89
|
|
90
|
|
91
|
|
92
|
|
93
|
|
94
|
|
95
|
|
96
|
|
97
|
|
98
|
|
99
|
|
100
|
|
101
|
|
102
|
|
103
|
|
104
|
|
105
|
|
106
|
|
107
|
|
108
|
|
109</td><td class="line-coverage quiet"><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">67x</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-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-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-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-neutral"> </span>
|
|
<span class="cline-any cline-yes">86x</span>
|
|
<span class="cline-any cline-yes">86x</span>
|
|
<span class="cline-any cline-yes">27x</span>
|
|
<span class="cline-any cline-neutral"> </span>
|
|
<span class="cline-any cline-yes">59x</span>
|
|
<span class="cline-any cline-yes">1x</span>
|
|
<span class="cline-any cline-neutral"> </span>
|
|
<span class="cline-any cline-yes">58x</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">27x</span>
|
|
<span class="cline-any cline-yes">552x</span>
|
|
<span class="cline-any cline-yes">552x</span>
|
|
<span class="cline-any cline-yes">552x</span>
|
|
<span class="cline-any cline-yes">552x</span>
|
|
<span class="cline-any cline-yes">552x</span>
|
|
<span class="cline-any cline-yes">51x</span>
|
|
<span class="cline-any cline-neutral"> </span>
|
|
<span class="cline-any cline-yes">501x</span>
|
|
<span class="cline-any cline-yes">9x</span>
|
|
<span class="cline-any cline-neutral"> </span>
|
|
<span class="cline-any cline-yes">492x</span>
|
|
<span class="cline-any cline-yes">7x</span>
|
|
<span class="cline-any cline-neutral"> </span>
|
|
<span class="cline-any cline-yes">485x</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">58x</span>
|
|
<span class="cline-any cline-yes">58x</span>
|
|
<span class="cline-any cline-yes">119x</span>
|
|
<span class="cline-any cline-yes">119x</span>
|
|
<span class="cline-any cline-yes">119x</span>
|
|
<span class="cline-any cline-yes">119x</span>
|
|
<span class="cline-any cline-yes">116x</span>
|
|
<span class="cline-any cline-yes">114x</span>
|
|
<span class="cline-any cline-yes">112x</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">1x</span>
|
|
<span class="cline-any cline-no"> </span>
|
|
<span class="cline-any cline-neutral"> </span>
|
|
<span class="cline-any cline-yes">1x</span>
|
|
<span class="cline-any cline-yes">7x</span>
|
|
<span class="cline-any cline-yes">7x</span>
|
|
<span class="cline-any cline-yes">7x</span>
|
|
<span class="cline-any cline-yes">5x</span>
|
|
<span class="cline-any cline-yes">4x</span>
|
|
<span class="cline-any cline-yes">2x</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-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-neutral"> </span>
|
|
<span class="cline-any cline-neutral"> </span>
|
|
<span class="cline-any cline-neutral"> </span>
|
|
<span class="cline-any cline-yes">6x</span>
|
|
<span class="cline-any cline-yes">6x</span>
|
|
<span class="cline-any cline-yes">6x</span>
|
|
<span class="cline-any cline-yes">6x</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-no"> </span>
|
|
<span class="cline-any cline-no"> </span>
|
|
<span class="cline-any cline-neutral"> </span>
|
|
<span class="cline-any cline-yes">5x</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">6x</span>
|
|
<span class="cline-any cline-yes">21x</span>
|
|
<span class="cline-any cline-yes">15x</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">6x</span>
|
|
<span class="cline-any cline-neutral"> </span>
|
|
<span class="cline-any cline-neutral"> </span></td><td class="text"><pre class="prettyprint lang-js">import get from 'lodash/get';
|
|
import moment from 'moment';
|
|
import {LogManager} from 'aurelia-framework';
|
|
let logger = LogManager.getLogger('sort-utils');
|
|
import cloneDeep from 'lodash/cloneDeep';
|
|
import {parseNumber} from './../components/products/lib/reducer-utils';
|
|
|
|
// TODO: look at moving this to components/products/lib/
|
|
|
|
/**
|
|
* creates a sorting function, for use in [].sort(xxx)
|
|
* @param {string} dataKey
|
|
* @param {string} direction eg 'DESC' or 'ASC'
|
|
* @param {Object} [options]
|
|
* @param {boolean} [options.isNumeric]
|
|
* @param {boolean} [options.isDate]
|
|
* @param {string} [options.dateFormat]
|
|
* @param {string} [options.secondaryCompare]
|
|
* @returns {function}
|
|
*/
|
|
export function createCompare(dataKey, direction, options = {}) {
|
|
let dir = direction === 'DESC' ? -1 : 1;
|
|
if (options.isNumeric) {
|
|
return _createNumericCompare(dataKey, dir, options.secondaryCompare);
|
|
}
|
|
if (options.isDate) {
|
|
return _createDateCompare(dataKey, dir, options.dateFormat, options.secondaryCompare);
|
|
}
|
|
return _createStringCompare(dataKey, dir, options.secondaryCompare);
|
|
}
|
|
|
|
function _createNumericCompare(dataKey, dir, secondaryCompare) {
|
|
return (a, b) => {
|
|
let aParsed = get(a, dataKey, '');
|
|
let bParsed = get(b, dataKey, '');
|
|
aParsed = (typeof aParsed !== 'number') ? parseNumber(aParsed) : <span class="branch-1 cbranch-no" title="branch not covered" >aParsed;</span>
|
|
bParsed = (typeof bParsed !== 'number') ? parseNumber(bParsed) : <span class="branch-1 cbranch-no" title="branch not covered" >bParsed;</span>
|
|
if ((isNaN(aParsed) && isNaN(bParsed)) || aParsed === bParsed) {
|
|
return secondaryCompare ? <span class="branch-0 cbranch-no" title="branch not covered" >secondaryCompare(a, b) </span>: 0;
|
|
}
|
|
if (isNaN(aParsed)) { // non-numbers always last
|
|
return 1;
|
|
}
|
|
if (isNaN(bParsed)) { // non-numbers always last
|
|
return -1;
|
|
}
|
|
return (aParsed - bParsed) * dir;
|
|
};
|
|
}
|
|
|
|
function _createStringCompare(dataKey, dir, secondaryCompare) {
|
|
const dashes = ['\u2014', '&#8212;', '-', ''];
|
|
return (a, b) => {
|
|
let aVal = get(a, dataKey, '').toString();
|
|
let bVal = get(b, dataKey, '').toString();
|
|
let result = aVal.localeCompare(bVal) * dir; // NB: by default, localeCompare() is case-insensitive
|
|
if (result === 0 && secondaryCompare) return secondaryCompare(a, b);
|
|
if (dashes.includes(aVal)) return 1; // dashes or empty always last
|
|
if (dashes.includes(bVal)) return -1; // dashes or empty always last
|
|
return result;
|
|
};
|
|
}
|
|
|
|
function _createDateCompare(dataKey, dir, format, secondaryCompare) {
|
|
<span class="missing-if-branch" title="if path not taken" >I</span>if (format === 'YYYY-MM-DD') {
|
|
<span class="cstat-no" title="statement not covered" > logger.warn('Date Sorting YYYY-MM-DD Format, x1000 faster to do string sorting');</span>
|
|
}
|
|
return (a, b) => {
|
|
let aParsed = moment(get(a, dataKey), format).valueOf();
|
|
let bParsed = moment(get(b, dataKey), format).valueOf();
|
|
if ((isNaN(aParsed) && isNaN(bParsed)) || aParsed === bParsed) return secondaryCompare ? <span class="branch-0 cbranch-no" title="branch not covered" >secondaryCompare(a, b) </span>: 0;
|
|
if (isNaN(aParsed)) return 1; // non-numbers (non-dates) always last
|
|
if (isNaN(bParsed)) return -1; // non-numbers (non-dates) always last
|
|
return (aParsed - bParsed) * dir;
|
|
};
|
|
}
|
|
|
|
|
|
/**
|
|
* reducer safe modification of sorting filters array, returns clone, doesn't modify source object
|
|
* @param {Object} sortFilters
|
|
* @param {string} filterName
|
|
* @returns {Object}
|
|
*/
|
|
export function toggleSortFilters(sortFilters, filterName) {
|
|
sortFilters = cloneDeep(sortFilters);
|
|
let sortColumn = sortFilters[filterName];
|
|
<span class="missing-if-branch" title="else path not taken" >E</span>if (sortColumn) {
|
|
switch (sortColumn.direction) {
|
|
case 'ASC':
|
|
sortColumn.direction = 'DESC';
|
|
break;
|
|
<span class="branch-1 cbranch-no" title="branch not covered" > case 'DESC':</span>
|
|
<span class="cstat-no" title="statement not covered" > sortColumn.direction = 'ASC';</span>
|
|
<span class="cstat-no" title="statement not covered" > break;</span>
|
|
default:
|
|
sortColumn.direction = sortColumn.isNumeric ? <span class="branch-0 cbranch-no" title="branch not covered" >'DESC' </span>: 'ASC';
|
|
}
|
|
}
|
|
|
|
for (let columnName in sortFilters) {
|
|
if (sortFilters.hasOwnProperty(columnName) && columnName !== filterName) {
|
|
sortFilters[columnName].direction = null;
|
|
}
|
|
}
|
|
|
|
return sortFilters;
|
|
}
|
|
</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="http://istanbul-js.org/" target="_blank">istanbul</a> at Thu Sep 28 2017 09:48:32 GMT+0100 (GMT Daylight Time)
|
|
</div>
|
|
</div>
|
|
<script src="..\prettify.js"></script>
|
|
<script>
|
|
window.onload = function () {
|
|
if (typeof prettyPrint === 'function') {
|
|
prettyPrint();
|
|
}
|
|
};
|
|
</script>
|
|
<script src="..\sorter.js"></script>
|
|
</body>
|
|
</html>
|