Skip to content

Commit

Permalink
Add new filter to format long numbers according to GOV.UK content
Browse files Browse the repository at this point in the history
guidelines, inserting commas every third digit

eg. 1000000 becomes 1,000,000
  • Loading branch information
gonogo committed Mar 20, 2019
1 parent 9e9a581 commit ae79c1c
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 1 deletion.
5 changes: 5 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,9 @@ module.exports = function (env) {
* @type {Object}
*/
var filters = {}
filters.formatNumber = function (x) {
return x.toString().replace(/\B(?=(\d{3})+(?!\d))/g, ',')
}

/* ------------------------------------------------------------------
add your methods to the filters obj below this comment block:
Expand Down Expand Up @@ -41,5 +45,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 ae79c1c

Please sign in to comment.