Commit 0756ecc6 authored by Zéfling's avatar Zéfling 🎨
Browse files

Negative numbers for Number._parse (0.1f)

parent a8f73cd4
var baku = {};
baku.version = '0.1e';
baku.version = '0.1f';
/**
* test if it's a string
......
......@@ -136,7 +136,7 @@ Number._parse = function (string, params) {
lg = params.lg || navigator.language,
dot = RegExp._toRegexString(params.dot || baku.lg(lg, 'number.dot')),
space = RegExp._toRegexString(params.space || baku.lg(lg, 'number.space')),
match = string.match(new RegExp('(\\d*((' + space + ')\\d*)*\\d)((' + dot + ')(\\d*))?', 'g') );
match = string.match(new RegExp('-?(\\d*((' + space + ')\\d*)*\\d)((' + dot + ')(\\d*))?', 'g') );
if (match[0]) {
number = +(match[0].replace(new RegExp(space, 'g'), '').replace(new RegExp(dot), '.'));
}
......
......@@ -10,4 +10,4 @@ elif [ "$1" = 'dom' ]; then
else
cat baku.js baku.math.js baku.number.js baku.date.js baku.regexp.js baku.string.js baku.string.formater.js | closure-compiler --js_output_file="baku$name.min.js"
fi
sed -i '1i/*! BakuJs v0.1e | (c) Zefling | license, see: github.com/Zefling/BakuJS */' "baku$name.min.js"
\ No newline at end of file
sed -i '1i/*! BakuJs v0.1f | (c) Zefling | license, see: github.com/Zefling/BakuJS */' "baku$name.min.js"
\ No newline at end of file
......@@ -204,6 +204,10 @@ window.onload = function(){
Test.equals("Number._parse('1 000\u00A0000', {space : ' '})", '1000', "1 000\u00A0000 → 1000");
Test.equals("Number._parse('1.2', {dot : '.'})", '1.2', "1.2 → 1.2");
Test.equals("Number._parse('1,2', {dot : ['.', ',']})", '1.2', "1,2 → 1.2");
Test.equals("Number._parse('-1,2', {lg : 'fr'})", '-1.2', "-1,2 → -1.2");
Test.equals("Number._parse('-1\u00A0234,5', {lg : 'fr'})", '-1234.5', "-1\u00A0234,5 → -1234.5");
Test.equals("Number._parse('a -1\u00A0234,5 b',{lg : 'fr'})", '-1234.5', "a -1\u00A0234,5 b → -1234.5");
Test.equals("Number._parse('a-1\u00A0234,5b', {lg : 'fr'})", '-1234.5', "a-1\u00A0234,5b → -1234.5");
Test.title("String.prototype._padLeft()");
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment