Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Regex flags #185

Open
wants to merge 82 commits into
base: dev
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
82 commits
Select commit Hold shift + click to select a range
29917fb
demo page and styles
Aug 21, 2011
78acf65
demo page and styles
Aug 21, 2011
c206a39
demo page and styles
Aug 21, 2011
6e84b31
demo page and styles
Aug 21, 2011
aded750
demo page and styles
Aug 21, 2011
425285c
demo page and styles
Aug 21, 2011
cb543c0
demo page and styles
Aug 21, 2011
937fc3a
demo page and styles
Aug 21, 2011
72449c7
demo page and styles
Aug 21, 2011
9c8904a
demo page and styles
Aug 21, 2011
91bb797
demo page and styles
Aug 21, 2011
f9ac715
demo page and styles
Aug 21, 2011
b69d4dd
Updated demo page, more docs to come.
Aug 23, 2011
840bb83
Updated demo page, more docs to come.
Aug 23, 2011
0d21af2
Updated demo page, more docs to come.
Aug 23, 2011
25507b8
Added documentation to plugin page
Aug 23, 2011
cc50c90
Added documentation
Aug 23, 2011
784636f
updated homepage demos and docs
Aug 23, 2011
b7df17f
updated homepage demos and docs
Aug 23, 2011
1da7986
fixed bug in library homepage
Aug 23, 2011
1b695c8
moar library homepage
Aug 23, 2011
4bcff07
Updated docs and examples
Aug 24, 2011
7244505
Updated docs and examples
Aug 24, 2011
c222ad6
Updated docs and examples
Aug 24, 2011
4ff5515
update demo page
Aug 28, 2011
52c53df
remove everything real quick
Oct 5, 2011
49ae746
Merge branch 'master' into gh-pages
Oct 5, 2011
dbb9703
Merge branch 'master' into gh-pages
Oct 5, 2011
330e65a
Merge branch 'master' into gh-pages
Oct 14, 2011
8fd29f0
Merge branch 'master' into gh-pages
Oct 19, 2011
9adde16
Merge branch 'master' into gh-pages
Oct 21, 2011
7a8496f
Merge branch 'master' into gh-pages
Oct 21, 2011
bac3c78
Added patch to allow for module use with Titanium Appcelerator
Oct 26, 2011
969d942
simplified module definition a little based on underscore.js
Dec 9, 2011
841f390
Merge branch 'master' into dev
Dec 9, 2011
46443d1
update license to MIT. go nuts\!
Dec 9, 2011
05e3b1b
Merge branch 'master' into dev
Dec 9, 2011
75ac3b6
Merge branch 'master' into gh-pages
Dec 9, 2011
96ec1e9
re-build and bump version number
Dec 9, 2011
5287192
Merge branch 'master' into dev
Dec 9, 2011
5321253
Merge branch 'master' into gh-pages
Dec 9, 2011
b1257e1
changed usage to reflect actual parameter order
maiwald Jan 26, 2012
924fa70
Merge pull request #37 from maiwald/patch-1
Jan 27, 2012
4877387
Merge branch 'master' of github.com:josscrowcroft/accounting.js into dev
Jan 28, 2012
447802f
package.json dependencies should be an object
Jan 28, 2012
2179557
bump version number
Jan 28, 2012
335d366
overhaul readme for 0.3.2
Jan 28, 2012
9ff4a40
merge changes from dev into master, leave experimental bits
Jan 28, 2012
1f22b43
unformat() uses by default the decimal separator provided in settings
fmntf May 29, 2012
8f733a9
Fixed isObject for Internet Explorer 7
keithpitt May 30, 2012
df6e8c9
Merge pull request #44 from keithpitt/master
May 31, 2012
0266259
number decimal separator instead of currency separator
fmntf May 31, 2012
d29a764
Merge pull request #43 from fmntf/master
May 31, 2012
1c3ffe8
fix reference to settings
ryanwood Jun 9, 2012
e426519
Merge pull request #46 from ryanwood/master
Jun 10, 2012
4a95cc7
v0.4 updates
Jul 14, 2014
7cc2e47
merge new version, from gh-pages
Jul 14, 2014
705c93a
update project page
Jul 14, 2014
6962c8d
project homepage updates
Jul 15, 2014
75ea0b9
v0.4.1
Jul 15, 2014
a58e7d3
bump version number in library
Jul 15, 2014
71db285
update readme
Jul 15, 2014
9b73d76
package.json
Jul 16, 2014
76847ff
added bower file.
wbotelhos Mar 26, 2015
541d749
removed lost comma
wbotelhos Jun 15, 2015
f290abd
Merge pull request #106 from wbotelhos/master
Jun 16, 2015
15e38ac
v0.4.2
Jun 17, 2015
2cd2152
bump version number in library
mrmoses Sep 21, 2015
7fc57bd
Add license info to package.json
reiz Jul 18, 2016
d3bdf03
Comment typo
joeljuca Nov 1, 2016
5dc3690
updated formatColumn to only accept an array as the first argument
jjsquillante Jan 14, 2017
f4219d8
Merge pull request #160 from jjsquillante/master
wjcrowcroft Jan 17, 2017
12f20f8
Merge pull request #156 from joelwallis/comment-typo
wjcrowcroft Jan 17, 2017
1dca38d
Merge pull request #157 from jasonpberry/master
jasonpberry Jan 17, 2017
84d3c10
Merge pull request #149 from reiz/patch-1
wjcrowcroft Jan 17, 2017
f312645
Merge pull request #115 from mrmoses/patch-1
wjcrowcroft Jan 17, 2017
ab30b96
update regex to get all unformat jasmine tests to pass.
jjsquillante Jan 28, 2017
28dff4d
Merge pull request #162 from jjsquillante/master
wjcrowcroft Jan 29, 2017
9d65e65
Updated toFixed method to handle all cases
gustavlrsn Mar 8, 2017
7a8b659
Added a test case for additional floating point error
gustavlrsn Mar 8, 2017
74a2b12
Merge pull request #164 from gustavlrsn/master
wjcrowcroft Mar 16, 2017
09c6b34
Fix RegExp
ibrahimbutt Nov 13, 2017
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
56 changes: 32 additions & 24 deletions accounting.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
/*!
* accounting.js javascript library v0.3.0
* http://josscrowcroft.github.com/accounting.js/
* accounting.js v0.4.2
* Copyright 2014 Open Exchange Rates
*
* Copyright 2011 by Joss Crowcroft
* Licensed under GPL v3 | http://www.gnu.org/licenses/gpl-3.0.txt
* Freely distributable under the MIT license.
* Portions of accounting.js are inspired or borrowed from underscore.js
*
* Full details and documentation:
* http://openexchangerates.github.io/accounting.js/
*/

(function(root, undefined) {
Expand All @@ -14,7 +17,7 @@
var lib = {};

// Current version
lib.version = '0.3.0';
lib.version = '0.4.2';


/* --- Exposed settings --- */
Expand Down Expand Up @@ -55,7 +58,7 @@
}

/**
* Tests whether supplied parameter is a string
* Tests whether supplied parameter is an array
* from underscore.js, delegates to ECMA5's native Array.isArray
*/
function isArray(obj) {
Expand All @@ -66,7 +69,7 @@
* Tests whether supplied parameter is a true object
*/
function isObject(obj) {
return toString.call(obj) === '[object Object]';
return obj && toString.call(obj) === '[object Object]';
}

/**
Expand Down Expand Up @@ -163,10 +166,11 @@

/**
* Takes a string/array of strings, removes all formatting/cruft and returns the raw float value
* alias: accounting.`parse(string)`
* Alias: `accounting.parse(string)`
*
* Decimal must be included in the regular expression to match floats (default: "."), so if the number
* uses a non-standard decimal separator, provide it as the second argument.
* Decimal must be included in the regular expression to match floats (defaults to
* accounting.settings.number.decimal), so if the number uses a non-standard decimal
* separator, provide it as the second argument.
*
* Also matches bracketed negatives (eg. "$ (1.99)" => -1.99)
*
Expand All @@ -186,14 +190,14 @@
// Return the value as-is if it's already a number:
if (typeof value === "number") return value;

// Default decimal point is "." but could be set to eg. "," in opts:
decimal = decimal || ".";
// Default decimal point comes from settings, but could be set to eg. "," in opts:
decimal = decimal || lib.settings.number.decimal;

// Build regex to strip out everything except digits, decimal point and minus sign:
var regex = new RegExp("[^0-9-" + decimal + "]", ["g"]),
var regex = new RegExp("[^0-9-" + decimal + "]", "g"),
unformatted = parseFloat(
("" + value)
.replace(/\((.*)\)/, "-$1") // replace bracketed values with negatives
.replace(/\((?=\d+)(.*)\)/, "-$1") // replace bracketed values with negatives
.replace(regex, '') // strip out any cruft
.replace(decimal, '.') // make sure decimal point is standard
);
Expand All @@ -211,20 +215,22 @@
*/
var toFixed = lib.toFixed = function(value, precision) {
precision = checkPrecision(precision, lib.settings.number.precision);
var power = Math.pow(10, precision);

// Multiply up by precision, round accurately, then divide and use native toFixed():
return (Math.round(lib.unformat(value) * power) / power).toFixed(precision);
var exponentialForm = Number(lib.unformat(value) + 'e' + precision);
var rounded = Math.round(exponentialForm);
var finalResult = Number(rounded + 'e-' + precision).toFixed(precision);
return finalResult;
};


/**
* Format a number, with comma-separated thousands and custom precision/decimal places
* Alias: `accounting.format()`
*
* Localise by overriding the precision and thousand / decimal separators
* 2nd parameter `precision` can be an object matching `settings.number`
*/
var formatNumber = lib.formatNumber = function(number, precision, thousand, decimal) {
var formatNumber = lib.formatNumber = lib.format = function(number, precision, thousand, decimal) {
// Resursively format arrays:
if (isArray(number)) {
return map(number, function(val) {
Expand Down Expand Up @@ -261,8 +267,8 @@
/**
* Format a number into currency
*
* Usage: accounting.formatMoney(number, precision, symbol, thousandsSep, decimalSep, format)
* defaults: (0, 2, "$", ",", ".", "%s%v")
* Usage: accounting.formatMoney(number, symbol, precision, thousandsSep, decimalSep, format)
* defaults: (0, "$", 2, ",", ".", "%s%v")
*
* Localise by overriding the symbol, precision, thousand / decimal separators and format
* Second param can be an object matching `settings.currency` which is the easiest way.
Expand Down Expand Up @@ -316,7 +322,7 @@
* browsers from collapsing the whitespace in the output strings.
*/
lib.formatColumn = function(list, symbol, precision, thousand, decimal, format) {
if (!list) return [];
if (!list || !isArray(list)) return [];

// Build options object from second param (if object) or all params, extending defaults:
var opts = defaults(
Expand Down Expand Up @@ -375,9 +381,11 @@

// Export accounting for CommonJS. If being loaded as an AMD module, define it as such.
// Otherwise, just add `accounting` to the global object
if (typeof module !== 'undefined' && module.exports) {
module.exports = lib;
lib.accounting = lib;
if (typeof exports !== 'undefined') {
if (typeof module !== 'undefined' && module.exports) {
exports = module.exports = lib;
}
exports.accounting = lib;
} else if (typeof define === 'function' && define.amd) {
// Return the library as an AMD module:
define([], function() {
Expand Down
6 changes: 4 additions & 2 deletions accounting.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 10 additions & 0 deletions bower.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"author" : "Open Exchange Rates <[email protected]> (https://www.openexchangerates.org)",
"description" : "number, money and currency formatting library",
"homepage" : "http://openexchangerates.github.io/accounting.js",
"ignore" : ["**/.*", "tests"],
"keywords" : ["accounting", "number", "money", "currency", "format", "utilities", "finance", "exchange"],
"main" : "accounting.js",
"name" : "accounting",
"version" : "0.4.2"
}
77 changes: 0 additions & 77 deletions extensions/accounting-jquery.js

This file was deleted.

49 changes: 0 additions & 49 deletions extensions/accounting-units.js

This file was deleted.

Loading