From 40f897e822cfa30af78a1b4398f4f0e6b5ab4952 Mon Sep 17 00:00:00 2001 From: Daniel Date: Fri, 5 Apr 2013 16:55:16 +0200 Subject: [PATCH 01/19] Added to parse the same optional config argument that format uses. Added tests, updated the API docs and user guide. --- .../docs/datatype-numberparse.mustache | 37 +++++++ src/datatype/docs/index.mustache | 26 +++-- ...datatype-numberparseconfig-source.mustache | 40 ++++++++ src/number/js/number-parse.js | 39 +++++++- src/number/tests/unit/assets/number-tests.js | 98 +++++++++++++++---- 5 files changed, 211 insertions(+), 29 deletions(-) create mode 100644 src/datatype/docs/partials/datatype-numberparseconfig-source.mustache diff --git a/src/datatype/docs/datatype-numberparse.mustache b/src/datatype/docs/datatype-numberparse.mustache index 6428c9c1af9..d947c6f7232 100644 --- a/src/datatype/docs/datatype-numberparse.mustache +++ b/src/datatype/docs/datatype-numberparse.mustache @@ -39,3 +39,40 @@ YUI().use("datatype-number", function(Y) { }); ``` +

A configuration argument can be added to deal with these numbers.

+``` +YUI().use("datatype-number", function(Y) { + var output = Y.Number.parse("$100", { + prefix:'$' + }); + // output is 100 + + output = Y.Number.parse("20 dollars", { + suffix: 'dollars' + }); + // output is 20 + + output = Y.Number.parse("3,000,000.12" ,{ + thousandsSeparator: ',' + }); + // output is 3000000.12 + + output = Y.Number.parse(new Date("Jan 1, 2000")); + // output is 946713600000 + +}); +``` +

+The following example uses the following configuration: +

+``` +{ + decimalSeparator: ',', + thousandsSeparator: '.', + prefix: '€', + suffix: '(EUR)' +} +``` +
+ {{>datatype-numberparseconfig-source}} +
diff --git a/src/datatype/docs/index.mustache b/src/datatype/docs/index.mustache index 117709f857b..f8e7807a5ee 100644 --- a/src/datatype/docs/index.mustache +++ b/src/datatype/docs/index.mustache @@ -1,15 +1,15 @@

- The DataType Utility is a collection of classes that provide type-conversion and + The DataType Utility is a collection of classes that provide type-conversion and string-formatting convenience methods for numbers, dates, and XML documents.

- + {{>getting-started}} - +

Using the DataType utility

- +

Dates

Formatting dates

@@ -37,7 +37,7 @@ YUI({lang:"ko-KR"}).use("datatype-date", function(Y) { href="{{apiDocs}}/classes/Date.html#method_format"> strftime format specifiers:

- +