├── .npmignore ├── .babelrc ├── source └── index.js ├── .travis.yml ├── note.txt ├── README.md ├── test └── index.test.js ├── .gitignore ├── package.json └── LICENSE /.npmignore: -------------------------------------------------------------------------------- 1 | source -------------------------------------------------------------------------------- /.babelrc: -------------------------------------------------------------------------------- 1 | { 2 | "passPerPreset": true, 3 | "presets": [ 4 | "es2015", 5 | "stage-3" 6 | ] 7 | } -------------------------------------------------------------------------------- /source/index.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | /** 4 | * Adds commas to a number 5 | * @param {number} number 6 | * @param {string} locale 7 | * @return {string} 8 | */ 9 | module.exports = (number, locale) => { 10 | return number.toLocaleString(locale); 11 | }; 12 | -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | language: node_js 2 | 3 | node_js: 4 | - stable 5 | 6 | install: 7 | - npm install 8 | 9 | script: 10 | - npm run cover 11 | 12 | # Send coverage data to Coveralls 13 | after_script: "cat coverage/lcov.info | node_modules/coveralls/bin/coveralls.js" -------------------------------------------------------------------------------- /note.txt: -------------------------------------------------------------------------------- 1 | git add . 2 | git commit -m “Initial release” 3 | git tag v0.0.1 4 | git push origin master --tags 5 | 6 | npm publish or npm publish --access=public 7 | 8 | npm version patch -m "Version %s - add sweet badges" 9 | 10 | After bumping the version number 11 | git push && git push --tags (or git push origin master --tags) 12 | npm publish -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # number-formatter 2 | 3 | [![Build Status](https://travis-ci.org/playground/number-formatter.svg?branch=master)](https://travis-ci.org/playground/number-formatter) 4 | 5 | [![Coverage Status](https://coveralls.io/repos/github/playground/number-formatter/badge.svg?branch=master)](https://coveralls.io/github/playground/number-formatter?branch=master) -------------------------------------------------------------------------------- /test/index.test.js: -------------------------------------------------------------------------------- 1 | import test from 'tape'; 2 | import numFormatter from '../source/index'; 3 | 4 | test('numFormatter', (assert) => { 5 | let result = numFormatter(1); 6 | assert.equal(result, '1', 'should convert single digit'); 7 | 8 | result = numFormatter(12); 9 | assert.equal(result, '12', 'should convert double digits'); 10 | 11 | result = numFormatter(123); 12 | assert.equal(result, '123', 'should convert tripple digits'); 13 | 14 | assert.end(); 15 | }); 16 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # Logs 2 | logs 3 | *.log 4 | npm-debug.log* 5 | 6 | # Runtime data 7 | pids 8 | *.pid 9 | *.seed 10 | 11 | # Directory for instrumented libs generated by jscoverage/JSCover 12 | lib-cov 13 | 14 | # Coverage directory used by tools like istanbul 15 | coverage 16 | 17 | # nyc test coverage 18 | .nyc_output 19 | 20 | # Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files) 21 | .grunt 22 | 23 | # node-waf configuration 24 | .lock-wscript 25 | 26 | # Compiled binary addons (http://nodejs.org/api/addons.html) 27 | build/Release 28 | 29 | # Dependency directories 30 | node_modules 31 | jspm_packages 32 | distribution 33 | 34 | # Optional npm cache directory 35 | .npm 36 | 37 | # Optional REPL history 38 | .node_repl_history 39 | .idea -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "@physicalweb/number-formatter", 3 | "version": "1.0.3", 4 | "description": "", 5 | "main": "./distribution/index.js", 6 | "scripts": { 7 | "build": "babel source --out-dir distribution", 8 | "prepublish": "npm run build", 9 | "test": "nyc babel-tape-runner test/**/*.test.js", 10 | "cover": "nyc --reporter=lcov --reporter=text-lcov babel-tape-runner test/**/*.test.js" 11 | }, 12 | "repository": { 13 | "type": "git", 14 | "url": "git+https://github.com/playground/number-formatter.git" 15 | }, 16 | "author": "Jeff Lu (http://www.soconnect.net)", 17 | "license": "ISC", 18 | "bugs": { 19 | "url": "https://github.com/playground/number-formatter/issues" 20 | }, 21 | "homepage": "https://github.com/playground/number-formatter#readme", 22 | "dependencies": { 23 | "babel-cli": "^6.24.0", 24 | "babel-preset-es2015": "^6.24.0", 25 | "babel-preset-stage-3": "^6.22.0" 26 | }, 27 | "devDependencies": { 28 | "babel-tape-runner": "^2.0.1", 29 | "coveralls": "^2.13.0", 30 | "nyc": "^10.2.0", 31 | "tape": "^4.6.3" 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2017 playground 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | 23 | 24 | Number Formatter 25 | ========= 26 | 27 | A small library that adds commas to numbers 28 | 29 | ## Installation 30 | 31 | `npm install @physicalweb/number-formatter` 32 | 33 | ## Usage 34 | 35 | var numFormatter = require('@physicalweb/number-formatter'); 36 | 37 | var formattedNum = numFormatter(35666); 38 | 39 | 40 | Output should be `35,666` 41 | 42 | 43 | ## Tests 44 | 45 | `npm test` 46 | 47 | ## Contributing 48 | 49 | In lieu of a formal style guide, take care to maintain the existing coding style. Add unit tests for any new or changed functionality. Lint and test your code. --------------------------------------------------------------------------------