diff --git a/CHANGELOG.md b/CHANGELOG.md index 6a32532..137ae66 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,10 @@ # Change Log All notable changes to this project will be documented in this file. +## [0.0.6] - 2020-11-01 +### Changed +- Add linter and update dependencies. + ## [0.0.5] - 2016-02-11 ### Changed - Stringify input value of any type first before attempting to commafy. diff --git a/LICENSE.md b/LICENSE similarity index 100% rename from LICENSE.md rename to LICENSE diff --git a/README.md b/README.md index ccd4226..956791b 100644 --- a/README.md +++ b/README.md @@ -1,25 +1,25 @@ # commafy -Add commas to a number. +> Add commas to a number. -# Install +## Install ```bash npm install commafy ``` -# Usage +## Usage ```javascript -var commafy = require('commafy'); +var commafy = require('commafy') -console.log(commafy(1000000)); // '1,000,000' -console.log(commafy(1000)); // '1,000' -console.log(commafy(1000.123)); // '1,000.123' -console.log(commafy(100)); // '100' -console.log(commafy(1e4)); // '10,000' +console.log(commafy(1000000)) // '1,000,000' +console.log(commafy(1000)) // '1,000' +console.log(commafy(1000.123)) // '1,000.123' +console.log(commafy(100)) // '100' +console.log(commafy(1e4)) // '10,000' ``` -# License +## License -MIT +[MIT](LICENSE) diff --git a/bower.json b/bower.json deleted file mode 100644 index d332313..0000000 --- a/bower.json +++ /dev/null @@ -1,22 +0,0 @@ -{ - "name": "commafy", - "main": "commafy.js", - "version": "0.0.5", - "homepage": "https://github.com/miguelmota/commafy", - "authors": [ - "Miguel Mota " - ], - "description": "Add commas to a number", - "keywords": [ - "number", - "commafy" - ], - "ignore": [ - "**/.*", - "node_modules", - "bower_components", - "test", - "tests" - ], - "license": "MIT" -} diff --git a/commafy.js b/commafy.js index 6954763..8851107 100644 --- a/commafy.js +++ b/commafy.js @@ -1,35 +1,33 @@ -(function(){ - - function isNumeric(val) { +;(function () { + function isNumeric (val) { if (typeof val === 'number' && !isNaN(val)) { - return true; + return true } - val = (val||'').toString().trim(); - return val && !isNaN(val); + val = (val || '').toString().trim() + return val && !isNaN(val) } - function commafy(val) { + function commafy (val) { if (typeof val === 'undefined' || val === null) { - val = ''; + val = '' } - val = val.toString(); + val = val.toString() if (!isNumeric(val)) { - return val; + return val } - var parts = val.split('.'); + var parts = val.split('.') - parts[0] = parts[0].replace(/\B(?=(\d{3})+(?!\d))/g, ','); - return parts.join('.'); + parts[0] = parts[0].replace(/\B(?=(\d{3})+(?!\d))/g, ',') + return parts.join('.') } if (typeof module !== 'undefined' && typeof module.exports !== 'undefined') { - module.exports = commafy; + module.exports = commafy } else { - window.commafy = commafy; + window.commafy = commafy } - })(); diff --git a/package.json b/package.json index 3854b96..0418fad 100644 --- a/package.json +++ b/package.json @@ -1,13 +1,14 @@ { "name": "commafy", - "version": "0.0.5", + "version": "0.0.6", "description": "Add commas to a number", "main": "commafy.js", "directories": { "test": "test" }, "scripts": { - "test": "tape test/*.js" + "test": "tape test/*.js", + "lint": "standard --fix commafy.js test/commafy.test.js" }, "repository": { "type": "git", @@ -23,7 +24,9 @@ "url": "https://github.com/miguelmota/commafy/issues" }, "homepage": "https://github.com/miguelmota/commafy", - "dependencies": { - "tape": "^3.0.3" + "dependencies": {}, + "devDependencies": { + "standard": "^16.0.1", + "tape": "^5.0.1" } } diff --git a/test/commafy.js b/test/commafy.js deleted file mode 100644 index 5642d40..0000000 --- a/test/commafy.js +++ /dev/null @@ -1,36 +0,0 @@ -var test = require('tape'); -var commafy = require('../commafy'); - -test('commafy', function (t) { - t.plan(28); - - t.equal(commafy(0), '0'); - t.equal(commafy(1000000), '1,000,000'); - t.equal(commafy(1000), '1,000'); - t.equal(commafy(100), '100'); - t.equal(commafy(85), '85'); - t.equal(commafy(10200.50), '10,200.5'); - t.equal(commafy(1000.5023), '1,000.5023'); - t.equal(commafy(14734534.53), '14,734,534.53'); - t.equal(commafy((10200.50).toFixed(3)), '10,200.500'); - t.equal(commafy(1e4), '10,000'); - t.equal(commafy(1e6), '1,000,000'); - - t.equal(commafy(), ''); - t.equal(commafy(''), ''); - t.equal(commafy(null), ''); - t.equal(commafy([]), ''); - t.equal(commafy(true), 'true'); - t.equal(commafy(false), 'false'); - t.equal(commafy(NaN), 'NaN'); - t.equal(commafy({}), '[object Object]'); - t.equal(commafy(function(){}), 'function (){}'); - t.equal(commafy(Infinity), 'Infinity'); - t.equal(commafy(-Infinity), '-Infinity'); - t.equal(commafy('10'), '10'); - t.equal(commafy('10000'), '10,000'); - t.equal(commafy('10000.500'), '10,000.500'); - t.equal(commafy('$58303'), '$58303'); - t.equal(commafy('1024px'), '1024px'); - t.equal(commafy('amount $1000.20'), 'amount $1000.20'); -}); diff --git a/test/commafy.test.js b/test/commafy.test.js new file mode 100644 index 0000000..dd1b925 --- /dev/null +++ b/test/commafy.test.js @@ -0,0 +1,36 @@ +var test = require('tape') +var commafy = require('../commafy') + +test('commafy', function (t) { + t.plan(28) + + t.equal(commafy(0), '0') + t.equal(commafy(1000000), '1,000,000') + t.equal(commafy(1000), '1,000') + t.equal(commafy(100), '100') + t.equal(commafy(85), '85') + t.equal(commafy(10200.50), '10,200.5') + t.equal(commafy(1000.5023), '1,000.5023') + t.equal(commafy(14734534.53), '14,734,534.53') + t.equal(commafy((10200.50).toFixed(3)), '10,200.500') + t.equal(commafy(1e4), '10,000') + t.equal(commafy(1e6), '1,000,000') + + t.equal(commafy(), '') + t.equal(commafy(''), '') + t.equal(commafy(null), '') + t.equal(commafy([]), '') + t.equal(commafy(true), 'true') + t.equal(commafy(false), 'false') + t.equal(commafy(NaN), 'NaN') + t.equal(commafy({}), '[object Object]') + t.equal(commafy(function () {}), 'function () {}') + t.equal(commafy(Infinity), 'Infinity') + t.equal(commafy(-Infinity), '-Infinity') + t.equal(commafy('10'), '10') + t.equal(commafy('10000'), '10,000') + t.equal(commafy('10000.500'), '10,000.500') + t.equal(commafy('$58303'), '$58303') + t.equal(commafy('1024px'), '1024px') + t.equal(commafy('amount $1000.20'), 'amount $1000.20') +})