Skip to content

Commit

Permalink
Add new filters, formatNumber (puts commas into longer numbers eg. 25…
Browse files Browse the repository at this point in the history
…,000), filterObjects (allows you to filter session data depending on whether the value of a given value is, or is not set) and date (which uses the nunjucks-date-filter module to format dates any way you like)
  • Loading branch information
gonogo committed Mar 7, 2019
1 parent 9e9a581 commit b72e8d8
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 1 deletion.
18 changes: 18 additions & 0 deletions app/filters.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
var dateFilter = require('nunjucks-date-filter')
module.exports = function (env) {
/**
* Instantiate object used to store the methods registered as a
Expand All @@ -6,6 +7,22 @@ module.exports = function (env) {
* @type {Object}
*/
var filters = {}
filters.formatNumber = function (x) {
return x.toString().replace(/\B(?=(\d{3})+(?!\d))/g, ',')
}

filters.filterObjects = function (array, property, check, value) {
var output
switch (check) {
case 'is':
output = array.filter(object => object[property].toLowerCase() === value.toLowerCase())
break
case 'is not':
output = array.filter(object => object[property].toLowerCase() !== value.toLowerCase())
break
}
return output
}

/* ------------------------------------------------------------------
add your methods to the filters obj below this comment block:
Expand Down Expand Up @@ -41,5 +58,6 @@ module.exports = function (env) {
/* ------------------------------------------------------------------
keep the following line to return your filters to the app
------------------------------------------------------------------ */
filters.date = dateFilter
return filters
}
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,8 @@
"require-dir": "^1.0.0",
"sync-request": "^6.0.0",
"universal-analytics": "^0.4.16",
"uuid": "^3.2.1"
"uuid": "^3.2.1",
"nunjucks-date-filter": "^0.1.1"
},
"greenkeeper": {
"ignore": [
Expand Down

0 comments on commit b72e8d8

Please sign in to comment.