-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Ryan Stockdale
committed
Jul 11, 2018
1 parent
a6a6845
commit 06ddc33
Showing
5 changed files
with
124 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
language: node_js | ||
|
||
node_js: | ||
- stable | ||
|
||
install: | ||
- npm install | ||
|
||
script: | ||
- npm run cover | ||
|
||
# Send coverage data to Coveralls | ||
after_script: "cat coverage/lcov.info | node_modules/coveralls/bin/coveralls.js" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,25 @@ | ||
# npm-number-formatter | ||
|
||
|
||
Number Formatter | ||
========= | ||
|
||
A small library that adds commas to numbers | ||
|
||
## Installation | ||
|
||
`npm install @unitsix/number-formatter` | ||
|
||
## Usage | ||
|
||
var numFormatter = require('@unitsix/number-formatter'); | ||
|
||
var formattedNum = numFormatter(35666); | ||
|
||
|
||
|
||
Output should be `35,666` | ||
|
||
|
||
## Tests | ||
|
||
`npm test` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
'use strict'; | ||
|
||
/** | ||
* Adds commas to a number | ||
* @param {number} number | ||
* @param {string} locale | ||
* @return {string} | ||
*/ | ||
module.exports = function(number, locale) { | ||
return number.toLocaleString(locale); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
{ | ||
"name": "@unitsix/number-formatter", | ||
"version": "0.1.2", | ||
"engines": { | ||
"node": ">=4.1.1" | ||
}, | ||
"description": "Formats number", | ||
"main": "index.js", | ||
"scripts": { | ||
"test": "mocha --reporter nyan", | ||
"cover": "node_modules/istanbul/lib/cli.js cover node_modules/mocha/bin/_mocha -- -R spec test/*" | ||
}, | ||
"repository": { | ||
"type": "git", | ||
"url": "https://github.com/unitsix/npm-number-formatter" | ||
}, | ||
"keywords": [ | ||
"number", | ||
"formatter" | ||
], | ||
"author": "Ryan Stockdale, forked from Joanne Daudier https://github.com/jdaudier/numberFormatter", | ||
"license": "MIT", | ||
"devDependencies": { | ||
"chai": "~3.0.0", | ||
"coveralls": "^2.11.2", | ||
"istanbul": "^0.3.17", | ||
"mocha": "~2.2.5" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
'use strict'; | ||
|
||
var expect = require('chai').expect; | ||
var numFormatter = require('../index'); | ||
|
||
describe('#numFormatter', function() { | ||
it('should convert single digits', function() { | ||
var result = numFormatter(1); | ||
expect(result).to.equal('1'); | ||
}); | ||
|
||
it('should convert double digits', function() { | ||
var result = numFormatter(12); | ||
expect(result).to.equal('12'); | ||
}); | ||
|
||
it('should convert triple digits', function() { | ||
var result = numFormatter(123); | ||
expect(result).to.equal('123'); | ||
}); | ||
|
||
it('should convert 4 digits', function() { | ||
var result = numFormatter(1234); | ||
expect(result).to.equal('1,234'); | ||
}); | ||
|
||
it('should convert 5 digits', function() { | ||
var result = numFormatter(12345); | ||
expect(result).to.equal('12,345'); | ||
}); | ||
|
||
it('should convert 6 digits', function() { | ||
var result = numFormatter(123456); | ||
expect(result).to.equal('123,456'); | ||
}); | ||
|
||
it('should convert 7 digits', function() { | ||
var result = numFormatter(1234567); | ||
expect(result).to.equal('1,234,567'); | ||
}); | ||
|
||
it('should convert 8 digits', function() { | ||
var result = numFormatter(12345678); | ||
expect(result).to.equal('12,345,678'); | ||
}); | ||
}); |