globalize-rpk 1.7.1 → 1.7.2

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 (81) hide show
  1. package/CONTRIBUTING.md +5 -0
  2. package/README.md +818 -0
  3. package/{globalize → dist/globalize}/currency.js +3 -3
  4. package/{globalize → dist/globalize}/date.js +3 -3
  5. package/{globalize → dist/globalize}/message.js +2 -2
  6. package/{globalize → dist/globalize}/number.js +3 -3
  7. package/{globalize → dist/globalize}/plural.js +3 -3
  8. package/{globalize → dist/globalize}/relative-time.js +3 -3
  9. package/{globalize → dist/globalize}/unit.js +0 -0
  10. package/dist/globalize-runtime/currency.js +183 -0
  11. package/dist/globalize-runtime/date.js +1657 -0
  12. package/dist/globalize-runtime/message.js +120 -0
  13. package/dist/globalize-runtime/number.js +919 -0
  14. package/dist/globalize-runtime/plural.js +90 -0
  15. package/dist/globalize-runtime/relative-time.js +120 -0
  16. package/dist/globalize-runtime/unit.js +132 -0
  17. package/{globalize → dist}/globalize-runtime.js +0 -0
  18. package/{globalize → dist}/globalize.js +2 -2
  19. package/{node-main.js → dist/node-main.js} +0 -0
  20. package/doc/api/core/constructor.md +28 -0
  21. package/doc/api/core/load.md +96 -0
  22. package/doc/api/core/locale.md +43 -0
  23. package/doc/api/currency/currency-formatter.md +196 -0
  24. package/doc/api/currency/currency-to-parts-formatter.md +117 -0
  25. package/doc/api/date/date-formatter.md +203 -0
  26. package/doc/api/date/date-parser.md +60 -0
  27. package/doc/api/date/date-to-parts-formatter.md +176 -0
  28. package/doc/api/date/load-iana-time-zone.md +29 -0
  29. package/doc/api/message/load-messages.md +105 -0
  30. package/doc/api/message/message-formatter.md +208 -0
  31. package/doc/api/number/number-formatter.md +202 -0
  32. package/doc/api/number/number-parser.md +130 -0
  33. package/doc/api/number/number-to-parts-formatter.md +140 -0
  34. package/doc/api/plural/plural-generator.md +84 -0
  35. package/doc/api/relative-time/relative-time-formatter.md +60 -0
  36. package/doc/api/unit/unit-formatter.md +72 -0
  37. package/doc/blog-post/2017-07-xx-1.3.0-announcement.md +177 -0
  38. package/doc/cldr.md +114 -0
  39. package/doc/error/e-default-locale-not-defined.md +9 -0
  40. package/doc/error/e-invalid-cldr.md +14 -0
  41. package/doc/error/e-invalid-par-type.md +12 -0
  42. package/doc/error/e-invalid-par-value.md +11 -0
  43. package/doc/error/e-missing-cldr.md +11 -0
  44. package/doc/error/e-missing-parameter.md +10 -0
  45. package/doc/error/e-missing-plural-module.md +9 -0
  46. package/doc/error/e-par-missing-key.md +11 -0
  47. package/doc/error/e-par-out-of-range.md +13 -0
  48. package/doc/error/e-unsupported.md +10 -0
  49. package/doc/migrating-from-0.x.md +64 -0
  50. package/examples/amd-bower/.bowerrc +7 -0
  51. package/examples/amd-bower/README.md +65 -0
  52. package/examples/amd-bower/bower.json +13 -0
  53. package/examples/amd-bower/index.html +46 -0
  54. package/examples/amd-bower/main.js +141 -0
  55. package/examples/amd-bower/messages/en.json +12 -0
  56. package/examples/amd-bower/package.json +14 -0
  57. package/examples/app-npm-webpack/README.md +74 -0
  58. package/examples/app-npm-webpack/app/index.js +89 -0
  59. package/examples/app-npm-webpack/index-template.html +71 -0
  60. package/examples/app-npm-webpack/messages/ar.json +25 -0
  61. package/examples/app-npm-webpack/messages/de.json +21 -0
  62. package/examples/app-npm-webpack/messages/en.json +21 -0
  63. package/examples/app-npm-webpack/messages/es.json +21 -0
  64. package/examples/app-npm-webpack/messages/pt.json +21 -0
  65. package/examples/app-npm-webpack/messages/ru.json +23 -0
  66. package/examples/app-npm-webpack/messages/zh.json +20 -0
  67. package/examples/app-npm-webpack/package.json +17 -0
  68. package/examples/app-npm-webpack/webpack-config.js +63 -0
  69. package/examples/globalize-compiler/README.md +45 -0
  70. package/examples/globalize-compiler/app.js +58 -0
  71. package/examples/globalize-compiler/development.html +121 -0
  72. package/examples/globalize-compiler/messages.json +12 -0
  73. package/examples/globalize-compiler/package.json +15 -0
  74. package/examples/globalize-compiler/production.html +75 -0
  75. package/examples/node-npm/README.md +57 -0
  76. package/examples/node-npm/main.js +65 -0
  77. package/examples/node-npm/messages/en.json +12 -0
  78. package/examples/node-npm/package.json +10 -0
  79. package/examples/plain-javascript/README.md +81 -0
  80. package/examples/plain-javascript/index.html +445 -0
  81. package/package.json +27 -4
@@ -0,0 +1,90 @@
1
+ /**
2
+ * Globalize Runtime v1.7.0
3
+ *
4
+ * https://github.com/globalizejs/globalize
5
+ *
6
+ * Copyright OpenJS Foundation and other contributors
7
+ * Released under the MIT license
8
+ * https://jquery.org/license
9
+ *
10
+ * Date: 2021-08-02T11:53Z
11
+ */
12
+ /*!
13
+ * Globalize Runtime v1.7.0 2021-08-02T11:53Z Released under the MIT license
14
+ * http://git.io/TrdQbw
15
+ */
16
+ (function( root, factory ) {
17
+
18
+ "use strict";
19
+
20
+ // UMD returnExports
21
+ if ( typeof define === "function" && define.amd ) {
22
+
23
+ // AMD
24
+ define([
25
+ "../globalize-runtime"
26
+ ], factory );
27
+ } else if ( typeof exports === "object" ) {
28
+
29
+ // Node, CommonJS
30
+ module.exports = factory( require( "../globalize-runtime" ) );
31
+ } else {
32
+
33
+ // Extend global
34
+ factory( root.Globalize );
35
+ }
36
+ }(this, function( Globalize ) {
37
+
38
+
39
+
40
+ var runtimeKey = Globalize._runtimeKey,
41
+ validateParameterPresence = Globalize._validateParameterPresence,
42
+ validateParameterType = Globalize._validateParameterType;
43
+
44
+
45
+ var validateParameterTypeNumber = function( value, name ) {
46
+ validateParameterType(
47
+ value,
48
+ name,
49
+ value === undefined || typeof value === "number",
50
+ "Number"
51
+ );
52
+ };
53
+
54
+
55
+
56
+
57
+ var pluralGeneratorFn = function( plural ) {
58
+ return function pluralGenerator( value ) {
59
+ validateParameterPresence( value, "value" );
60
+ validateParameterTypeNumber( value, "value" );
61
+
62
+ return plural( value );
63
+ };
64
+ };
65
+
66
+
67
+
68
+
69
+ Globalize._pluralGeneratorFn = pluralGeneratorFn;
70
+ Globalize._validateParameterTypeNumber = validateParameterTypeNumber;
71
+
72
+ Globalize.plural =
73
+ Globalize.prototype.plural = function( value, options ) {
74
+ validateParameterPresence( value, "value" );
75
+ validateParameterTypeNumber( value, "value" );
76
+ return this.pluralGenerator( options )( value );
77
+ };
78
+
79
+ Globalize.pluralGenerator =
80
+ Globalize.prototype.pluralGenerator = function( options ) {
81
+ options = options || {};
82
+ return Globalize[ runtimeKey( "pluralGenerator", this._locale, [ options ] ) ];
83
+ };
84
+
85
+ return Globalize;
86
+
87
+
88
+
89
+
90
+ }));
@@ -0,0 +1,120 @@
1
+ /**
2
+ * Globalize Runtime v1.7.0
3
+ *
4
+ * https://github.com/globalizejs/globalize
5
+ *
6
+ * Copyright OpenJS Foundation and other contributors
7
+ * Released under the MIT license
8
+ * https://jquery.org/license
9
+ *
10
+ * Date: 2021-08-02T11:53Z
11
+ */
12
+ /*!
13
+ * Globalize Runtime v1.7.0 2021-08-02T11:53Z Released under the MIT license
14
+ * http://git.io/TrdQbw
15
+ */
16
+ (function( root, factory ) {
17
+
18
+ "use strict";
19
+
20
+ // UMD returnExports
21
+ if ( typeof define === "function" && define.amd ) {
22
+
23
+ // AMD
24
+ define([
25
+ "../globalize-runtime",
26
+ "./number",
27
+ "./plural"
28
+ ], factory );
29
+ } else if ( typeof exports === "object" ) {
30
+
31
+ // Node, CommonJS
32
+ module.exports = factory(
33
+ require( "../globalize-runtime" ),
34
+ require( "./number" ),
35
+ require( "./plural" )
36
+ );
37
+ } else {
38
+
39
+ // Extend global
40
+ factory( root.Globalize );
41
+ }
42
+ }(this, function( Globalize ) {
43
+
44
+
45
+
46
+ var formatMessage = Globalize._formatMessage,
47
+ runtimeKey = Globalize._runtimeKey,
48
+ validateParameterPresence = Globalize._validateParameterPresence,
49
+ validateParameterTypeNumber = Globalize._validateParameterTypeNumber;
50
+
51
+
52
+ /**
53
+ * format( value, numberFormatter, pluralGenerator, properties )
54
+ *
55
+ * @value [Number] The number to format
56
+ *
57
+ * @numberFormatter [String] A numberFormatter from Globalize.numberFormatter
58
+ *
59
+ * @pluralGenerator [String] A pluralGenerator from Globalize.pluralGenerator
60
+ *
61
+ * @properties [Object] containing relative time plural message.
62
+ *
63
+ * Format relative time.
64
+ */
65
+ var relativeTimeFormat = function( value, numberFormatter, pluralGenerator, properties ) {
66
+
67
+ var relativeTime,
68
+ message = properties[ "relative-type-" + value ];
69
+
70
+ if ( message ) {
71
+ return message;
72
+ }
73
+
74
+ relativeTime = value <= 0 ? properties[ "relativeTime-type-past" ] :
75
+ properties[ "relativeTime-type-future" ];
76
+
77
+ value = Math.abs( value );
78
+
79
+ message = relativeTime[ "relativeTimePattern-count-" + pluralGenerator( value ) ];
80
+ return formatMessage( message, [ numberFormatter( value ) ] );
81
+ };
82
+
83
+
84
+
85
+
86
+ var relativeTimeFormatterFn = function( numberFormatter, pluralGenerator, properties ) {
87
+ return function relativeTimeFormatter( value ) {
88
+ validateParameterPresence( value, "value" );
89
+ validateParameterTypeNumber( value, "value" );
90
+
91
+ return relativeTimeFormat( value, numberFormatter, pluralGenerator, properties );
92
+ };
93
+
94
+ };
95
+
96
+
97
+
98
+
99
+ Globalize._relativeTimeFormatterFn = relativeTimeFormatterFn;
100
+
101
+ Globalize.formatRelativeTime =
102
+ Globalize.prototype.formatRelativeTime = function( value, unit, options ) {
103
+ validateParameterPresence( value, "value" );
104
+ validateParameterTypeNumber( value, "value" );
105
+
106
+ return this.relativeTimeFormatter( unit, options )( value );
107
+ };
108
+
109
+ Globalize.relativeTimeFormatter =
110
+ Globalize.prototype.relativeTimeFormatter = function( unit, options ) {
111
+ options = options || {};
112
+ return Globalize[ runtimeKey( "relativeTimeFormatter", this._locale, [ unit, options ] ) ];
113
+ };
114
+
115
+ return Globalize;
116
+
117
+
118
+
119
+
120
+ }));
@@ -0,0 +1,132 @@
1
+ /**
2
+ * Globalize Runtime v1.7.0
3
+ *
4
+ * https://github.com/globalizejs/globalize
5
+ *
6
+ * Copyright OpenJS Foundation and other contributors
7
+ * Released under the MIT license
8
+ * https://jquery.org/license
9
+ *
10
+ * Date: 2021-08-02T11:53Z
11
+ */
12
+ /*!
13
+ * Globalize Runtime v1.7.0 2021-08-02T11:53Z Released under the MIT license
14
+ * http://git.io/TrdQbw
15
+ */
16
+ (function( root, factory ) {
17
+
18
+ "use strict";
19
+
20
+ // UMD returnExports
21
+ if ( typeof define === "function" && define.amd ) {
22
+
23
+ // AMD
24
+ define([
25
+ "../globalize-runtime",
26
+ "./number",
27
+ "./plural"
28
+ ], factory );
29
+ } else if ( typeof exports === "object" ) {
30
+
31
+ // Node, CommonJS
32
+ module.exports = factory(
33
+ require( "../globalize-runtime" ),
34
+ require( "./number" ),
35
+ require( "./plural" )
36
+ );
37
+ } else {
38
+
39
+ // Extend global
40
+ factory( root.Globalize );
41
+ }
42
+ }(this, function( Globalize ) {
43
+
44
+
45
+
46
+ var formatMessage = Globalize._formatMessage,
47
+ runtimeKey = Globalize._runtimeKey,
48
+ validateParameterPresence = Globalize._validateParameterPresence,
49
+ validateParameterTypeNumber = Globalize._validateParameterTypeNumber;
50
+
51
+
52
+ /**
53
+ * format( value, numberFormatter, pluralGenerator, unitProperies )
54
+ *
55
+ * @value [Number]
56
+ *
57
+ * @numberFormatter [Object]: A numberFormatter from Globalize.numberFormatter.
58
+ *
59
+ * @pluralGenerator [Object]: A pluralGenerator from Globalize.pluralGenerator.
60
+ *
61
+ * @unitProperies [Object]: localized unit data from cldr.
62
+ *
63
+ * Format units such as seconds, minutes, days, weeks, etc.
64
+ *
65
+ * OBS:
66
+ *
67
+ * Unit Sequences are not implemented.
68
+ * http://www.unicode.org/reports/tr35/tr35-35/tr35-general.html#Unit_Sequences
69
+ *
70
+ * Duration Unit (for composed time unit durations) is not implemented.
71
+ * http://www.unicode.org/reports/tr35/tr35-35/tr35-general.html#durationUnit
72
+ */
73
+ var unitFormat = function( value, numberFormatter, pluralGenerator, unitProperties ) {
74
+ var compoundUnitPattern = unitProperties.compoundUnitPattern, dividend, dividendProperties,
75
+ formattedValue, divisor, divisorProperties, message, pluralValue, oneProperty;
76
+
77
+ unitProperties = unitProperties.unitProperties;
78
+ formattedValue = numberFormatter( value );
79
+ pluralValue = pluralGenerator( value );
80
+
81
+ // computed compound unit, eg. "megabyte-per-second".
82
+ if ( unitProperties instanceof Array ) {
83
+ dividendProperties = unitProperties[ 0 ];
84
+ divisorProperties = unitProperties[ 1 ];
85
+ oneProperty = divisorProperties.hasOwnProperty( "one" ) ? "one" : "other";
86
+
87
+ dividend = formatMessage( dividendProperties[ pluralValue ], [ formattedValue ] );
88
+ divisor = formatMessage( divisorProperties[ oneProperty ], [ "" ] ).trim();
89
+
90
+ return formatMessage( compoundUnitPattern, [ dividend, divisor ] );
91
+ }
92
+
93
+ message = unitProperties[ pluralValue ];
94
+
95
+ return formatMessage( message, [ formattedValue ] );
96
+ };
97
+
98
+
99
+
100
+
101
+ var unitFormatterFn = function( numberFormatter, pluralGenerator, unitProperties ) {
102
+ return function unitFormatter( value ) {
103
+ validateParameterPresence( value, "value" );
104
+ validateParameterTypeNumber( value, "value" );
105
+
106
+ return unitFormat( value, numberFormatter, pluralGenerator, unitProperties );
107
+ };
108
+
109
+ };
110
+
111
+
112
+
113
+
114
+ Globalize._unitFormatterFn = unitFormatterFn;
115
+
116
+ Globalize.formatUnit =
117
+ Globalize.prototype.formatUnit = function( value, unit, options ) {
118
+ return this.unitFormatter( unit, options )( value );
119
+ };
120
+
121
+ Globalize.unitFormatter =
122
+ Globalize.prototype.unitFormatter = function( unit, options ) {
123
+ options = options || {};
124
+ return Globalize[ runtimeKey( "unitFormatter", this._locale, [ unit, options ] ) ];
125
+ };
126
+
127
+ return Globalize;
128
+
129
+
130
+
131
+
132
+ }));
File without changes
@@ -20,8 +20,8 @@
20
20
 
21
21
  // AMD
22
22
  define([
23
- "cldr",
24
- "cldr/event"
23
+ "cldrjs/dist/cldr",
24
+ "cldrjs/dist/cldr/event"
25
25
  ], factory );
26
26
  } else if ( typeof exports === "object" ) {
27
27
 
File without changes
@@ -0,0 +1,28 @@
1
+ ## [new] Globalize( locale|cldr )
2
+
3
+ Create a Globalize instance.
4
+
5
+ ### Parameters
6
+
7
+ #### locale|cldr
8
+
9
+ Locale string or [Cldr instance](https://github.com/rxaviers/cldrjs) of the instance.
10
+
11
+ ### Example
12
+
13
+ Prior to creating any Globalize instance, you must load `cldr/supplemental/likelySubtags.json`. Read [CLDR content][] if you need more information.
14
+
15
+ [CLDR content]: ../../../README.md#2-cldr-content
16
+
17
+ ```javascript
18
+ var en = new Globalize( "en" );
19
+
20
+ // You can optionally omit the `new` operator.
21
+ var pt = Globalize( "pt" );
22
+
23
+ en.formatNumber( 3.1415 );
24
+ // > 3.142
25
+
26
+ pt.formatNumber( 3.1415 );
27
+ // > 3,142
28
+ ```
@@ -0,0 +1,96 @@
1
+ ## Globalize.load( cldrJSONData, ... )
2
+
3
+ This method allows you to load CLDR JSON locale data. `Globalize.load()` is a proxy to `Cldr.load()`.
4
+
5
+ This method can be called as many times as needed. All passed JSON objects are deeply merged internally.
6
+
7
+ For more information, see https://github.com/rxaviers/cldrjs#readme.
8
+
9
+ ### Parameters
10
+
11
+ #### cldrJSONData
12
+
13
+ A JSON object with CLDR data. See [Getting Started](#../../../README.md#2-cldr-content) for more information.
14
+
15
+ ### Example
16
+
17
+ ```javascript
18
+ Globalize.load({
19
+ "main": {
20
+ "en": {
21
+ "identity": {
22
+ "version": {
23
+ "_cldrVersion": "25",
24
+ "_number": "$Revision: 91 $"
25
+ },
26
+ "generation": {
27
+ "_date": "$Date: 2014-03-13 22:27:12 -0500 (Thu, 13 Mar 2014) $"
28
+ },
29
+ "language": "en"
30
+ },
31
+ "dates": {
32
+ "calendars": {
33
+ "gregorian": {
34
+ "months": {
35
+ "format": {
36
+ "abbreviated": {
37
+ "1": "Jan",
38
+ "2": "Feb",
39
+ "3": "Mar",
40
+ "4": "Apr",
41
+ "5": "May",
42
+ "6": "Jun",
43
+ "7": "Jul",
44
+ "8": "Aug",
45
+ "9": "Sep",
46
+ "10": "Oct",
47
+ "11": "Nov",
48
+ "12": "Dec"
49
+ }
50
+ }
51
+ },
52
+ "dayPeriods": {
53
+ "format": {
54
+ "wide": {
55
+ "am": "AM",
56
+ "am-alt-variant": "am",
57
+ "noon": "noon",
58
+ "pm": "PM",
59
+ "pm-alt-variant": "pm"
60
+ }
61
+ }
62
+ },
63
+ "dateFormats": {
64
+ "medium": "MMM d, y"
65
+ },
66
+ "timeFormats": {
67
+ "medium": "h:mm:ss a",
68
+ },
69
+ "dateTimeFormats": {
70
+ "medium": "{1}, {0}"
71
+ }
72
+ }
73
+ }
74
+ },
75
+ "numbers": {
76
+ "defaultNumberingSystem": "latn",
77
+ "symbols-numberSystem-latn": {
78
+ "group": ","
79
+ },
80
+ "decimalFormats-numberSystem-latn": {
81
+ "standard": "#,##0.###"
82
+ }
83
+ }
84
+ }
85
+ },
86
+ "supplemental": {
87
+ "version": {
88
+ "_cldrVersion": "25",
89
+ "_number": "$Revision: 91 $"
90
+ },
91
+ "likelySubtags": {
92
+ "en": "en-Latn-US",
93
+ }
94
+ }
95
+ });
96
+ ```
@@ -0,0 +1,43 @@
1
+ ## Globalize.locale( [locale|cldr] )
2
+
3
+ Set default locale, or get it if locale argument is omitted.
4
+
5
+ Return the default [Cldr instance](https://github.com/rxaviers/cldrjs).
6
+
7
+ An application that supports globalization and/or localization will need to have a way to determine the user's preference. Attempting to automatically determine the appropriate locale is useful, but it is good practice to always offer the user a choice, by whatever means.
8
+
9
+ Whatever your mechanism, it is likely that you will have to correlate the user's preferences with the list of locale data supported in the app. This method allows you to select the best match given the locale data that you have included and to set the Globalize locale to the one which the user prefers.
10
+
11
+ LanguageMatching TBD (CLDR's spec http://www.unicode.org/reports/tr35/#LanguageMatching).
12
+
13
+ ### Parameters
14
+
15
+ #### locale|cldr
16
+
17
+ - The locale string, e.g., `"en"`, `"pt-BR"`, or `"zh-Hant-TW"`. Or,
18
+ - The [Cldr instance](https://github.com/rxaviers/cldrjs), e.g., new `Cldr( "en" )`.
19
+
20
+ ### Example
21
+
22
+ Prior to using this function, you must load `cldr/supplemental/likelySubtags.json`. Read [CLDR content][] if you need more information.
23
+
24
+ [CLDR content]: ../../../README.md#2-cldr-content
25
+
26
+ ```javascript
27
+ // Set "pt" as our default locale.
28
+ Globalize.locale( "pt" );
29
+
30
+ // Get default locale.
31
+ Globalize.locale();
32
+ // > {
33
+ // attributes: {
34
+ // "languageId": "pt",
35
+ // "maxLanguageId": "pt_Latn_BR",
36
+ // "language": "pt",
37
+ // "script": "Latn",
38
+ // "territory": "BR",
39
+ // "region": "BR"
40
+ // },
41
+ // some more stuff...
42
+ // }
43
+ ```