globalize-rpk 1.7.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (65) hide show
  1. package/CONTRIBUTING.md +5 -0
  2. package/LICENSE +20 -0
  3. package/README.md +818 -0
  4. package/doc/api/core/constructor.md +28 -0
  5. package/doc/api/core/load.md +96 -0
  6. package/doc/api/core/locale.md +43 -0
  7. package/doc/api/currency/currency-formatter.md +196 -0
  8. package/doc/api/currency/currency-to-parts-formatter.md +117 -0
  9. package/doc/api/date/date-formatter.md +203 -0
  10. package/doc/api/date/date-parser.md +60 -0
  11. package/doc/api/date/date-to-parts-formatter.md +176 -0
  12. package/doc/api/date/load-iana-time-zone.md +29 -0
  13. package/doc/api/message/load-messages.md +105 -0
  14. package/doc/api/message/message-formatter.md +208 -0
  15. package/doc/api/number/number-formatter.md +202 -0
  16. package/doc/api/number/number-parser.md +130 -0
  17. package/doc/api/number/number-to-parts-formatter.md +140 -0
  18. package/doc/api/plural/plural-generator.md +84 -0
  19. package/doc/api/relative-time/relative-time-formatter.md +60 -0
  20. package/doc/api/unit/unit-formatter.md +72 -0
  21. package/doc/blog-post/2017-07-xx-1.3.0-announcement.md +177 -0
  22. package/doc/cldr.md +114 -0
  23. package/doc/error/e-default-locale-not-defined.md +9 -0
  24. package/doc/error/e-invalid-cldr.md +14 -0
  25. package/doc/error/e-invalid-par-type.md +12 -0
  26. package/doc/error/e-invalid-par-value.md +11 -0
  27. package/doc/error/e-missing-cldr.md +11 -0
  28. package/doc/error/e-missing-parameter.md +10 -0
  29. package/doc/error/e-missing-plural-module.md +9 -0
  30. package/doc/error/e-par-missing-key.md +11 -0
  31. package/doc/error/e-par-out-of-range.md +13 -0
  32. package/doc/error/e-unsupported.md +10 -0
  33. package/doc/migrating-from-0.x.md +64 -0
  34. package/examples/amd-bower/.bowerrc +7 -0
  35. package/examples/amd-bower/README.md +65 -0
  36. package/examples/amd-bower/bower.json +13 -0
  37. package/examples/amd-bower/index.html +46 -0
  38. package/examples/amd-bower/main.js +141 -0
  39. package/examples/amd-bower/messages/en.json +12 -0
  40. package/examples/amd-bower/package.json +14 -0
  41. package/examples/app-npm-webpack/README.md +74 -0
  42. package/examples/app-npm-webpack/app/index.js +89 -0
  43. package/examples/app-npm-webpack/index-template.html +71 -0
  44. package/examples/app-npm-webpack/messages/ar.json +25 -0
  45. package/examples/app-npm-webpack/messages/de.json +21 -0
  46. package/examples/app-npm-webpack/messages/en.json +21 -0
  47. package/examples/app-npm-webpack/messages/es.json +21 -0
  48. package/examples/app-npm-webpack/messages/pt.json +21 -0
  49. package/examples/app-npm-webpack/messages/ru.json +23 -0
  50. package/examples/app-npm-webpack/messages/zh.json +20 -0
  51. package/examples/app-npm-webpack/package.json +17 -0
  52. package/examples/app-npm-webpack/webpack-config.js +63 -0
  53. package/examples/globalize-compiler/README.md +45 -0
  54. package/examples/globalize-compiler/app.js +58 -0
  55. package/examples/globalize-compiler/development.html +121 -0
  56. package/examples/globalize-compiler/messages.json +12 -0
  57. package/examples/globalize-compiler/package.json +15 -0
  58. package/examples/globalize-compiler/production.html +75 -0
  59. package/examples/node-npm/README.md +57 -0
  60. package/examples/node-npm/main.js +65 -0
  61. package/examples/node-npm/messages/en.json +12 -0
  62. package/examples/node-npm/package.json +10 -0
  63. package/examples/plain-javascript/README.md +81 -0
  64. package/examples/plain-javascript/index.html +445 -0
  65. package/package.json +109 -0
@@ -0,0 +1,177 @@
1
+ # Globalize 1.3.0 announcement
2
+
3
+ On July 3rd, we released Globalize 1.3.0. It is a special release, because it includes some very useful feature enhancements to support advanced date, time, timezone manipulation, and other long due fixes. We wanted to share more details on these improvements.
4
+
5
+ ## IANA/Olson Time Zone Support
6
+
7
+ > This change was contributed by Kandaswamy Manikandan @rajavelmani (PayPal) and Rafael Xavier @rxaviers in #687 and #701.
8
+
9
+ In previous versions, Globalize had some partial time zone support for a user's runtime time zone. However specific CLDR patterns (`z`, `v`, and `V`) that display strings such as `PDT`, `Pacific Daylight Time`, `Pacific Time`, and `Los Angeles Time` could not be displayed. The challenge [we had](https://github.com/globalizejs/globalize/pull/202) to determine how costly a solution would be to provide full IANA/Olson time zone support due to the additional manipulation code and data (i.e., IANA database). Therefore, in the past, we encouraged users that needed to manipulate date in arbitrary time zones to use a separate library, like *moment-timezone*. Nevertheless, this solution never closed the gap between internationalization (i18n) implementations leveraging CLDR and having full maneuverability of time zones.
10
+
11
+ With the latest release 1.3.0, Globalize fully supports time zone. Simply put, by using Globalize 1.3.0, you now have full IANA support with the strength of CLDR for i18n!
12
+
13
+ ```js
14
+ Globalize.locale("en");
15
+ let date = new Date();
16
+
17
+ Globalize.formatDate(date, {datetime: "short", timeZone: "America/Los_Angeles"});
18
+ // > '3/19/17, 3:19 PM'
19
+ Globalize.formatDate(date, {datetime: "short", timeZone: "America/New_York"});
20
+ // > '3/19/17, 6:19 PM'
21
+ Globalize.formatDate(date, {datetime: "short", timeZone: "America/Sao_Paulo"});
22
+ // > '3/19/17, 7:19 PM'
23
+ Globalize.formatDate(date, {datetime: "short", timeZone: "Europe/Berlin"});
24
+ // > '3/19/17, 11:19 PM'
25
+
26
+ Globalize.formatDate(date, {datetime: "full", timeZone: "America/Los_Angeles"});
27
+ // > 'Sunday, March 19, 2017 at 3:19:22 PM Pacific Daylight Time'
28
+ Globalize.formatDate(date, {datetime: "full", timeZone: "America/New_York"});
29
+ // > 'Sunday, March 19, 2017 at 6:19:22 PM Eastern Daylight Time'
30
+ Globalize.formatDate(date, {datetime: "full", timeZone: "America/Sao_Paulo"});
31
+ // > 'Sunday, March 19, 2017 at 7:19:22 PM Brasilia Standard Time'
32
+ Globalize.formatDate(date, {datetime: "full", timeZone: "Europe/Berlin"});
33
+ // > 'Sunday, March 19, 2017 at 11:19:22 PM Central European Standard Time'
34
+
35
+ Globalize("pt").formatDate(date, {datetime: "full", timeZone: "America/Sao_Paulo"});
36
+ // > 'domingo, 19 de março de 2017 19:19:22 Horário Padrão de Brasília'
37
+ Globalize("de").formatDate(date, {datetime: "full", timeZone: "Europe/Berlin"});
38
+ // > 'Sonntag, 19. März 2017 um 23:19:22 Mitteleuropäische Normalzeit'
39
+ Globalize("zh").formatDate(date, {datetime: "full", timeZone: "Asia/Shanghai"});
40
+ // > '2017年3月20日星期一 中国标准时间 上午6:19:22'
41
+ Globalize("ar").formatDate(date, {datetime: "full", timeZone: "Africa/Cairo"});
42
+ // > 'الاثنين، ٢٠ مارس، ٢٠١٧ ١٢:١٩:٢٢ ص توقيت شرق أوروبا الرسمي'
43
+ ```
44
+
45
+ We have solved this in a low footprint, high performance implementation using [zoned-date-time](https://github.com/rxaviers/zoned-date-time) under the hoods, which is a 0.6KB library for the time zone manipulations. We have leveraged the Globalize Compiler for precompling the IANA data base for production. For example, let's say you are serving content in English (e.g. locale en-US) for America/Los_Angeles time using the following formatter:
46
+
47
+ ```js
48
+ var dateWithTimeZoneFormatter = Globalize.dateFormatter({
49
+ datetime: "full",
50
+ timeZone: "America/Los_Angeles"
51
+ });
52
+ ```
53
+
54
+ The final size (for production) of this code will be:
55
+
56
+ | filename | minified+gzipped size |
57
+ | ---------------------------------------- | --------------------- |
58
+ | i18n/en.js (includes CLDR and IANA data) | 1.7KB |
59
+ | core, number, and date globalize runtime lib + zoned-date-time | 7.0KB |
60
+
61
+ See globalize [compiler example](https://github.com/globalizejs/globalize/tree/master/examples/globalize-compiler) or [app-npm-webpack example](https://github.com/globalizejs/globalize/tree/master/examples/app-npm-webpack) for details.
62
+
63
+ ## Format Date To Parts
64
+
65
+ > This change was contributed by Reza Payami @rpayami (PayPal) and Rafael Xavier @rxaviers in #697 and #700.
66
+
67
+ Modern user interfaces often need to manipulate the date format output, which is impossible via the existing format function that returns an opaque string. Making any attempt to do this can break internationalization support. [Ecma-402](https://github.com/tc39/ecma402/) has recently added [`Intl.DateTimeFormat.prototype.formatToParts`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/DateTimeFormat/formatToParts) to fulfill that purpose, which at the time of this post, is at stage 4 and is implemented by latest Firefox and Chrome.
68
+
69
+ In Globalize, we introduced [`.dateToPartsFormatter`](https://github.com/globalizejs/globalize/blob/master/doc/api/date/date-to-parts-formatter.md) and [`.formatDateToParts`](https://github.com/globalizejs/globalize/blob/master/doc/api/date/date-to-parts-formatter.md).
70
+
71
+ ```js
72
+ Globalize.locale( "en" );
73
+ Globalize.formatDateToParts(new Date(2010, 10, 30));
74
+ // > [
75
+ // { "type": "month", "value": "11" },
76
+ // { "type": "literal", "value": "/" },
77
+ // { "type": "day", "value": "30" },
78
+ // { "type": "literal", "value": "/" },
79
+ // { "type": "year", "value": "2010" }
80
+ // ]
81
+ ```
82
+
83
+ The data is available separately and it can be formatted and concatenated again in a customized way. For example by using [`Array.prototype.map()`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/map), [arrow functions](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Functions/Arrow_functions), a [switch statement](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/switch), [template literals](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Template_literals), and [`Array.prototype.reduce()`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/reduce).
84
+
85
+ ```js
86
+ let formatter;
87
+
88
+ Globalize.locale( "en" );
89
+ formatter = Globalize.dateToPartsFormatter({datetime: "short"});
90
+
91
+ formatter( new Date( 2010, 10, 30, 17, 55 ) ).map(({type, value}) => {
92
+ switch ( type ) {
93
+ case "year": return `<strong>${value}</strong>`;
94
+ default: return value;
95
+ }
96
+ }).join( "" );
97
+ // > "11/30/<strong>10</strong>, 5:55 PM"
98
+ ```
99
+
100
+ See [React Date Input](https://github.com/rxaviers/react-date-input) as a demo of a UI component for React optimized for i18n and a11y.
101
+
102
+ | Localized and smart date input | Feb 28 in `en`, `es`, `pt`, `de`, `zh`, `ko`, and `ar` |
103
+ | ---------------------------------------- | ---------------------------------------- |
104
+ | ![en](https://media.giphy.com/media/xUA7aZAUNINGP2jI4M/giphy.gif) | ![en-es-pt-de-zh-ko-ar](https://media.giphy.com/media/3og0ILQu0KxLRewJnW/giphy.gif) |
105
+
106
+ ## Dynamically Augmented Date Skeletons
107
+
108
+ > This change was contributed by Marat Dyatko @vectart and Artur Eshenbrener @Strate in #462 and #604.
109
+
110
+ The style used to display a date format often varies depending on the application. CLDR offers data for certain presets like short (e.g., short date `"7/1/17"`), medium (e.g., medium date `"Jul 1, 2017"`), long (e.g., long date `"July 1, 2017"`), and full (e.g., full date `"Saturday, July 1, 2017"`). Although, we may want something different such as `"Jul 1"`. For that CLDR offers data for individual [date fields](http://www.unicode.org/reports/tr35/tr35-dates.html#Date_Field_Symbol_Table) and their combinations, which are used by Globalize to synthesize an open-ended list of custom formats (called skeletons). But, what's interesting is that it would be prohibitively large if CLDR provided data for every single possible combination. So, there's an algorithm specified by [UTS#35](http://www.unicode.org/reports/tr35/tr35-dates.html#availableFormats_appendItems) to deduce missing data from the requested format.
111
+
112
+ For the `"Jul 1"` example, we should use `{skeleton: "MMMd"}`. Internally, Globalize finds a direct match in CLDR for the requested skeleton. This works fine in previous Globalize versions.
113
+
114
+ For that next example, let's assume we want `"July 1"`, i.e., `{skeleton: "MMMMd"}`. Internally, Globalize doesn't find a direct match in CLDR. For this skeleton, Globalize needs to use the data for `MMMd`, which maps to `"MMM d"` in the English case, and then it needs to replace `MMM` with `MMMM` dynamically generating `"MMMM d"`. This doesn't work in previous versions of Globalize, but it works now on latest v1.3.0.
115
+
116
+ If we wanted `"07/01"` instead, we should use `{skeleton: "MMdd"}`. Internally, Globalize doesn't find a direct match in CLDR for this skeleton and, therefore, it fais in globalize v1.2.3. Globalize needs to use the data for `Md`, which in the case of English maps to `"M/d"`, and then replace `M` wtih `MM` and `d` with `dd` dynamically generating `"MM/dd"`.
117
+
118
+ To make a long story short, the algorithm in globalize v1.3.0 has been significantly improved and it allows using virtually any skeletons.
119
+
120
+ ```js
121
+ // A skeleton not directly found in CLDR and that needs to be deduced by globalize.
122
+ // In English, globalize needs to use the data for GyMMMEd, and adjust MMM with MMMM,
123
+ // and E with EEEE. Then, it needs to find the data for hms and glue them together
124
+ // using the appropriate format.
125
+ // On globalize v1.2.3, an error is thrown saying this skeleton wasn't found.
126
+ let skeleton = "GyMMMMEEEEdhms";
127
+ Globalize("en").formatDate(new Date(), {skeleton});
128
+ // > 'Saturday, July 1, 2017 AD at 4:58:27 PM'
129
+ Globalize("pt").formatDate(new Date(), {skeleton});
130
+ // > 'sábado, 1 de julho de 2017 d.C. 5:01:20 PM'
131
+ Globalize("de").formatDate(new Date(), {skeleton});
132
+ // > 'Samstag, 1. Juli 2017 n. Chr. um 5:01:33 nachm.'
133
+ Globalize("zh").formatDate(new Date(), {skeleton});
134
+ // > '公元2017年七月月1日星期六 下午5:01:35'
135
+ Globalize("ko").formatDate(new Date(), {skeleton});
136
+ // > 'AD 2017년 7월 1일 토요일 오후 5:01:38'
137
+ Globalize("ar").formatDate(new Date(), {skeleton});
138
+ // > 'السبت، ١ يوليو، ٢٠١٧ م ٥:٠١:٤٠ م'
139
+ Globalize("ar-MA").formatDate(new Date(), {skeleton});
140
+ // > 'السبت، 1 يوليوز، 2017 م 5:04:29 م'
141
+ Globalize("it").formatDate(new Date(), {skeleton});
142
+ // > 'sabato 1 luglio 2017 d.C. 5:01:52 PM'
143
+ ```
144
+
145
+ Read our [getting started](https://github.com/globalizejs/globalize/#getting-started) and play with it yourself.
146
+
147
+ ## Other Enhancements and Bug Fixes
148
+
149
+ 🎉 Enhancements
150
+
151
+ - Date: Show timezone offset optional minutes for O pattern (e.g., GMT-6:30 note the :30) [#339](https://github.com/globalizejs/globalize/pull/339) (via PR [#729](https://github.com/globalizejs/globalize/pull/729)) (Rafael Xavier)
152
+ - Date: Show timezone offset optional minutes and seconds for x and X patterns (e.g., -06:30 note the :30) [#339](https://github.com/globalizejs/globalize/pull/339) (via PR [#729](https://github.com/globalizejs/globalize/pull/729)) (Rafael Xavier)
153
+ - Date: Assert options.skeleton (PR [#726](https://github.com/globalizejs/globalize/pull/726)) (Rafael Xavier)
154
+ - Date parser: Make runtime phase lighter [#735](https://github.com/globalizejs/globalize/pull/735) (Rafael Xavier)
155
+ - Date parser: Loose Matching PR [#730](https://github.com/globalizejs/globalize/pull/730) (Rafael Xavier)
156
+ - Allows, among others, parsing arabic dates as user types them (i.e., without control characters)
157
+ - Number formatter: Amend integer and fraction formatter for small numbers like 1e-7 [#750](https://github.com/globalizejs/globalize/pull/750) (Rafael Xavier)
158
+ - Number parser: Lenient about trailing decimal separator [#744](https://github.com/globalizejs/globalize/pull/744) (Rafael Xavier)
159
+ - Runtime: Use strict [#676](https://github.com/globalizejs/globalize/pull/676) (Zack Birkenbuel)
160
+
161
+ 🐛 Fixes
162
+
163
+ - Date parser: invalid output by mixing numbering systems [#696](https://github.com/globalizejs/globalize/pull/696) (via PR [#733](https://github.com/globalizejs/globalize/pull/733)) (Rafael Xavier)
164
+ - Date parser: fails on Turkish full datetime with Monday or Saturday [#690](https://github.com/globalizejs/globalize/pull/690) (via PR [#732](https://github.com/globalizejs/globalize/pull/732)) (Rafael Xavier)
165
+
166
+ ⚙️ Others
167
+
168
+ - Compiler tests! [#721](https://github.com/globalizejs/globalize/pull/721) (via PR [#727](https://github.com/globalizejs/globalize/pull/727)) (Nikola Kovacs)
169
+ - Documentation style refactor [#737](https://github.com/globalizejs/globalize/pull/737) (Rafael Xavier)
170
+
171
+ ## Last but not least
172
+
173
+ Special thanks to other PayPal internationalization team members including Daniel Bruhn, Lucas Welti, Alolita Sharma, Mike McKenna for testing and helping integrate Globalize for PayPal products.
174
+
175
+ Special thanks to James Bellenger and Nicolas Gallagher for the React and Webpack integration enhancements for Twitter products, which certainly deserves its own blog post.
176
+
177
+ Many thanks to all of you who participated in this release by testing, reporting bugs, or submitting patches, including Jörn Zaefferer, Frédéric Miserey, Nova Patch, and whole Globalize team.
package/doc/cldr.md ADDED
@@ -0,0 +1,114 @@
1
+ # Unicode CLDR usage
2
+
3
+ ## How do I get CLDR data?
4
+
5
+ *By downloading the JSON packages individually...*
6
+
7
+ Unicode CLDR is available as JSON at https://github.com/unicode-cldr/ (after this [json-packaging proposal][] took place). Please, read https://github.com/unicode-cldr/cldr-json for more information about package organization.
8
+
9
+ [json-packaging proposal]: http://cldr.unicode.org/development/development-process/design-proposals/json-packaging
10
+
11
+ *By using a package manager...*
12
+
13
+ `cldr-data` can be used for convenience. It always downloads from the correct source.
14
+
15
+ Use bower `bower install cldr-data` ([detailed instructions][]) or npm `npm install cldr-data`. For more information, see:
16
+
17
+ - https://github.com/rxaviers/cldr-data-npm
18
+ - https://github.com/rxaviers/cldr-data-bower
19
+
20
+ [detailed instructions]: https://github.com/rxaviers/cldr-data-bower
21
+
22
+ ## How do I load CLDR data into Globalize?
23
+
24
+ The short answer is by using `Globalize.load()` and passing the JSON data as the first argument. Below, follow several examples on how this could be accomplished.
25
+
26
+ Example of embedding CLDR JSON data:
27
+
28
+ ```html
29
+ <script>
30
+ Globalize.load({
31
+ main: {
32
+ en: {
33
+ ...
34
+ }
35
+ },
36
+ supplemental: {
37
+ likelySubtags: {
38
+ ...
39
+ },
40
+ timeDate: {
41
+ ...
42
+ },
43
+ weekData: {
44
+ ...
45
+ }
46
+ }
47
+ });
48
+ </script>
49
+ ```
50
+
51
+ Example of loading it dynamically:
52
+
53
+ ```html
54
+ <script src="jquery.js"></script>
55
+ <script>
56
+
57
+ // Use $.getJSON instead of $.get if your server is not configured to return the
58
+ // right MIME type for .json files.
59
+ $.when(
60
+ $.get( "cldr/main/en/ca-gregorian.json" ),
61
+ $.get( "cldr/supplemental/likelySubtags.json" ),
62
+ $.get( "cldr/supplemental/timeData.json" ),
63
+ $.get( "cldr/supplemental/weekData.json" )
64
+ ).then(function() {
65
+
66
+ // Normalize $.get results, we only need the JSON, not the request statuses.
67
+ return [].slice.apply( arguments, [ 0 ] ).map(function( result ) {
68
+ return result[ 0 ];
69
+ });
70
+
71
+ }).then( Globalize.load ).then(function() {
72
+
73
+ // Your code goes here.
74
+
75
+ });
76
+
77
+ </script>
78
+ ```
79
+
80
+ Example using AMD (also see our [functional tests](../../test/functional.js)):
81
+ ```javascript
82
+ define([
83
+ "globalize",
84
+ "json!cldr-data/main/en/ca-gregorian.json",
85
+ "json!cldr-data/supplemental/likelySubtags.json",
86
+ "json!cldr-data/supplemental/timeData.json",
87
+ "json!cldr-data/supplemental/weekData.json",
88
+ "globalize/date"
89
+ ], function( Globalize, enCaGregorian, likelySubtags, timeData, weekData ) {
90
+
91
+ Globalize.load(
92
+ enCaGregorian,
93
+ likelySubtags,
94
+ timeData,
95
+ weekData
96
+ );
97
+
98
+ // Your code goes here.
99
+
100
+ });
101
+ ```
102
+
103
+ Example using Node.js:
104
+
105
+ ```javascript
106
+ var Globalize = require( "globalize" );
107
+
108
+ Globalize.load(
109
+ require( "cldr-data/main/en/ca-gregorian" ),
110
+ require( "cldr-data/supplemental/likelySubtags" ),
111
+ require( "cldr-data/supplemental/timeData" ),
112
+ require( "cldr-data/supplemental/weekData" )
113
+ );
114
+ ```
@@ -0,0 +1,9 @@
1
+ ## E_DEFAULT_LOCALE_NOT_DEFINED
2
+
3
+ Thrown when any static method, eg. `Globalize.formatNumber()` is used prior to setting the Global locale with `Globalize.locale( <locale> )`.
4
+
5
+ Error object:
6
+
7
+ | Attribute | Value |
8
+ | --- | --- |
9
+ | code | `E_DEFAULT_LOCALE_NOT_DEFINED` |
@@ -0,0 +1,14 @@
1
+ ## E_INVALID_CLDR
2
+
3
+ Thrown when a CLDR item has an invalid or unexpected value.
4
+
5
+ Error object:
6
+
7
+ | Attribute | Value |
8
+ | --- | --- |
9
+ | code | `E_INVALID_CLDR` |
10
+ | description | Reason why the data was considered invalid |
11
+
12
+ - description "Missing rules to deduce plural form of \`{value}\`"
13
+
14
+ Thrown when the plural form (also known as plural group) is not found for the given value. This error is very unlikely to occur and is related to incomplete or invalid CLDR `supplemental/plurals-type-cardinal/{language}` data.
@@ -0,0 +1,12 @@
1
+ ## E_INVALID_PAR_TYPE
2
+
3
+ Thrown when a parameter has an invalid type on any static or instance methods.
4
+
5
+ Error object:
6
+
7
+ | Attribute | Value |
8
+ | --- | --- |
9
+ | code | `E_INVALID_PAR_TYPE` |
10
+ | name | Name of the invalid parameter |
11
+ | value | Invalid value |
12
+ | expected | Expected type |
@@ -0,0 +1,11 @@
1
+ ## E_INVALID_PAR_VALUE
2
+
3
+ Thrown for certain parameters when the type is correct, but the value is invalid. Currently, the only parameter with such validation is the date format (for either format and parse). Format allows [certain variants](../api/date/date-formatter.md#parameters), if it's none of them, error is thrown.
4
+
5
+ Error object:
6
+
7
+ | Attribute | Value |
8
+ | --- | --- |
9
+ | code | `E_INVALID_PAR_VALUE` |
10
+ | name | Name of the invalid parameter |
11
+ | value | Invalid value |
@@ -0,0 +1,11 @@
1
+ ## E_MISSING_CLDR
2
+
3
+ Thrown when any required CLDR item is NOT found.
4
+
5
+ Error object:
6
+
7
+ | Attribute | Value |
8
+ | --- | --- |
9
+ | code | `E_MISSING_CLDR` |
10
+ | path | Missing CLDR item path |
11
+
@@ -0,0 +1,10 @@
1
+ ## E_MISSING_PARAMETER
2
+
3
+ Thrown when a required parameter is missing on any static or instance methods.
4
+
5
+ Error object:
6
+
7
+ | Attribute | Value |
8
+ | --- | --- |
9
+ | code | `E_MISSING_PARAMETER` |
10
+ | name | Name of the missing parameter |
@@ -0,0 +1,9 @@
1
+ ## E_MISSING_PLURAL_MODULE
2
+
3
+ Thrown when plural module is needed, but not loaded, eg. formatting currencies using plural messages.
4
+
5
+ Error object:
6
+
7
+ | Attribute | Value |
8
+ | --- | --- |
9
+ | code | `E_MISSING_PLURAL_MODULE` |
@@ -0,0 +1,11 @@
1
+ ## E_PAR_MISSING_KEY
2
+
3
+ Thrown when a parameter misses a required key.
4
+
5
+ Error object:
6
+
7
+ | Attribute | Value |
8
+ | --- | --- |
9
+ | code | `E_PAR_MISSING_KEY` |
10
+ | key | Name of the missing parameter's key |
11
+ | name | Name of the missing parameter |
@@ -0,0 +1,13 @@
1
+ ## E_PAR_OUT_OF_RANGE
2
+
3
+ Thrown when a parameter is not within a valid range of values.
4
+
5
+ Error object:
6
+
7
+ | Attribute | Value |
8
+ | --- | --- |
9
+ | code | `E_PAR_OUT_OF_RANGE` |
10
+ | name | Name of the invalid parameter |
11
+ | value | Invalid value |
12
+ | minimum | Minimum value of the valid range |
13
+ | maximum | Maximum value of the valid range |
@@ -0,0 +1,10 @@
1
+ ## E_UNSUPPORTED
2
+
3
+ Thrown for unsupported features, eg. to format unsupported date patterns.
4
+
5
+ Error object:
6
+
7
+ | Attribute | Value |
8
+ | --- | --- |
9
+ | code | `E_UNSUPPORTED` |
10
+ | feature | Description of the unsupported feature |
@@ -0,0 +1,64 @@
1
+ # Migrating from Globalize 0.x
2
+
3
+ Globalize 0.x came with a bundled locale for US English, and optional files for various other locales. Globalize 1.x uses CLDR for the locale data, and it doesn't bundle any locale data. Check out the documentation for loading CLDR data in 1.x to learn more about that. If you were only using the bundle locale, you only need to load CLDR data for US English. If you were loading other locales, make sure you load those from CLDR as well.
4
+
5
+ On the API side, things have also changed, to simplify usage, remove ambiguity and add features. The rest of this document provides a brief function-by-function list.
6
+
7
+ If you still need help with migration, let us know. We may extend this guide later as necessary.
8
+
9
+ ## Globalize.addCultureInfo()
10
+
11
+ This method is replaced by `Globalize.loadMessages( json )`. If you were using it for anything except message translations, you may also need to use `Globalize.load`.
12
+
13
+ ## Globalize.cultures
14
+
15
+ This property is gone. You can use Cldrjs to traverse CLDR directly.
16
+
17
+ ## Globalize.culture( [locale] )
18
+
19
+ This method is replaced by the `Globalize.locale( [locale|cldr] )` method. Call it without arguments to retrieve the default locale, call it with a string argument to set the default locale.
20
+
21
+ ## Globalize.findClosestCulture
22
+
23
+ This method is gone, there is no replacement. If you still need this method, create an issue with your usecase.
24
+
25
+ ## Globalize.format
26
+
27
+ Replaced by three separate methods:
28
+
29
+ * `.formatNumber( value [, options] )`
30
+ * `.formatCurrency( value, currency [, options] )`
31
+ * `.formatDate( value, pattern )`
32
+
33
+ See their respective documentation for usage details. Note that the number and date formats are now based on CLDR, using the options and patterns standardized by Unicode. We don't currently have documentation for migrating these formats.
34
+
35
+ ## Globalize.localize
36
+
37
+ Replaced by `.formatMessage( path [, variables ] )`. The new API is quite different and provides much more than just value-lookup. See their respective documentation for usage details.
38
+
39
+ ## Globalize.parseInt/parseFloat
40
+
41
+ Replaced by `.parseNumber( value [, options] )`. So where you might have previously executed:
42
+
43
+ ```js
44
+ Globalize( "en" ).parseFloat( "123,456.789" )
45
+ // > 123456.789
46
+ ```
47
+
48
+ You could now execute:
49
+
50
+ ```js
51
+ Globalize( "en" ).parseNumber( "123,456.789" )
52
+ // > 123456.789
53
+ ```
54
+
55
+ `parseNumber` is an alias for [`.numberParser( [options] )( value )`](api/number/number-parser.md). So you could also do this:
56
+
57
+ ```js
58
+ Globalize( "en" ).numberParser()( "123,456.789" )
59
+ // > 123456.789
60
+ ```
61
+
62
+ ## Globalize.parseDate
63
+
64
+ This method still exists, and the signature is almost the same: `.parseDate( value, pattern )`. Note that `pattern` indicates just a single "format", where Globalize 0.x supported multiple of those "formats".
@@ -0,0 +1,7 @@
1
+ {
2
+ "directory": "bower_components",
3
+ "scripts": {
4
+ "preinstall": "npm install cldr-data-downloader",
5
+ "postinstall": "node ./node_modules/cldr-data-downloader/bin/download.js -i bower_components/cldr-data/index.json -o bower_components/cldr-data/"
6
+ }
7
+ }
@@ -0,0 +1,65 @@
1
+ # Hello World (AMD + bower)
2
+
3
+ We assume you know what [AMD](https://github.com/amdjs/amdjs-api/wiki/AMD) and
4
+ [bower](http://bower.io/) is.
5
+
6
+ The demo is composed of the following files:
7
+
8
+ ```
9
+ .
10
+ ├── index.html
11
+ └── main.js
12
+ ```
13
+
14
+ Before running it, execute the requirements below.
15
+
16
+
17
+ ## Requirements
18
+
19
+ **1. Install Globalize**
20
+
21
+ Let's use bower to download Globalize. For more information on regard of
22
+ installation, please read [Getting Started](../../README.md#installation).
23
+
24
+ ```
25
+ bower install
26
+ ```
27
+
28
+ Note bower will also fetch some other dependencies of this demo, eg. require.js
29
+ and its json plugin.
30
+
31
+ You'll get this:
32
+
33
+ ```
34
+ .
35
+ ├── bower_components/
36
+ │ ├── globalize/
37
+ │ │ └── dist/
38
+ │ │ ├── globalize
39
+ │ │ │ ├── date.js
40
+ │ │ │ └── ...
41
+ │ │ └── globalize.js
42
+ │ └── ...
43
+ ├── index.html
44
+ └── main.js
45
+ ```
46
+
47
+ **2. Install Dependencies**
48
+
49
+ No action needed, because bower has already handled that for us.
50
+
51
+ **3. CLDR content**
52
+
53
+ No action needed, because bower has already handled that for us. Note `.bowerrc`
54
+ has postinstall hook that populates bower's cldr-data skeleton. For more
55
+ information, see [bower's cldr-data](https://github.com/rxaviers/cldr-data-bower).
56
+
57
+
58
+ ## Running the demo
59
+
60
+ Once you've completed the requirements above:
61
+
62
+ 1. Start a server by running `python -m SimpleHTTPServer` or other alternative servers such as [http-server](https://github.com/nodeapps/http-server), [nginx](http://nginx.org/en/docs/), [apache](http://httpd.apache.org/docs/trunk/).
63
+ 1. Point your browser at `http://localhost:8000/`.
64
+ 1. Understand the demo by reading the source code (both index.html and main.js).
65
+ We have comments there for you.
@@ -0,0 +1,13 @@
1
+ {
2
+ "name": "globalize-hello-world-amd-bower",
3
+ "dependencies": {
4
+ "cldr-data": "*",
5
+ "globalize": "^1.3.0",
6
+ "iana-tz-data": "*"
7
+ },
8
+ "devDependencies": {
9
+ "requirejs": "2.1.14",
10
+ "requirejs-plugins": "1.0.2" ,
11
+ "requirejs-text": "2.0.12"
12
+ }
13
+ }
@@ -0,0 +1,46 @@
1
+ <!doctype html>
2
+ <head>
3
+ <meta charset="utf-8">
4
+ <meta http-equiv="X-UA-Compatible" content="IE=edge">
5
+ <title>Globalize Hello World (AMD + bower)</title>
6
+ </head>
7
+ <body>
8
+ <h1>Globalize Hello World (AMD + bower)</h1>
9
+
10
+ <div id="requirements">
11
+ <h2>Requirements</h2>
12
+ <ul>
13
+ <li>Run `bower install` (you must have bower installed first).</li>
14
+ <li>Start a server, e.g., by running `python -m SimpleHTTPServer`.</li>
15
+ <li>Point your browser at `http://localhost:8000/`.</li>
16
+ <li>Please, read README.md for more information on any of the above.</li>
17
+ </ul>
18
+ </div>
19
+
20
+ <div id="demo" style="display: none">
21
+ <h2>Demo output</h2>
22
+ <p>Now: <span id="date"></span></p>
23
+ <p>Now: <span id="dateToParts"></span> (note the highlighted month, the markup was added using formatDateToParts)</p>
24
+ <p>Now (in America/Sao_Paulo): <span id="zonedDate"></span></p>
25
+ <p>A number: <span id="number"></span></p>
26
+ <p>A number (compact form): <span id="number-compact"></span></p>
27
+ <p>A currency: <span id="currency"></span></p>
28
+ <p>Plural form of <span id="plural-number"></span> is <span id="plural-form"></span></p>
29
+ <p>Messages:</p>
30
+ <ul>
31
+ <li><span id="message-0"></span></li>
32
+ <li><span id="message-1"></span></li>
33
+ <li><span id="message-2"></span></li>
34
+ <li><span id="message-3"></span></li>
35
+ </ul>
36
+ <p>Something happened: <span id="relative-time"></span></p>
37
+ <p>Speed limit: <span id="unit"></span></p>
38
+ </div>
39
+
40
+ <!--
41
+ Load require.js and let it execute main.js
42
+ -->
43
+ <script data-main="main.js" src="bower_components/requirejs/require.js"></script>
44
+
45
+ </body>
46
+ </html>