Skip to content

Instantly share code, notes, and snippets.

@chrishutchinson
Created May 13, 2015 10:47
Show Gist options
  • Save chrishutchinson/67f8dbb84854dee7219d to your computer and use it in GitHub Desktop.
Save chrishutchinson/67f8dbb84854dee7219d to your computer and use it in GitHub Desktop.
AngularJS (ES6) filter wrapper for NumberStrings (https://www.npmjs.com/package/numberstrings)
'use strict';
// Import class
import NumberStrings from 'path/to/numberstrings.filter';
angular.module('appName', [])
.filter('NumberStrings', () => new NumberStrings()) // Add filter
'use strict';
// Require module
var NumberStringsModule = require('numberstrings');
// Setup NumberStrings class
class NumberStrings {
constructor () {
// Load module
var ns = new NumberStringsModule();
return function(input) {
// Replace commas in input
input = parseInt(input.replace(/\,/g,''), 10);
// Return formatted number
return ns.format(input);
}
}
}
// Export class
export default NumberStrings;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment