Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

Client/Brower side and Bower. #1

Merged
merged 2 commits into from

2 participants

@bostrt

I've added support for client/browsers and installation via Bower. I have not deployed on Bower, I'll leave that to you if you wish.

Note that there are a lot of white-space changes in index.js but it's because I've wrapped the main code in a immediate invocation function call and had to tab everything over.

@domharrington domharrington merged commit d56de60 into from
@domharrington

Thanks for this. I've fixed the whitespace to reflect the style guide and ensure jshint passes.

I think i've published to bower correctly but have never done it before. Can you confirm?

@bostrt

@domharrington I was able to install number-abbreviate via bower without any trouble. It pulled version 0.0.2. You deployed correctly.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Feb 6, 2014
  1. @bostrt

    Added bower.json, not deployed to bower yet. Change library to be imm…

    bostrt authored
    …ediately invoked and added export for client side.
  2. @bostrt
This page is out of date. Refresh to see the latest.
Showing with 52 additions and 18 deletions.
  1. +24 −0 bower.json
  2. +27 −17 index.js
  3. +1 −1  package.json
View
24 bower.json
@@ -0,0 +1,24 @@
+{
+ "name": "number-abbreviate",
+ "main": "index.js",
+ "version": "0.0.2",
+ "homepage": "https://github.com/domharrington/js-number-abbreviate",
+ "description": "Abbreviate a number and add unit letters e.g. 2200000 => '2.2m'",
+ "keywords": [
+ "number",
+ "number-abbreviate",
+ "abbreviate"
+ ],
+ "authors": [
+ "Dom Harrington <dom@harrington-mail.com>"
+ ],
+ "license": "BSD-2-Clause",
+ "ignore": [
+ "**/.*",
+ "node_modules",
+ "bower_components",
+ "test",
+ "tests",
+ "test.js"
+ ]
+}
View
44 index.js
@@ -1,25 +1,35 @@
-module.exports = function numberAbbreviate(number, decPlaces) {
- decPlaces = Math.pow(10, decPlaces)
+(function(root){
+ 'use strict';
- var abbrev = [ 'k', 'm', 'b', 't' ]
+ var numberAbbreviate = function(number, decPlaces) {
+ decPlaces = Math.pow(10, decPlaces)
- for (var i = abbrev.length - 1; i>=0; i--) {
+ var abbrev = [ 'k', 'm', 'b', 't' ]
- var size = Math.pow(10, (i + 1) * 3)
+ for (var i = abbrev.length - 1; i>=0; i--) {
- if(size <= number) {
- number = Math.round(number * decPlaces / size) / decPlaces
+ var size = Math.pow(10, (i + 1) * 3)
- if((number === 1000) && (i < abbrev.length - 1)) {
- number = 1
- i++
- }
+ if(size <= number) {
+ number = Math.round(number * decPlaces / size) / decPlaces
- number += abbrev[i]
+ if((number === 1000) && (i < abbrev.length - 1)) {
+ number = 1
+ i++
+ }
- break
- }
- }
+ number += abbrev[i]
+
+ break
+ }
+ }
- return number
-}
+ return number
+ };
+
+ if (typeof module !== 'undefined' && module.exports) {
+ module.exports = numberAbbreviate;
+ } else {
+ root.numberAbbreviate = numberAbbreviate;
+ }
+})(this);
View
2  package.json
@@ -1,6 +1,6 @@
{
"name": "number-abbreviate",
- "version": "0.0.1",
+ "version": "0.0.2",
"description": "Abbreviate a number and add unit letters e.g. 2200000 => '2.2m'",
"author": "Dom Harrington <dom@harrington-mail.com>",
"main": "index.js",
Something went wrong with that request. Please try again.