Permalink
Browse files

Add grunt build, cleaned up code for jshint

  • Loading branch information...
Mottie committed May 1, 2014
1 parent 8e488e2 commit 3093b4d8730251431def9f8f7c2d7a4b80531d4b
Showing with 388 additions and 86 deletions.
  1. +1 −0 .gitignore
  2. +24 −0 .jshintrc
  3. +4 −0 .travis.yml
  4. +81 −0 Gruntfile.js
  5. +5 −0 bower.json
  6. +0 −75 format.js
  7. +0 −9 format.min.js
  8. +2 −2 index.html
  9. +80 −0 lib/format.js
  10. +2 −0 lib/format.min.js
  11. +57 −0 package.json
  12. +68 −0 src/format.js
  13. +21 −0 test/index.html
  14. +43 −0 test/test.js
@@ -49,6 +49,7 @@ local.properties
# Build results
[Dd]ebug/
[Rr]elease/
node_modules/
*_i.c
*_p.c
*.ilk
@@ -0,0 +1,24 @@
{
"bitwise" : true,
"camelcase" : true,
"curly" : true,
"eqeqeq" : true,
"es3" : true,
"eqnull" : true,
"forin" : true,
"freeze" : true,
"immed" : true,
"indent" : 2,
"jquery" : true,
"latedef" : true,
"newcap" : true,
"noarg" : true,
"noempty" : true,
"nonbsp" : true,
"nonew" : true,
"quotmark" : true,
"sub" : true,
"trailing" : true,
"undef" : true,
"unused" : true
}
@@ -0,0 +1,4 @@
language: node_js
node_js:
- "0.11"
- "0.10"
@@ -0,0 +1,81 @@
/*global module:false*/
module.exports = function(grunt) {
'use strict';
// Project configuration.
grunt.initConfig({
pkg: grunt.file.readJSON( 'package.json' ),
clean: {
build: [ 'lib' ]
},
concat: {
options: {
banner: '/**\n' +
' * <%= pkg.name %>\n' +
' * <%= pkg.description %>\n' +
' *\n' +
' * @preserve IntegraXor Web SCADA - JavaScript Number Formatter (http://www.integraxor.com/)\n' +
' * @author <%= pkg.author.name %>\n' +
' * @maintainer <%= pkg.maintainers[0].name %>\n' +
' * @copyright <%= grunt.template.today("yyyy") %> ecava\n' +
' * @license <%= pkg.licenses[0].type %> <<%= pkg.licenses[0].url %>>\n' +
' * @link <%= pkg.homepage %>\n' +
' * @version <%= pkg.version %>\n' +
' */\n'
},
dist: {
src: [
'src/format.js'
],
dest : 'lib/format.js'
}
},
jshint: {
files: {
src: [
'Gruntfile.js',
'src/**/*.js',
'test/*.js'
]
},
options: {
jshintrc: '.jshintrc'
}
},
uglify: {
options: {
banner: '/*! <%= pkg.name %> - v<%= pkg.version %> * IntegraXor Web SCADA - http://www.integraxor.com/ */\n',
report: 'gzip'
},
dist: {
files: {
'lib/format.min.js': ['<banner>','lib/format.js']
}
}
},
qunit: {
files: ['test/index.html']
},
watch: {
scripts: {
files: ['src/**/*.js'],
tasks: ['build']
}
}
});
grunt.loadNpmTasks('grunt-contrib-clean' );
grunt.loadNpmTasks('grunt-contrib-jshint');
grunt.loadNpmTasks('grunt-contrib-qunit');
grunt.loadNpmTasks('grunt-contrib-concat');
grunt.loadNpmTasks('grunt-contrib-uglify');
grunt.loadNpmTasks('grunt-contrib-watch');
// Default task.
grunt.registerTask('build', ['clean:build', 'concat', 'uglify']);
grunt.registerTask('test', ['jshint', 'qunit']);
grunt.registerTask('default', ['test', 'build']);
};
@@ -0,0 +1,5 @@
{
"name": "format.js",
"version": "1.0.1",
"main": "format.min.js"
}

This file was deleted.

Oops, something went wrong.

This file was deleted.

Oops, something went wrong.
@@ -192,8 +192,8 @@ <h3>See also...</h3>
</p>
-->
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script>
<script type="text/javascript" src="format.js"></script>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script>
<script src="lib/format.js"></script>
<script>
var i = 0;
$('.row').each( function() {
@@ -0,0 +1,80 @@
/**
* format.js
* Lightweight & Fast JavaScript Number Formatter
*
* @preserve IntegraXor Web SCADA - JavaScript Number Formatter (http://www.integraxor.com/)
* @author KPL
* @maintainer Rob Garrison
* @copyright 2014 ecava
* @license MIT <http://www.opensource.org/licenses/mit-license.php>
* @link http://mottie.github.com/javascript-number-formatter/
* @version 1.0.1
*/
/*jshint browser:true */
window.format = function( m, v ){
if ( !m || isNaN(+v) ) {
return v; // return as it is.
}
var isNegative, result, decimal, group, posLeadZero, posTrailZero, posSeparator, part, szSep,
integer, str, offset, i, l;
// convert any string to number according to formation sign.
v = m.charAt(0) === '-' ? -v : +v;
isNegative = v < 0? v = -v: 0; // process only abs(), and turn on flag.
// search for separator for grp & decimal, anything not digit, not +/- sign, not #.
result = m.match(/[^\d\-\+#]/g);
decimal = (result && result[result.length-1]) || '.'; // treat the right most symbol as decimal
group = (result && result[1] && result[0]) || ','; // treat the left most symbol as group separator
// split the decimal for the format string if any.
m = m.split( decimal );
// Fix the decimal first, toFixed will auto fill trailing zero.
v = v.toFixed( m[1] && m[1].length );
v = +(v) + ''; // convert number to string to trim off *all* trailing decimal zero(es)
// fill back any trailing zero according to format
posTrailZero = m[1] && m[1].lastIndexOf('0'); // look for last zero in format
part = v.split('.');
// integer will get !part[1]
if ( !part[1] || part[1] && part[1].length <= posTrailZero ) {
v = (+v).toFixed( posTrailZero + 1 );
}
szSep = m[0].split( group ); // look for separator
m[0] = szSep.join(''); // join back without separator for counting the pos of any leading 0.
posLeadZero = m[0] && m[0].indexOf('0');
if ( posLeadZero > -1 ) {
while ( part[0].length < (m[0].length - posLeadZero) ) {
part[0] = '0' + part[0];
}
} else if (+part[0] === 0){
part[0] = '';
}
v = v.split('.');
v[0] = part[0];
// process the first group separator from decimal (.) only, the rest ignore.
// get the length of the last slice of split result.
posSeparator = ( szSep[1] && szSep[ szSep.length - 1 ].length );
if ( posSeparator ) {
integer = v[0];
str = '';
offset = integer.length % posSeparator;
l = integer.length;
for (i = 0; i < l; i++) {
str += integer.charAt(i); // ie6 only support charAt for sz.
// -posSeparator so that won't trail separator on full length
/*jshint -W018 */
if ( !( (i - offset + 1) % posSeparator ) && i < l - posSeparator ) {
str += group;
}
}
v[0] = str;
}
v[1] = ( m[1] && v[1] ) ? decimal + v[1] : '';
return ( isNegative ? '-' : '' ) + v[0] + v[1]; // put back any negation and combine integer and fraction.
};

Some generated files are not rendered by default. Learn more.

Oops, something went wrong.
@@ -0,0 +1,57 @@
{
"name": "format.js",
"description": "Lightweight & Fast JavaScript Number Formatter",
"version": "1.0.1",
"homepage": "http://mottie.github.com/javascript-number-formatter/",
"main": "lib/format.min.js",
"demo": "https://github.com/Mottie/javascript-number-formatter/index.html",
"repository": {
"type": "git",
"url": "git://github.com/Mottie/javascript-number-formatter.git"
},
"author": {
"name": "KPL",
"url": "https://code.google.com/u/100789773228459308870/"
},
"maintainers": [
{
"name": "Rob Garrison",
"url": "https://github.com/Mottie",
"email": "wowmotty@gmail.com"
}
],
"licenses": [
{
"type": "MIT",
"url": "http://www.opensource.org/licenses/mit-license.php"
},
{
"type": "GPL",
"url": "http://www.gnu.org/licenses/old-licenses/gpl-2.0.html"
}
],
"bugs": "https://github.com/Mottie/javascript-number-formatter/issues",
"docs": "http://mottie.github.com/javascript-number-formatter/index.html",
"keywords": [
"number",
"format",
"formatter",
"currency"
],
"files": [
"format.js"
],
"scripts": {
"test": "grunt test"
},
"devDependencies": {
"grunt": "^0.4.4",
"grunt-cli": "~0.1.13",
"grunt-contrib-jshint": "~0.9.2",
"grunt-contrib-qunit": "~0.4.0",
"grunt-contrib-concat": "~0.3.0",
"grunt-contrib-uglify": "~0.4.0",
"grunt-contrib-clean": "~0.5.0",
"grunt-contrib-watch": "~0.6.1"
}
}
Oops, something went wrong.

0 comments on commit 3093b4d

Please sign in to comment.