iobroker.vis2-materialdesign 0.1.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.
- package/LICENSE +22 -0
- package/README.md +198 -0
- package/admin/admin.d.ts +93 -0
- package/admin/i18n/de.json +985 -0
- package/admin/i18n/en.json +985 -0
- package/admin/i18n/es.json +985 -0
- package/admin/i18n/fr.json +985 -0
- package/admin/i18n/it.json +985 -0
- package/admin/i18n/nl.json +985 -0
- package/admin/i18n/pl.json +985 -0
- package/admin/i18n/pt.json +985 -0
- package/admin/i18n/ru.json +985 -0
- package/admin/i18n/uk.json +985 -0
- package/admin/i18n/zh-cn.json +985 -0
- package/admin/img/info-big.png +0 -0
- package/admin/index_m.html +456 -0
- package/admin/index_m.js +1018 -0
- package/admin/lib/clipboard-polyfill.promise.js +16 -0
- package/admin/lib/colors.json +1304 -0
- package/admin/lib/colorsDark.json +1304 -0
- package/admin/lib/defaultcolors.json +22 -0
- package/admin/lib/defaultcolorsDark.json +22 -0
- package/admin/lib/defaultfontSizes.json +14 -0
- package/admin/lib/defaultfonts.json +14 -0
- package/admin/lib/fontSizes.json +380 -0
- package/admin/lib/fonts.json +386 -0
- package/admin/lib/monolith.min.css +1 -0
- package/admin/lib/pickr.min.js +5 -0
- package/admin/materialdesign-widgets-click-sound.mp3 +0 -0
- package/admin/style.css +31 -0
- package/admin/tsconfig.json +9 -0
- package/admin/vis-materialdesign.png +0 -0
- package/admin/vis-materialdesign_16_9.png +0 -0
- package/admin/words.js +11949 -0
- package/io-package.json +184 -0
- package/package.json +71 -0
- package/widgets/materialdesign/css/widgets.css +7174 -0
- package/widgets/materialdesign/css/widgets.min.css +1 -0
- package/widgets/materialdesign/img/IoBroker_Logo.png +0 -0
- package/widgets/materialdesign/img/bar_chart.png +0 -0
- package/widgets/materialdesign/img/calendar.png +0 -0
- package/widgets/materialdesign/img/pie_chart.png +0 -0
- package/widgets/materialdesign/img/prev_alerts.png +0 -0
- package/widgets/materialdesign/img/prev_autocomplete.png +0 -0
- package/widgets/materialdesign/img/prev_color_schemes.png +0 -0
- package/widgets/materialdesign/img/prev_dialog_view.png +0 -0
- package/widgets/materialdesign/img/prev_grid_views.png +0 -0
- package/widgets/materialdesign/img/prev_icon.png +0 -0
- package/widgets/materialdesign/img/prev_iconlist.png +0 -0
- package/widgets/materialdesign/img/prev_input.png +0 -0
- package/widgets/materialdesign/img/prev_json_chart.png +0 -0
- package/widgets/materialdesign/img/prev_line_history_chart.png +0 -0
- package/widgets/materialdesign/img/prev_list.png +0 -0
- package/widgets/materialdesign/img/prev_masonry_views.png +0 -0
- package/widgets/materialdesign/img/prev_select_bool.png +0 -0
- package/widgets/materialdesign/img/prev_select_value.png +0 -0
- package/widgets/materialdesign/img/prev_table.png +0 -0
- package/widgets/materialdesign/img/prev_top_app_bar_nav_drawer.png +0 -0
- package/widgets/materialdesign/img/prev_version.png +0 -0
- package/widgets/materialdesign/img/preview.jpg +0 -0
- package/widgets/materialdesign/js/materialdesign.js +56 -0
- package/widgets/materialdesign/js/widgets/materialdesign.00.helper.js +1229 -0
- package/widgets/materialdesign/js/widgets/materialdesign.00.vue.helper.js +710 -0
- package/widgets/materialdesign/js/widgets/materialdesign.alerts.js +177 -0
- package/widgets/materialdesign/js/widgets/materialdesign.autocomplete.js +263 -0
- package/widgets/materialdesign/js/widgets/materialdesign.button.js +1617 -0
- package/widgets/materialdesign/js/widgets/materialdesign.calendar.js +472 -0
- package/widgets/materialdesign/js/widgets/materialdesign.card.js +276 -0
- package/widgets/materialdesign/js/widgets/materialdesign.chart.bar.js +389 -0
- package/widgets/materialdesign/js/widgets/materialdesign.chart.helper.js +494 -0
- package/widgets/materialdesign/js/widgets/materialdesign.chart.json.js +621 -0
- package/widgets/materialdesign/js/widgets/materialdesign.chart.line.js +552 -0
- package/widgets/materialdesign/js/widgets/materialdesign.chart.pie.js +380 -0
- package/widgets/materialdesign/js/widgets/materialdesign.checkbox.js +281 -0
- package/widgets/materialdesign/js/widgets/materialdesign.colorschemes.js +129 -0
- package/widgets/materialdesign/js/widgets/materialdesign.dialog.js +384 -0
- package/widgets/materialdesign/js/widgets/materialdesign.iconList.js +873 -0
- package/widgets/materialdesign/js/widgets/materialdesign.list.js +503 -0
- package/widgets/materialdesign/js/widgets/materialdesign.materialdesignicons.js +7055 -0
- package/widgets/materialdesign/js/widgets/materialdesign.progress.js +413 -0
- package/widgets/materialdesign/js/widgets/materialdesign.roundslider.js +267 -0
- package/widgets/materialdesign/js/widgets/materialdesign.select.js +243 -0
- package/widgets/materialdesign/js/widgets/materialdesign.slider.js +363 -0
- package/widgets/materialdesign/js/widgets/materialdesign.switch.js +284 -0
- package/widgets/materialdesign/js/widgets/materialdesign.table.js +688 -0
- package/widgets/materialdesign/js/widgets/materialdesign.textfield.js +260 -0
- package/widgets/materialdesign/js/widgets/materialdesign.topappbarnav.js +747 -0
- package/widgets/materialdesign/js/widgets/materialdesign.value.js +369 -0
- package/widgets/materialdesign/js/widgets/materialdesign.views.js +827 -0
- package/widgets/materialdesign/js/widgets/materialdesign.viseditor.js +1088 -0
- package/widgets/materialdesign/js/widgets.min.js +1 -0
- package/widgets/materialdesign/lib/Chart.css +47 -0
- package/widgets/materialdesign/lib/Chart.js +16151 -0
- package/widgets/materialdesign/lib/VueTheMask.umd.js +556 -0
- package/widgets/materialdesign/lib/chartjs-plugin-datalabels.js +1385 -0
- package/widgets/materialdesign/lib/chroma.js +3225 -0
- package/widgets/materialdesign/lib/fonts/material-design-icons/materialdesignicons-webfont.ttf +0 -0
- package/widgets/materialdesign/lib/fonts/material-design-icons/materialdesignicons.css +27457 -0
- package/widgets/materialdesign/lib/fonts/material-design-icons/materialdesignicons.min.css +1 -0
- package/widgets/materialdesign/lib/fonts/material-icons/MaterialIcons-Regular.ttf +0 -0
- package/widgets/materialdesign/lib/fonts/material-icons/material-icons.css +31 -0
- package/widgets/materialdesign/lib/he.js +345 -0
- package/widgets/materialdesign/lib/jquery.initialize.js +156 -0
- package/widgets/materialdesign/lib/jquery.knob.js +820 -0
- package/widgets/materialdesign/lib/jquery.mobile-events.js +940 -0
- package/widgets/materialdesign/lib/material-components-web.css +10011 -0
- package/widgets/materialdesign/lib/material-components-web.js +22651 -0
- package/widgets/materialdesign/lib/math.js +41 -0
- package/widgets/materialdesign/lib/moment-duration-format.js +1737 -0
- package/widgets/materialdesign/lib/myUnderscore.js +1695 -0
- package/widgets/materialdesign/lib/raw/moment-with-locales.min.js +28 -0
- package/widgets/materialdesign/lib/raw/round-slider.js +271 -0
- package/widgets/materialdesign/lib/raw/sentry/bundle.min.js +3 -0
- package/widgets/materialdesign/lib/raw/sentry/captureconsole.min.js +2 -0
- package/widgets/materialdesign/lib/raw/sentry/dedupe.min.js +2 -0
- package/widgets/materialdesign/lib/svg-inject.js +697 -0
- package/widgets/materialdesign/lib/vue.js +11965 -0
- package/widgets/materialdesign/lib/vuetify.js +43729 -0
- package/widgets/materialdesign/lib.min.css +1 -0
- package/widgets/materialdesign/lib.min.js +6285 -0
- package/widgets/materialdesign.html +1063 -0
- package/widgets/vis2-materialdesign/assets/MaterialDesignButtonAdition-BOasvewn.js +1 -0
- package/widgets/vis2-materialdesign/assets/MaterialDesignButtonAditionVertical-CfxLrjtz.js +1 -0
- package/widgets/vis2-materialdesign/assets/MaterialDesignButtonLink-DFOHalVe.js +1 -0
- package/widgets/vis2-materialdesign/assets/MaterialDesignButtonLinkVertical-bLBc2Zj6.js +1 -0
- package/widgets/vis2-materialdesign/assets/MaterialDesignButtonNavigation-loocTeHA.js +1 -0
- package/widgets/vis2-materialdesign/assets/MaterialDesignButtonNavigationVertical-wKivh3mz.js +1 -0
- package/widgets/vis2-materialdesign/assets/MaterialDesignButtonState-DyuzNIZY.js +1 -0
- package/widgets/vis2-materialdesign/assets/MaterialDesignButtonStateMulti-D9YVumU3.js +1 -0
- package/widgets/vis2-materialdesign/assets/MaterialDesignButtonStateMultiVertical-J7SUuXNA.js +1 -0
- package/widgets/vis2-materialdesign/assets/MaterialDesignButtonStateVertical-EhVri-Bj.js +1 -0
- package/widgets/vis2-materialdesign/assets/MaterialDesignButtonToggle-CLxaT9SA.js +1 -0
- package/widgets/vis2-materialdesign/assets/MaterialDesignButtonToggleVertical-4zI4T-cI.js +1 -0
- package/widgets/vis2-materialdesign/assets/MaterialDesignButtons-BHDA55zY.js +1 -0
- package/widgets/vis2-materialdesign/assets/MaterialDesignCheckbox-Dwl43BB6.js +1 -0
- package/widgets/vis2-materialdesign/assets/MaterialDesignIcon-07Jl1QSv.js +1 -0
- package/widgets/vis2-materialdesign/assets/MaterialDesignIconButtonAdition-DkyLUAuu.js +1 -0
- package/widgets/vis2-materialdesign/assets/MaterialDesignIconButtonLink-CFh_41FT.js +1 -0
- package/widgets/vis2-materialdesign/assets/MaterialDesignIconButtonNavigation-CLvhcORZ.js +1 -0
- package/widgets/vis2-materialdesign/assets/MaterialDesignIconButtonSlider-TfUJKNib.js +1 -0
- package/widgets/vis2-materialdesign/assets/MaterialDesignIconButtonState-Con_l2iN.js +1 -0
- package/widgets/vis2-materialdesign/assets/MaterialDesignIconButtonStateMulti-DuakGd7h.js +1 -0
- package/widgets/vis2-materialdesign/assets/MaterialDesignIconButtonToggle-B3Yxo-Ii.js +1 -0
- package/widgets/vis2-materialdesign/assets/MaterialDesignSwitch-BPSYRrDe.js +1 -0
- package/widgets/vis2-materialdesign/assets/MaterialDesignValue-D5sJ-iyi.js +1 -0
- package/widgets/vis2-materialdesign/assets/_virtual_mf-localSharedImportMap___mfe_internal__vis2MaterialDesignWidgets-BFI0756z.js +1 -0
- package/widgets/vis2-materialdesign/assets/_virtual_mf___mfe_internal__vis2MaterialDesignWidgets__loadShare__react__loadShare__.js-4V-ZaKyJ.js +1 -0
- package/widgets/vis2-materialdesign/assets/_virtual_mf___mfe_internal__vis2MaterialDesignWidgets__loadShare__react_mf_1_jsx_mf_2_runtime__loadShare__.js-Eu2aWCKd.js +1 -0
- package/widgets/vis2-materialdesign/assets/_virtual_mf___mfe_internal__vis2MaterialDesignWidgets__loadShare__react_mf_2_dom__loadShare__.js-D3wyrTEe.js +8 -0
- package/widgets/vis2-materialdesign/assets/hostInit-CP4jqDxy.js +1 -0
- package/widgets/vis2-materialdesign/assets/index-jMDUG1V1.js +1 -0
- package/widgets/vis2-materialdesign/assets/mf-entry-bootstrap-0-5bdbe7bd.js +35 -0
- package/widgets/vis2-materialdesign/assets/rolldown-runtime-CNC7AqOf.js +1 -0
- package/widgets/vis2-materialdesign/assets/translations-CYT3A7CQ.js +1 -0
- package/widgets/vis2-materialdesign/assets/virtualExposes-BFTZrXtp.js +1 -0
- package/widgets/vis2-materialdesign/assets/virtual_mf-REMOTE_ENTRY_ID___mfe_internal__vis2MaterialDesignWidgets__customWidgets_js-BOvf1QCd.js +4 -0
- package/widgets/vis2-materialdesign/assets/virtual_mf-exposes-ssr___mfe_internal__vis2MaterialDesignWidgets__customWidgets_js-vY7qHvFF.js +2 -0
- package/widgets/vis2-materialdesign/assets/virtual_mf-exposes___mfe_internal__vis2MaterialDesignWidgets__customWidgets_js-C28iDRsy.js +2 -0
- package/widgets/vis2-materialdesign/assets/vite-preload-helper-DuG8C5Si.js +1 -0
- package/widgets/vis2-materialdesign/assets/widgetUtils-D_-xivaB.js +1 -0
- package/widgets/vis2-materialdesign/customWidgets.js +1 -0
- package/widgets/vis2-materialdesign/customWidgets.ssr.js +1 -0
- package/widgets/vis2-materialdesign/materialdesign-widgets-click-sound.mp3 +0 -0
- package/widgets/vis2-materialdesign/mf-stats.json +1 -0
|
@@ -0,0 +1,1737 @@
|
|
|
1
|
+
/*! Moment Duration Format v2.2.2
|
|
2
|
+
* https://github.com/jsmreese/moment-duration-format
|
|
3
|
+
* Date: 2018-02-16
|
|
4
|
+
*
|
|
5
|
+
* Duration format plugin function for the Moment.js library
|
|
6
|
+
* http://momentjs.com/
|
|
7
|
+
*
|
|
8
|
+
* Copyright 2018 John Madhavan-Reese
|
|
9
|
+
* Released under the MIT license
|
|
10
|
+
*/
|
|
11
|
+
|
|
12
|
+
(function (root, factory) {
|
|
13
|
+
if (typeof define === 'function' && define.amd) {
|
|
14
|
+
// AMD. Register as an anonymous module.
|
|
15
|
+
define(['moment'], factory);
|
|
16
|
+
} else if (typeof exports === 'object') {
|
|
17
|
+
// Node. Does not work with strict CommonJS, but only CommonJS-like
|
|
18
|
+
// enviroments that support module.exports, like Node.
|
|
19
|
+
try {
|
|
20
|
+
module.exports = factory(require('moment'));
|
|
21
|
+
} catch (e) {
|
|
22
|
+
// If moment is not available, leave the setup up to the user.
|
|
23
|
+
// Like when using moment-timezone or similar moment-based package.
|
|
24
|
+
module.exports = factory;
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
if (root) {
|
|
29
|
+
// Globals.
|
|
30
|
+
root.momentDurationFormatSetup = root.moment ? factory(root.moment) : factory;
|
|
31
|
+
}
|
|
32
|
+
})(this, function (moment) {
|
|
33
|
+
// `Number#tolocaleString` is tested on plugin initialization.
|
|
34
|
+
// If the feature test passes, `toLocaleStringWorks` will be set to `true` and the
|
|
35
|
+
// native function will be used to generate formatted output. If the feature
|
|
36
|
+
// test fails, the fallback format function internal to this plugin will be
|
|
37
|
+
// used.
|
|
38
|
+
var toLocaleStringWorks = false;
|
|
39
|
+
|
|
40
|
+
// `Number#toLocaleString` rounds incorrectly for select numbers in Microsoft
|
|
41
|
+
// environments (Edge, IE11, Windows Phone) and possibly other environments.
|
|
42
|
+
// If the rounding test fails and `toLocaleString` will be used for formatting,
|
|
43
|
+
// the plugin will "pre-round" number values using the fallback number format
|
|
44
|
+
// function before passing them to `toLocaleString` for final formatting.
|
|
45
|
+
var toLocaleStringRoundingWorks = false;
|
|
46
|
+
|
|
47
|
+
// `Intl.NumberFormat#format` is tested on plugin initialization.
|
|
48
|
+
// If the feature test passes, `intlNumberFormatRoundingWorks` will be set to
|
|
49
|
+
// `true` and the native function will be used to generate formatted output.
|
|
50
|
+
// If the feature test fails, either `Number#tolocaleString` (if
|
|
51
|
+
// `toLocaleStringWorks` is `true`), or the fallback format function internal
|
|
52
|
+
// to this plugin will be used.
|
|
53
|
+
var intlNumberFormatWorks = false;
|
|
54
|
+
|
|
55
|
+
// `Intl.NumberFormat#format` rounds incorrectly for select numbers in Microsoft
|
|
56
|
+
// environments (Edge, IE11, Windows Phone) and possibly other environments.
|
|
57
|
+
// If the rounding test fails and `Intl.NumberFormat#format` will be used for
|
|
58
|
+
// formatting, the plugin will "pre-round" number values using the fallback number
|
|
59
|
+
// format function before passing them to `Intl.NumberFormat#format` for final
|
|
60
|
+
// formatting.
|
|
61
|
+
var intlNumberFormatRoundingWorks = false;
|
|
62
|
+
|
|
63
|
+
// Token type names in order of descending magnitude.
|
|
64
|
+
var types = "escape years months weeks days hours minutes seconds milliseconds general".split(" ");
|
|
65
|
+
|
|
66
|
+
var bubbles = [
|
|
67
|
+
{
|
|
68
|
+
type: "seconds",
|
|
69
|
+
targets: [
|
|
70
|
+
{ type: "minutes", value: 60 },
|
|
71
|
+
{ type: "hours", value: 3600 },
|
|
72
|
+
{ type: "days", value: 86400 },
|
|
73
|
+
{ type: "weeks", value: 604800 },
|
|
74
|
+
{ type: "months", value: 2678400 },
|
|
75
|
+
{ type: "years", value: 31536000 }
|
|
76
|
+
]
|
|
77
|
+
},
|
|
78
|
+
{
|
|
79
|
+
type: "minutes",
|
|
80
|
+
targets: [
|
|
81
|
+
{ type: "hours", value: 60 },
|
|
82
|
+
{ type: "days", value: 1440 },
|
|
83
|
+
{ type: "weeks", value: 10080 },
|
|
84
|
+
{ type: "months", value: 44640 },
|
|
85
|
+
{ type: "years", value: 525600 }
|
|
86
|
+
]
|
|
87
|
+
},
|
|
88
|
+
{
|
|
89
|
+
type: "hours",
|
|
90
|
+
targets: [
|
|
91
|
+
{ type: "days", value: 24 },
|
|
92
|
+
{ type: "weeks", value: 168 },
|
|
93
|
+
{ type: "months", value: 744 },
|
|
94
|
+
{ type: "years", value: 8760 }
|
|
95
|
+
]
|
|
96
|
+
},
|
|
97
|
+
{
|
|
98
|
+
type: "days",
|
|
99
|
+
targets: [
|
|
100
|
+
{ type: "weeks", value: 7 },
|
|
101
|
+
{ type: "months", value: 31 },
|
|
102
|
+
{ type: "years", value: 365 }
|
|
103
|
+
]
|
|
104
|
+
},
|
|
105
|
+
{
|
|
106
|
+
type: "months",
|
|
107
|
+
targets: [
|
|
108
|
+
{ type: "years", value: 12 }
|
|
109
|
+
]
|
|
110
|
+
}
|
|
111
|
+
];
|
|
112
|
+
|
|
113
|
+
// stringIncludes
|
|
114
|
+
function stringIncludes(str, search) {
|
|
115
|
+
if (search.length > str.length) {
|
|
116
|
+
return false;
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
return str.indexOf(search) !== -1;
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
// repeatZero(qty)
|
|
123
|
+
// Returns "0" repeated `qty` times.
|
|
124
|
+
// `qty` must be a integer >= 0.
|
|
125
|
+
function repeatZero(qty) {
|
|
126
|
+
var result = "";
|
|
127
|
+
|
|
128
|
+
while (qty) {
|
|
129
|
+
result += "0";
|
|
130
|
+
qty -= 1;
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
return result;
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
function stringRound(digits) {
|
|
137
|
+
var digitsArray = digits.split("").reverse();
|
|
138
|
+
var i = 0;
|
|
139
|
+
var carry = true;
|
|
140
|
+
|
|
141
|
+
while (carry && i < digitsArray.length) {
|
|
142
|
+
if (i) {
|
|
143
|
+
if (digitsArray[i] === "9") {
|
|
144
|
+
digitsArray[i] = "0";
|
|
145
|
+
} else {
|
|
146
|
+
digitsArray[i] = (parseInt(digitsArray[i], 10) + 1).toString();
|
|
147
|
+
carry = false;
|
|
148
|
+
}
|
|
149
|
+
} else {
|
|
150
|
+
if (parseInt(digitsArray[i], 10) < 5) {
|
|
151
|
+
carry = false;
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
digitsArray[i] = "0";
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
i += 1;
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
if (carry) {
|
|
161
|
+
digitsArray.push("1");
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
return digitsArray.reverse().join("");
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
// cachedNumberFormat
|
|
168
|
+
// Returns an `Intl.NumberFormat` instance for the given locale and configuration.
|
|
169
|
+
// On first use of a particular configuration, the instance is cached for fast
|
|
170
|
+
// repeat access.
|
|
171
|
+
function cachedNumberFormat(locale, options) {
|
|
172
|
+
// Create a sorted, stringified version of `options`
|
|
173
|
+
// for use as part of the cache key
|
|
174
|
+
var optionsString = map(
|
|
175
|
+
keys(options).sort(),
|
|
176
|
+
function(key) {
|
|
177
|
+
return key + ':' + options[key];
|
|
178
|
+
}
|
|
179
|
+
).join(',');
|
|
180
|
+
|
|
181
|
+
// Set our cache key
|
|
182
|
+
var cacheKey = locale + '+' + optionsString;
|
|
183
|
+
|
|
184
|
+
// If we don't have this configuration cached, configure and cache it
|
|
185
|
+
if (!cachedNumberFormat.cache[cacheKey]) {
|
|
186
|
+
cachedNumberFormat.cache[cacheKey] = Intl.NumberFormat(locale, options);
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
// Return the cached version of this configuration
|
|
190
|
+
return cachedNumberFormat.cache[cacheKey];
|
|
191
|
+
}
|
|
192
|
+
cachedNumberFormat.cache = {};
|
|
193
|
+
|
|
194
|
+
// formatNumber
|
|
195
|
+
// Formats any number greater than or equal to zero using these options:
|
|
196
|
+
// - userLocale
|
|
197
|
+
// - useToLocaleString
|
|
198
|
+
// - useGrouping
|
|
199
|
+
// - grouping
|
|
200
|
+
// - maximumSignificantDigits
|
|
201
|
+
// - minimumIntegerDigits
|
|
202
|
+
// - fractionDigits
|
|
203
|
+
// - groupingSeparator
|
|
204
|
+
// - decimalSeparator
|
|
205
|
+
//
|
|
206
|
+
// `useToLocaleString` will use `Intl.NumberFormat` or `toLocaleString` for formatting.
|
|
207
|
+
// `userLocale` option is passed through to the formatting function.
|
|
208
|
+
// `fractionDigits` is passed through to `maximumFractionDigits` and `minimumFractionDigits`
|
|
209
|
+
// Using `maximumSignificantDigits` will override `minimumIntegerDigits` and `fractionDigits`.
|
|
210
|
+
function formatNumber(number, options, userLocale) {
|
|
211
|
+
var useToLocaleString = options.useToLocaleString;
|
|
212
|
+
var useGrouping = options.useGrouping;
|
|
213
|
+
var grouping = useGrouping && options.grouping.slice();
|
|
214
|
+
var maximumSignificantDigits = options.maximumSignificantDigits;
|
|
215
|
+
var minimumIntegerDigits = options.minimumIntegerDigits || 1;
|
|
216
|
+
var fractionDigits = options.fractionDigits || 0;
|
|
217
|
+
var groupingSeparator = options.groupingSeparator;
|
|
218
|
+
var decimalSeparator = options.decimalSeparator;
|
|
219
|
+
|
|
220
|
+
if (useToLocaleString && userLocale) {
|
|
221
|
+
var localeStringOptions = {
|
|
222
|
+
minimumIntegerDigits: minimumIntegerDigits,
|
|
223
|
+
useGrouping: useGrouping
|
|
224
|
+
};
|
|
225
|
+
|
|
226
|
+
if (fractionDigits) {
|
|
227
|
+
localeStringOptions.maximumFractionDigits = fractionDigits;
|
|
228
|
+
localeStringOptions.minimumFractionDigits = fractionDigits;
|
|
229
|
+
}
|
|
230
|
+
|
|
231
|
+
// toLocaleString output is "0.0" instead of "0" for HTC browsers
|
|
232
|
+
// when maximumSignificantDigits is set. See #96.
|
|
233
|
+
if (maximumSignificantDigits && number > 0) {
|
|
234
|
+
localeStringOptions.maximumSignificantDigits = maximumSignificantDigits;
|
|
235
|
+
}
|
|
236
|
+
|
|
237
|
+
if (intlNumberFormatWorks) {
|
|
238
|
+
if (!intlNumberFormatRoundingWorks) {
|
|
239
|
+
var roundingOptions = extend({}, options);
|
|
240
|
+
roundingOptions.useGrouping = false;
|
|
241
|
+
roundingOptions.decimalSeparator = ".";
|
|
242
|
+
number = parseFloat(formatNumber(number, roundingOptions), 10);
|
|
243
|
+
}
|
|
244
|
+
|
|
245
|
+
return cachedNumberFormat(userLocale, localeStringOptions).format(number);
|
|
246
|
+
} else {
|
|
247
|
+
if (!toLocaleStringRoundingWorks) {
|
|
248
|
+
var roundingOptions = extend({}, options);
|
|
249
|
+
roundingOptions.useGrouping = false;
|
|
250
|
+
roundingOptions.decimalSeparator = ".";
|
|
251
|
+
number = parseFloat(formatNumber(number, roundingOptions), 10);
|
|
252
|
+
}
|
|
253
|
+
|
|
254
|
+
return number.toLocaleString(userLocale, localeStringOptions);
|
|
255
|
+
}
|
|
256
|
+
}
|
|
257
|
+
|
|
258
|
+
var numberString;
|
|
259
|
+
|
|
260
|
+
// Add 1 to digit output length for floating point errors workaround. See below.
|
|
261
|
+
if (maximumSignificantDigits) {
|
|
262
|
+
numberString = number.toPrecision(maximumSignificantDigits + 1);
|
|
263
|
+
} else {
|
|
264
|
+
numberString = number.toFixed(fractionDigits + 1);
|
|
265
|
+
}
|
|
266
|
+
|
|
267
|
+
var integerString;
|
|
268
|
+
var fractionString;
|
|
269
|
+
var exponentString;
|
|
270
|
+
|
|
271
|
+
var temp = numberString.split("e");
|
|
272
|
+
|
|
273
|
+
exponentString = temp[1] || "";
|
|
274
|
+
|
|
275
|
+
temp = temp[0].split(".");
|
|
276
|
+
|
|
277
|
+
fractionString = temp[1] || "";
|
|
278
|
+
integerString = temp[0] || "";
|
|
279
|
+
|
|
280
|
+
// Workaround for floating point errors in `toFixed` and `toPrecision`.
|
|
281
|
+
// (3.55).toFixed(1); --> "3.5"
|
|
282
|
+
// (123.55 - 120).toPrecision(2); --> "3.5"
|
|
283
|
+
// (123.55 - 120); --> 3.549999999999997
|
|
284
|
+
// (123.55 - 120).toFixed(2); --> "3.55"
|
|
285
|
+
// Round by examing the string output of the next digit.
|
|
286
|
+
|
|
287
|
+
// *************** Implement String Rounding here ***********************
|
|
288
|
+
// Check integerString + fractionString length of toPrecision before rounding.
|
|
289
|
+
// Check length of fractionString from toFixed output before rounding.
|
|
290
|
+
var integerLength = integerString.length;
|
|
291
|
+
var fractionLength = fractionString.length;
|
|
292
|
+
var digitCount = integerLength + fractionLength;
|
|
293
|
+
var digits = integerString + fractionString;
|
|
294
|
+
|
|
295
|
+
if (maximumSignificantDigits && digitCount === (maximumSignificantDigits + 1) || !maximumSignificantDigits && fractionLength === (fractionDigits + 1)) {
|
|
296
|
+
// Round digits.
|
|
297
|
+
digits = stringRound(digits);
|
|
298
|
+
|
|
299
|
+
if (digits.length === digitCount + 1) {
|
|
300
|
+
integerLength = integerLength + 1;
|
|
301
|
+
}
|
|
302
|
+
|
|
303
|
+
// Discard final fractionDigit.
|
|
304
|
+
if (fractionLength) {
|
|
305
|
+
digits = digits.slice(0, -1);
|
|
306
|
+
}
|
|
307
|
+
|
|
308
|
+
// Separate integer and fraction.
|
|
309
|
+
integerString = digits.slice(0, integerLength);
|
|
310
|
+
fractionString = digits.slice(integerLength);
|
|
311
|
+
}
|
|
312
|
+
|
|
313
|
+
// Trim trailing zeroes from fractionString because toPrecision outputs
|
|
314
|
+
// precision, not significant digits.
|
|
315
|
+
if (maximumSignificantDigits) {
|
|
316
|
+
fractionString = fractionString.replace(/0*$/, "");
|
|
317
|
+
}
|
|
318
|
+
|
|
319
|
+
// Handle exponent.
|
|
320
|
+
var exponent = parseInt(exponentString, 10);
|
|
321
|
+
|
|
322
|
+
if (exponent > 0) {
|
|
323
|
+
if (fractionString.length <= exponent) {
|
|
324
|
+
fractionString = fractionString + repeatZero(exponent - fractionString.length);
|
|
325
|
+
|
|
326
|
+
integerString = integerString + fractionString;
|
|
327
|
+
fractionString = "";
|
|
328
|
+
} else {
|
|
329
|
+
integerString = integerString + fractionString.slice(0, exponent);
|
|
330
|
+
fractionString = fractionString.slice(exponent);
|
|
331
|
+
}
|
|
332
|
+
} else if (exponent < 0) {
|
|
333
|
+
fractionString = (repeatZero(Math.abs(exponent) - integerString.length) + integerString + fractionString);
|
|
334
|
+
|
|
335
|
+
integerString = "0";
|
|
336
|
+
}
|
|
337
|
+
|
|
338
|
+
if (!maximumSignificantDigits) {
|
|
339
|
+
// Trim or pad fraction when not using maximumSignificantDigits.
|
|
340
|
+
fractionString = fractionString.slice(0, fractionDigits);
|
|
341
|
+
|
|
342
|
+
if (fractionString.length < fractionDigits) {
|
|
343
|
+
fractionString = fractionString + repeatZero(fractionDigits - fractionString.length);
|
|
344
|
+
}
|
|
345
|
+
|
|
346
|
+
// Pad integer when using minimumIntegerDigits
|
|
347
|
+
// and not using maximumSignificantDigits.
|
|
348
|
+
if (integerString.length < minimumIntegerDigits) {
|
|
349
|
+
integerString = repeatZero(minimumIntegerDigits - integerString.length) + integerString;
|
|
350
|
+
}
|
|
351
|
+
}
|
|
352
|
+
|
|
353
|
+
var formattedString = "";
|
|
354
|
+
|
|
355
|
+
// Handle grouping.
|
|
356
|
+
if (useGrouping) {
|
|
357
|
+
temp = integerString;
|
|
358
|
+
var group;
|
|
359
|
+
|
|
360
|
+
while (temp.length) {
|
|
361
|
+
if (grouping.length) {
|
|
362
|
+
group = grouping.shift();
|
|
363
|
+
}
|
|
364
|
+
|
|
365
|
+
if (formattedString) {
|
|
366
|
+
formattedString = groupingSeparator + formattedString;
|
|
367
|
+
}
|
|
368
|
+
|
|
369
|
+
formattedString = temp.slice(-group) + formattedString;
|
|
370
|
+
|
|
371
|
+
temp = temp.slice(0, -group);
|
|
372
|
+
}
|
|
373
|
+
} else {
|
|
374
|
+
formattedString = integerString;
|
|
375
|
+
}
|
|
376
|
+
|
|
377
|
+
// Add decimalSeparator and fraction.
|
|
378
|
+
if (fractionString) {
|
|
379
|
+
formattedString = formattedString + decimalSeparator + fractionString;
|
|
380
|
+
}
|
|
381
|
+
|
|
382
|
+
return formattedString;
|
|
383
|
+
}
|
|
384
|
+
|
|
385
|
+
// durationLabelCompare
|
|
386
|
+
function durationLabelCompare(a, b) {
|
|
387
|
+
if (a.label.length > b.label.length) {
|
|
388
|
+
return -1;
|
|
389
|
+
}
|
|
390
|
+
|
|
391
|
+
if (a.label.length < b.label.length) {
|
|
392
|
+
return 1;
|
|
393
|
+
}
|
|
394
|
+
|
|
395
|
+
// a must be equal to b
|
|
396
|
+
return 0;
|
|
397
|
+
}
|
|
398
|
+
|
|
399
|
+
// durationGetLabels
|
|
400
|
+
function durationGetLabels(token, localeData) {
|
|
401
|
+
var labels = [];
|
|
402
|
+
|
|
403
|
+
each(keys(localeData), function (localeDataKey) {
|
|
404
|
+
if (localeDataKey.slice(0, 15) !== "_durationLabels") {
|
|
405
|
+
return;
|
|
406
|
+
}
|
|
407
|
+
|
|
408
|
+
var labelType = localeDataKey.slice(15).toLowerCase();
|
|
409
|
+
|
|
410
|
+
each(keys(localeData[localeDataKey]), function (labelKey) {
|
|
411
|
+
if (labelKey.slice(0, 1) === token) {
|
|
412
|
+
labels.push({
|
|
413
|
+
type: labelType,
|
|
414
|
+
key: labelKey,
|
|
415
|
+
label: localeData[localeDataKey][labelKey]
|
|
416
|
+
});
|
|
417
|
+
}
|
|
418
|
+
});
|
|
419
|
+
});
|
|
420
|
+
|
|
421
|
+
return labels;
|
|
422
|
+
}
|
|
423
|
+
|
|
424
|
+
// durationPluralKey
|
|
425
|
+
function durationPluralKey(token, integerValue, decimalValue) {
|
|
426
|
+
// Singular for a value of `1`, but not for `1.0`.
|
|
427
|
+
if (integerValue === 1 && decimalValue === null) {
|
|
428
|
+
return token;
|
|
429
|
+
}
|
|
430
|
+
|
|
431
|
+
return token + token;
|
|
432
|
+
}
|
|
433
|
+
|
|
434
|
+
var engLocale = {
|
|
435
|
+
durationLabelsStandard: {
|
|
436
|
+
S: 'millisecond',
|
|
437
|
+
SS: 'milliseconds',
|
|
438
|
+
s: 'second',
|
|
439
|
+
ss: 'seconds',
|
|
440
|
+
m: 'minute',
|
|
441
|
+
mm: 'minutes',
|
|
442
|
+
h: 'hour',
|
|
443
|
+
hh: 'hours',
|
|
444
|
+
d: 'day',
|
|
445
|
+
dd: 'days',
|
|
446
|
+
w: 'week',
|
|
447
|
+
ww: 'weeks',
|
|
448
|
+
M: 'month',
|
|
449
|
+
MM: 'months',
|
|
450
|
+
y: 'year',
|
|
451
|
+
yy: 'years'
|
|
452
|
+
},
|
|
453
|
+
durationLabelsShort: {
|
|
454
|
+
S: 'msec',
|
|
455
|
+
SS: 'msecs',
|
|
456
|
+
s: 'sec',
|
|
457
|
+
ss: 'secs',
|
|
458
|
+
m: 'min',
|
|
459
|
+
mm: 'mins',
|
|
460
|
+
h: 'hr',
|
|
461
|
+
hh: 'hrs',
|
|
462
|
+
d: 'dy',
|
|
463
|
+
dd: 'dys',
|
|
464
|
+
w: 'wk',
|
|
465
|
+
ww: 'wks',
|
|
466
|
+
M: 'mo',
|
|
467
|
+
MM: 'mos',
|
|
468
|
+
y: 'yr',
|
|
469
|
+
yy: 'yrs'
|
|
470
|
+
},
|
|
471
|
+
durationTimeTemplates: {
|
|
472
|
+
HMS: 'h:mm:ss',
|
|
473
|
+
HM: 'h:mm',
|
|
474
|
+
MS: 'm:ss'
|
|
475
|
+
},
|
|
476
|
+
durationLabelTypes: [
|
|
477
|
+
{ type: "standard", string: "__" },
|
|
478
|
+
{ type: "short", string: "_" }
|
|
479
|
+
],
|
|
480
|
+
durationPluralKey: durationPluralKey
|
|
481
|
+
};
|
|
482
|
+
|
|
483
|
+
// isArray
|
|
484
|
+
function isArray(array) {
|
|
485
|
+
return Object.prototype.toString.call(array) === "[object Array]";
|
|
486
|
+
}
|
|
487
|
+
|
|
488
|
+
// isObject
|
|
489
|
+
function isObject(obj) {
|
|
490
|
+
return Object.prototype.toString.call(obj) === "[object Object]";
|
|
491
|
+
}
|
|
492
|
+
|
|
493
|
+
// findLast
|
|
494
|
+
function findLast(array, callback) {
|
|
495
|
+
var index = array.length;
|
|
496
|
+
|
|
497
|
+
while (index -= 1) {
|
|
498
|
+
if (callback(array[index])) { return array[index]; }
|
|
499
|
+
}
|
|
500
|
+
}
|
|
501
|
+
|
|
502
|
+
// find
|
|
503
|
+
function find(array, callback) {
|
|
504
|
+
var index = 0;
|
|
505
|
+
|
|
506
|
+
var max = array && array.length || 0;
|
|
507
|
+
|
|
508
|
+
var match;
|
|
509
|
+
|
|
510
|
+
if (typeof callback !== "function") {
|
|
511
|
+
match = callback;
|
|
512
|
+
callback = function (item) {
|
|
513
|
+
return item === match;
|
|
514
|
+
};
|
|
515
|
+
}
|
|
516
|
+
|
|
517
|
+
while (index < max) {
|
|
518
|
+
if (callback(array[index])) { return array[index]; }
|
|
519
|
+
index += 1;
|
|
520
|
+
}
|
|
521
|
+
}
|
|
522
|
+
|
|
523
|
+
// each
|
|
524
|
+
function each(array, callback) {
|
|
525
|
+
var index = 0,
|
|
526
|
+
max = array.length;
|
|
527
|
+
|
|
528
|
+
if (!array || !max) { return; }
|
|
529
|
+
|
|
530
|
+
while (index < max) {
|
|
531
|
+
if (callback(array[index], index) === false) { return; }
|
|
532
|
+
index += 1;
|
|
533
|
+
}
|
|
534
|
+
}
|
|
535
|
+
|
|
536
|
+
// map
|
|
537
|
+
function map(array, callback) {
|
|
538
|
+
var index = 0,
|
|
539
|
+
max = array.length,
|
|
540
|
+
ret = [];
|
|
541
|
+
|
|
542
|
+
if (!array || !max) { return ret; }
|
|
543
|
+
|
|
544
|
+
while (index < max) {
|
|
545
|
+
ret[index] = callback(array[index], index);
|
|
546
|
+
index += 1;
|
|
547
|
+
}
|
|
548
|
+
|
|
549
|
+
return ret;
|
|
550
|
+
}
|
|
551
|
+
|
|
552
|
+
// pluck
|
|
553
|
+
function pluck(array, prop) {
|
|
554
|
+
return map(array, function (item) {
|
|
555
|
+
return item[prop];
|
|
556
|
+
});
|
|
557
|
+
}
|
|
558
|
+
|
|
559
|
+
// compact
|
|
560
|
+
function compact(array) {
|
|
561
|
+
var ret = [];
|
|
562
|
+
|
|
563
|
+
each(array, function (item) {
|
|
564
|
+
if (item) { ret.push(item); }
|
|
565
|
+
});
|
|
566
|
+
|
|
567
|
+
return ret;
|
|
568
|
+
}
|
|
569
|
+
|
|
570
|
+
// unique
|
|
571
|
+
function unique(array) {
|
|
572
|
+
var ret = [];
|
|
573
|
+
|
|
574
|
+
each(array, function (_a) {
|
|
575
|
+
if (!find(ret, _a)) { ret.push(_a); }
|
|
576
|
+
});
|
|
577
|
+
|
|
578
|
+
return ret;
|
|
579
|
+
}
|
|
580
|
+
|
|
581
|
+
// intersection
|
|
582
|
+
function intersection(a, b) {
|
|
583
|
+
var ret = [];
|
|
584
|
+
|
|
585
|
+
each(a, function (_a) {
|
|
586
|
+
each(b, function (_b) {
|
|
587
|
+
if (_a === _b) { ret.push(_a); }
|
|
588
|
+
});
|
|
589
|
+
});
|
|
590
|
+
|
|
591
|
+
return unique(ret);
|
|
592
|
+
}
|
|
593
|
+
|
|
594
|
+
// rest
|
|
595
|
+
function rest(array, callback) {
|
|
596
|
+
var ret = [];
|
|
597
|
+
|
|
598
|
+
each(array, function (item, index) {
|
|
599
|
+
if (!callback(item)) {
|
|
600
|
+
ret = array.slice(index);
|
|
601
|
+
return false;
|
|
602
|
+
}
|
|
603
|
+
});
|
|
604
|
+
|
|
605
|
+
return ret;
|
|
606
|
+
}
|
|
607
|
+
|
|
608
|
+
// initial
|
|
609
|
+
function initial(array, callback) {
|
|
610
|
+
var reversed = array.slice().reverse();
|
|
611
|
+
|
|
612
|
+
return rest(reversed, callback).reverse();
|
|
613
|
+
}
|
|
614
|
+
|
|
615
|
+
// extend
|
|
616
|
+
function extend(a, b) {
|
|
617
|
+
for (var key in b) {
|
|
618
|
+
if (b.hasOwnProperty(key)) { a[key] = b[key]; }
|
|
619
|
+
}
|
|
620
|
+
|
|
621
|
+
return a;
|
|
622
|
+
}
|
|
623
|
+
|
|
624
|
+
// keys
|
|
625
|
+
function keys(a) {
|
|
626
|
+
var ret = [];
|
|
627
|
+
|
|
628
|
+
for (var key in a) {
|
|
629
|
+
if (a.hasOwnProperty(key)) { ret.push(key); }
|
|
630
|
+
}
|
|
631
|
+
|
|
632
|
+
return ret;
|
|
633
|
+
}
|
|
634
|
+
|
|
635
|
+
// any
|
|
636
|
+
function any(array, callback) {
|
|
637
|
+
var index = 0,
|
|
638
|
+
max = array.length;
|
|
639
|
+
|
|
640
|
+
if (!array || !max) { return false; }
|
|
641
|
+
|
|
642
|
+
while (index < max) {
|
|
643
|
+
if (callback(array[index], index) === true) { return true; }
|
|
644
|
+
index += 1;
|
|
645
|
+
}
|
|
646
|
+
|
|
647
|
+
return false;
|
|
648
|
+
}
|
|
649
|
+
|
|
650
|
+
// flatten
|
|
651
|
+
function flatten(array) {
|
|
652
|
+
var ret = [];
|
|
653
|
+
|
|
654
|
+
each(array, function(child) {
|
|
655
|
+
ret = ret.concat(child);
|
|
656
|
+
});
|
|
657
|
+
|
|
658
|
+
return ret;
|
|
659
|
+
}
|
|
660
|
+
|
|
661
|
+
function toLocaleStringSupportsLocales() {
|
|
662
|
+
var number = 0;
|
|
663
|
+
try {
|
|
664
|
+
number.toLocaleString('i');
|
|
665
|
+
} catch (e) {
|
|
666
|
+
return e.name === 'RangeError';
|
|
667
|
+
}
|
|
668
|
+
return false;
|
|
669
|
+
}
|
|
670
|
+
|
|
671
|
+
function featureTestFormatterRounding(formatter) {
|
|
672
|
+
return formatter(3.55, "en", {
|
|
673
|
+
useGrouping: false,
|
|
674
|
+
minimumIntegerDigits: 1,
|
|
675
|
+
minimumFractionDigits: 1,
|
|
676
|
+
maximumFractionDigits: 1
|
|
677
|
+
}) === "3.6";
|
|
678
|
+
}
|
|
679
|
+
|
|
680
|
+
function featureTestFormatter(formatter) {
|
|
681
|
+
var passed = true;
|
|
682
|
+
|
|
683
|
+
// Test minimumIntegerDigits.
|
|
684
|
+
passed = passed && formatter(1, "en", { minimumIntegerDigits: 1 }) === "1";
|
|
685
|
+
passed = passed && formatter(1, "en", { minimumIntegerDigits: 2 }) === "01";
|
|
686
|
+
passed = passed && formatter(1, "en", { minimumIntegerDigits: 3 }) === "001";
|
|
687
|
+
if (!passed) { return false; }
|
|
688
|
+
|
|
689
|
+
// Test maximumFractionDigits and minimumFractionDigits.
|
|
690
|
+
passed = passed && formatter(99.99, "en", { maximumFractionDigits: 0, minimumFractionDigits: 0 }) === "100";
|
|
691
|
+
passed = passed && formatter(99.99, "en", { maximumFractionDigits: 1, minimumFractionDigits: 1 }) === "100.0";
|
|
692
|
+
passed = passed && formatter(99.99, "en", { maximumFractionDigits: 2, minimumFractionDigits: 2 }) === "99.99";
|
|
693
|
+
passed = passed && formatter(99.99, "en", { maximumFractionDigits: 3, minimumFractionDigits: 3 }) === "99.990";
|
|
694
|
+
if (!passed) { return false; }
|
|
695
|
+
|
|
696
|
+
// Test maximumSignificantDigits.
|
|
697
|
+
passed = passed && formatter(99.99, "en", { maximumSignificantDigits: 1 }) === "100";
|
|
698
|
+
passed = passed && formatter(99.99, "en", { maximumSignificantDigits: 2 }) === "100";
|
|
699
|
+
passed = passed && formatter(99.99, "en", { maximumSignificantDigits: 3 }) === "100";
|
|
700
|
+
passed = passed && formatter(99.99, "en", { maximumSignificantDigits: 4 }) === "99.99";
|
|
701
|
+
passed = passed && formatter(99.99, "en", { maximumSignificantDigits: 5 }) === "99.99";
|
|
702
|
+
if (!passed) { return false; }
|
|
703
|
+
|
|
704
|
+
// Test grouping.
|
|
705
|
+
passed = passed && formatter(1000, "en", { useGrouping: true }) === "1,000";
|
|
706
|
+
passed = passed && formatter(1000, "en", { useGrouping: false }) === "1000";
|
|
707
|
+
if (!passed) { return false; }
|
|
708
|
+
|
|
709
|
+
return true;
|
|
710
|
+
}
|
|
711
|
+
|
|
712
|
+
// durationsFormat(durations [, template] [, precision] [, settings])
|
|
713
|
+
function durationsFormat() {
|
|
714
|
+
var args = [].slice.call(arguments);
|
|
715
|
+
var settings = {};
|
|
716
|
+
var durations;
|
|
717
|
+
|
|
718
|
+
// Parse arguments.
|
|
719
|
+
each(args, function (arg, index) {
|
|
720
|
+
if (!index) {
|
|
721
|
+
if (!isArray(arg)) {
|
|
722
|
+
throw "Expected array as the first argument to durationsFormat.";
|
|
723
|
+
}
|
|
724
|
+
|
|
725
|
+
durations = arg;
|
|
726
|
+
}
|
|
727
|
+
|
|
728
|
+
if (typeof arg === "string" || typeof arg === "function") {
|
|
729
|
+
settings.template = arg;
|
|
730
|
+
return;
|
|
731
|
+
}
|
|
732
|
+
|
|
733
|
+
if (typeof arg === "number") {
|
|
734
|
+
settings.precision = arg;
|
|
735
|
+
return;
|
|
736
|
+
}
|
|
737
|
+
|
|
738
|
+
if (isObject(arg)) {
|
|
739
|
+
extend(settings, arg);
|
|
740
|
+
}
|
|
741
|
+
});
|
|
742
|
+
|
|
743
|
+
if (!durations || !durations.length) {
|
|
744
|
+
return [];
|
|
745
|
+
}
|
|
746
|
+
|
|
747
|
+
settings.returnMomentTypes = true;
|
|
748
|
+
|
|
749
|
+
var formattedDurations = map(durations, function (dur) {
|
|
750
|
+
return dur.format(settings);
|
|
751
|
+
});
|
|
752
|
+
|
|
753
|
+
// Merge token types from all durations.
|
|
754
|
+
var outputTypes = intersection(types, unique(pluck(flatten(formattedDurations), "type")));
|
|
755
|
+
|
|
756
|
+
var largest = settings.largest;
|
|
757
|
+
|
|
758
|
+
if (largest) {
|
|
759
|
+
outputTypes = outputTypes.slice(0, largest);
|
|
760
|
+
}
|
|
761
|
+
|
|
762
|
+
settings.returnMomentTypes = false;
|
|
763
|
+
settings.outputTypes = outputTypes;
|
|
764
|
+
|
|
765
|
+
return map(durations, function (dur) {
|
|
766
|
+
return dur.format(settings);
|
|
767
|
+
});
|
|
768
|
+
}
|
|
769
|
+
|
|
770
|
+
// durationFormat([template] [, precision] [, settings])
|
|
771
|
+
function durationFormat() {
|
|
772
|
+
|
|
773
|
+
var args = [].slice.call(arguments);
|
|
774
|
+
var settings = extend({}, this.format.defaults);
|
|
775
|
+
|
|
776
|
+
// Keep a shadow copy of this moment for calculating remainders.
|
|
777
|
+
// Perform all calculations on positive duration value, handle negative
|
|
778
|
+
// sign at the very end.
|
|
779
|
+
var asMilliseconds = this.asMilliseconds();
|
|
780
|
+
var asMonths = this.asMonths();
|
|
781
|
+
|
|
782
|
+
// Treat invalid durations as having a value of 0 milliseconds.
|
|
783
|
+
if (typeof this.isValid === "function" && this.isValid() === false) {
|
|
784
|
+
asMilliseconds = 0;
|
|
785
|
+
asMonths = 0;
|
|
786
|
+
}
|
|
787
|
+
|
|
788
|
+
var isNegative = asMilliseconds < 0;
|
|
789
|
+
|
|
790
|
+
// Two shadow copies are needed because of the way moment.js handles
|
|
791
|
+
// duration arithmetic for years/months and for weeks/days/hours/minutes/seconds.
|
|
792
|
+
var remainder = moment.duration(Math.abs(asMilliseconds), "milliseconds");
|
|
793
|
+
var remainderMonths = moment.duration(Math.abs(asMonths), "months");
|
|
794
|
+
|
|
795
|
+
// Parse arguments.
|
|
796
|
+
each(args, function (arg) {
|
|
797
|
+
if (typeof arg === "string" || typeof arg === "function") {
|
|
798
|
+
settings.template = arg;
|
|
799
|
+
return;
|
|
800
|
+
}
|
|
801
|
+
|
|
802
|
+
if (typeof arg === "number") {
|
|
803
|
+
settings.precision = arg;
|
|
804
|
+
return;
|
|
805
|
+
}
|
|
806
|
+
|
|
807
|
+
if (isObject(arg)) {
|
|
808
|
+
extend(settings, arg);
|
|
809
|
+
}
|
|
810
|
+
});
|
|
811
|
+
|
|
812
|
+
var momentTokens = {
|
|
813
|
+
years: "y",
|
|
814
|
+
months: "M",
|
|
815
|
+
weeks: "w",
|
|
816
|
+
days: "d",
|
|
817
|
+
hours: "h",
|
|
818
|
+
minutes: "m",
|
|
819
|
+
seconds: "s",
|
|
820
|
+
milliseconds: "S"
|
|
821
|
+
};
|
|
822
|
+
|
|
823
|
+
var tokenDefs = {
|
|
824
|
+
escape: /\[(.+?)\]/,
|
|
825
|
+
years: /\*?[Yy]+/,
|
|
826
|
+
months: /\*?M+/,
|
|
827
|
+
weeks: /\*?[Ww]+/,
|
|
828
|
+
days: /\*?[Dd]+/,
|
|
829
|
+
hours: /\*?[Hh]+/,
|
|
830
|
+
minutes: /\*?m+/,
|
|
831
|
+
seconds: /\*?s+/,
|
|
832
|
+
milliseconds: /\*?S+/,
|
|
833
|
+
general: /.+?/
|
|
834
|
+
};
|
|
835
|
+
|
|
836
|
+
// Types array is available in the template function.
|
|
837
|
+
settings.types = types;
|
|
838
|
+
|
|
839
|
+
var typeMap = function (token) {
|
|
840
|
+
return find(types, function (type) {
|
|
841
|
+
return tokenDefs[type].test(token);
|
|
842
|
+
});
|
|
843
|
+
};
|
|
844
|
+
|
|
845
|
+
var tokenizer = new RegExp(map(types, function (type) {
|
|
846
|
+
return tokenDefs[type].source;
|
|
847
|
+
}).join("|"), "g");
|
|
848
|
+
|
|
849
|
+
// Current duration object is available in the template function.
|
|
850
|
+
settings.duration = this;
|
|
851
|
+
|
|
852
|
+
// Eval template function and cache template string.
|
|
853
|
+
var template = typeof settings.template === "function" ? settings.template.apply(settings) : settings.template;
|
|
854
|
+
|
|
855
|
+
// outputTypes and returnMomentTypes are settings to support durationsFormat().
|
|
856
|
+
|
|
857
|
+
// outputTypes is an array of moment token types that determines
|
|
858
|
+
// the tokens returned in formatted output. This option overrides
|
|
859
|
+
// trim, largest, stopTrim, etc.
|
|
860
|
+
var outputTypes = settings.outputTypes;
|
|
861
|
+
|
|
862
|
+
// returnMomentTypes is a boolean that sets durationFormat to return
|
|
863
|
+
// the processed momentTypes instead of formatted output.
|
|
864
|
+
var returnMomentTypes = settings.returnMomentTypes;
|
|
865
|
+
|
|
866
|
+
var largest = settings.largest;
|
|
867
|
+
|
|
868
|
+
// Setup stopTrim array of token types.
|
|
869
|
+
var stopTrim = [];
|
|
870
|
+
|
|
871
|
+
if (!outputTypes) {
|
|
872
|
+
if (isArray(settings.stopTrim)) {
|
|
873
|
+
settings.stopTrim = settings.stopTrim.join("");
|
|
874
|
+
}
|
|
875
|
+
|
|
876
|
+
// Parse stopTrim string to create token types array.
|
|
877
|
+
if (settings.stopTrim) {
|
|
878
|
+
each(settings.stopTrim.match(tokenizer), function (token) {
|
|
879
|
+
var type = typeMap(token);
|
|
880
|
+
|
|
881
|
+
if (type === "escape" || type === "general") {
|
|
882
|
+
return;
|
|
883
|
+
}
|
|
884
|
+
|
|
885
|
+
stopTrim.push(type);
|
|
886
|
+
});
|
|
887
|
+
}
|
|
888
|
+
}
|
|
889
|
+
|
|
890
|
+
// Cache moment's locale data.
|
|
891
|
+
var localeData = moment.localeData();
|
|
892
|
+
|
|
893
|
+
if (!localeData) {
|
|
894
|
+
localeData = {};
|
|
895
|
+
}
|
|
896
|
+
|
|
897
|
+
// Fall back to this plugin's `eng` extension.
|
|
898
|
+
each(keys(engLocale), function (key) {
|
|
899
|
+
if (typeof engLocale[key] === "function") {
|
|
900
|
+
if (!localeData[key]) {
|
|
901
|
+
localeData[key] = engLocale[key];
|
|
902
|
+
}
|
|
903
|
+
|
|
904
|
+
return;
|
|
905
|
+
}
|
|
906
|
+
|
|
907
|
+
if (!localeData["_" + key]) {
|
|
908
|
+
localeData["_" + key] = engLocale[key];
|
|
909
|
+
}
|
|
910
|
+
});
|
|
911
|
+
|
|
912
|
+
// Replace Duration Time Template strings.
|
|
913
|
+
// For locale `eng`: `_HMS_`, `_HM_`, and `_MS_`.
|
|
914
|
+
each(keys(localeData._durationTimeTemplates), function (item) {
|
|
915
|
+
template = template.replace("_" + item + "_", localeData._durationTimeTemplates[item]);
|
|
916
|
+
});
|
|
917
|
+
|
|
918
|
+
// Determine user's locale.
|
|
919
|
+
var userLocale = settings.userLocale || moment.locale();
|
|
920
|
+
|
|
921
|
+
var useLeftUnits = settings.useLeftUnits;
|
|
922
|
+
var usePlural = settings.usePlural;
|
|
923
|
+
var precision = settings.precision;
|
|
924
|
+
var forceLength = settings.forceLength;
|
|
925
|
+
var useGrouping = settings.useGrouping;
|
|
926
|
+
var trunc = settings.trunc;
|
|
927
|
+
|
|
928
|
+
// Use significant digits only when precision is greater than 0.
|
|
929
|
+
var useSignificantDigits = settings.useSignificantDigits && precision > 0;
|
|
930
|
+
var significantDigits = useSignificantDigits ? settings.precision : 0;
|
|
931
|
+
var significantDigitsCache = significantDigits;
|
|
932
|
+
|
|
933
|
+
var minValue = settings.minValue;
|
|
934
|
+
var isMinValue = false;
|
|
935
|
+
|
|
936
|
+
var maxValue = settings.maxValue;
|
|
937
|
+
var isMaxValue = false;
|
|
938
|
+
|
|
939
|
+
// formatNumber fallback options.
|
|
940
|
+
var useToLocaleString = settings.useToLocaleString;
|
|
941
|
+
var groupingSeparator = settings.groupingSeparator;
|
|
942
|
+
var decimalSeparator = settings.decimalSeparator;
|
|
943
|
+
var grouping = settings.grouping;
|
|
944
|
+
|
|
945
|
+
useToLocaleString = useToLocaleString && (toLocaleStringWorks || intlNumberFormatWorks);
|
|
946
|
+
|
|
947
|
+
// Trim options.
|
|
948
|
+
var trim = settings.trim;
|
|
949
|
+
|
|
950
|
+
if (isArray(trim)) {
|
|
951
|
+
trim = trim.join(" ");
|
|
952
|
+
}
|
|
953
|
+
|
|
954
|
+
if (trim === null && (largest || maxValue || useSignificantDigits)) {
|
|
955
|
+
trim = "all";
|
|
956
|
+
}
|
|
957
|
+
|
|
958
|
+
if (trim === null || trim === true || trim === "left" || trim === "right") {
|
|
959
|
+
trim = "large";
|
|
960
|
+
}
|
|
961
|
+
|
|
962
|
+
if (trim === false) {
|
|
963
|
+
trim = "";
|
|
964
|
+
}
|
|
965
|
+
|
|
966
|
+
var trimIncludes = function (item) {
|
|
967
|
+
return item.test(trim);
|
|
968
|
+
};
|
|
969
|
+
|
|
970
|
+
var rLarge = /large/;
|
|
971
|
+
var rSmall = /small/;
|
|
972
|
+
var rBoth = /both/;
|
|
973
|
+
var rMid = /mid/;
|
|
974
|
+
var rAll = /^all|[^sm]all/;
|
|
975
|
+
var rFinal = /final/;
|
|
976
|
+
|
|
977
|
+
var trimLarge = largest > 0 || any([rLarge, rBoth, rAll], trimIncludes);
|
|
978
|
+
var trimSmall = any([rSmall, rBoth, rAll], trimIncludes);
|
|
979
|
+
var trimMid = any([rMid, rAll], trimIncludes);
|
|
980
|
+
var trimFinal = any([rFinal, rAll], trimIncludes);
|
|
981
|
+
|
|
982
|
+
// Parse format string to create raw tokens array.
|
|
983
|
+
var rawTokens = map(template.match(tokenizer), function (token, index) {
|
|
984
|
+
var type = typeMap(token);
|
|
985
|
+
|
|
986
|
+
if (token.slice(0, 1) === "*") {
|
|
987
|
+
token = token.slice(1);
|
|
988
|
+
|
|
989
|
+
if (type !== "escape" && type !== "general") {
|
|
990
|
+
stopTrim.push(type);
|
|
991
|
+
}
|
|
992
|
+
}
|
|
993
|
+
|
|
994
|
+
return {
|
|
995
|
+
index: index,
|
|
996
|
+
length: token.length,
|
|
997
|
+
text: "",
|
|
998
|
+
|
|
999
|
+
// Replace escaped tokens with the non-escaped token text.
|
|
1000
|
+
token: (type === "escape" ? token.replace(tokenDefs.escape, "$1") : token),
|
|
1001
|
+
|
|
1002
|
+
// Ignore type on non-moment tokens.
|
|
1003
|
+
type: ((type === "escape" || type === "general") ? null : type)
|
|
1004
|
+
};
|
|
1005
|
+
});
|
|
1006
|
+
|
|
1007
|
+
// Associate text tokens with moment tokens.
|
|
1008
|
+
var currentToken = {
|
|
1009
|
+
index: 0,
|
|
1010
|
+
length: 0,
|
|
1011
|
+
token: "",
|
|
1012
|
+
text: "",
|
|
1013
|
+
type: null
|
|
1014
|
+
};
|
|
1015
|
+
|
|
1016
|
+
var tokens = [];
|
|
1017
|
+
|
|
1018
|
+
if (useLeftUnits) {
|
|
1019
|
+
rawTokens.reverse();
|
|
1020
|
+
}
|
|
1021
|
+
|
|
1022
|
+
each(rawTokens, function (token) {
|
|
1023
|
+
if (token.type) {
|
|
1024
|
+
if (currentToken.type || currentToken.text) {
|
|
1025
|
+
tokens.push(currentToken);
|
|
1026
|
+
}
|
|
1027
|
+
|
|
1028
|
+
currentToken = token;
|
|
1029
|
+
|
|
1030
|
+
return;
|
|
1031
|
+
}
|
|
1032
|
+
|
|
1033
|
+
if (useLeftUnits) {
|
|
1034
|
+
currentToken.text = token.token + currentToken.text;
|
|
1035
|
+
} else {
|
|
1036
|
+
currentToken.text += token.token;
|
|
1037
|
+
}
|
|
1038
|
+
});
|
|
1039
|
+
|
|
1040
|
+
if (currentToken.type || currentToken.text) {
|
|
1041
|
+
tokens.push(currentToken);
|
|
1042
|
+
}
|
|
1043
|
+
|
|
1044
|
+
if (useLeftUnits) {
|
|
1045
|
+
tokens.reverse();
|
|
1046
|
+
}
|
|
1047
|
+
|
|
1048
|
+
// Find unique moment token types in the template in order of
|
|
1049
|
+
// descending magnitude.
|
|
1050
|
+
var momentTypes = intersection(types, unique(compact(pluck(tokens, "type"))));
|
|
1051
|
+
|
|
1052
|
+
// Exit early if there are no moment token types.
|
|
1053
|
+
if (!momentTypes.length) {
|
|
1054
|
+
return pluck(tokens, "text").join("");
|
|
1055
|
+
}
|
|
1056
|
+
|
|
1057
|
+
// Calculate values for each moment type in the template.
|
|
1058
|
+
// For processing the settings, values are associated with moment types.
|
|
1059
|
+
// Values will be assigned to tokens at the last step in order to
|
|
1060
|
+
// assume nothing about frequency or order of tokens in the template.
|
|
1061
|
+
momentTypes = map(momentTypes, function (momentType, index) {
|
|
1062
|
+
// Is this the least-magnitude moment token found?
|
|
1063
|
+
var isSmallest = ((index + 1) === momentTypes.length);
|
|
1064
|
+
|
|
1065
|
+
// Is this the greatest-magnitude moment token found?
|
|
1066
|
+
var isLargest = (!index);
|
|
1067
|
+
|
|
1068
|
+
// Get the raw value in the current units.
|
|
1069
|
+
var rawValue;
|
|
1070
|
+
|
|
1071
|
+
if (momentType === "years" || momentType === "months") {
|
|
1072
|
+
rawValue = remainderMonths.as(momentType);
|
|
1073
|
+
} else {
|
|
1074
|
+
rawValue = remainder.as(momentType);
|
|
1075
|
+
}
|
|
1076
|
+
|
|
1077
|
+
var wholeValue = Math.floor(rawValue);
|
|
1078
|
+
var decimalValue = rawValue - wholeValue;
|
|
1079
|
+
|
|
1080
|
+
var token = find(tokens, function (token) {
|
|
1081
|
+
return momentType === token.type;
|
|
1082
|
+
});
|
|
1083
|
+
|
|
1084
|
+
if (isLargest && maxValue && rawValue > maxValue) {
|
|
1085
|
+
isMaxValue = true;
|
|
1086
|
+
}
|
|
1087
|
+
|
|
1088
|
+
if (isSmallest && minValue && Math.abs(settings.duration.as(momentType)) < minValue) {
|
|
1089
|
+
isMinValue = true;
|
|
1090
|
+
}
|
|
1091
|
+
|
|
1092
|
+
// Note the length of the largest-magnitude moment token:
|
|
1093
|
+
// if it is greater than one and forceLength is not set,
|
|
1094
|
+
// then default forceLength to `true`.
|
|
1095
|
+
//
|
|
1096
|
+
// Rationale is this: If the template is "h:mm:ss" and the
|
|
1097
|
+
// moment value is 5 minutes, the user-friendly output is
|
|
1098
|
+
// "5:00", not "05:00". We shouldn't pad the `minutes` token
|
|
1099
|
+
// even though it has length of two if the template is "h:mm:ss";
|
|
1100
|
+
//
|
|
1101
|
+
// If the minutes output should always include the leading zero
|
|
1102
|
+
// even when the hour is trimmed then set `{ forceLength: true }`
|
|
1103
|
+
// to output "05:00". If the template is "hh:mm:ss", the user
|
|
1104
|
+
// clearly wanted everything padded so we should output "05:00";
|
|
1105
|
+
//
|
|
1106
|
+
// If the user wants the full padded output, they can use
|
|
1107
|
+
// template "hh:mm:ss" and set `{ trim: false }` to output
|
|
1108
|
+
// "00:05:00".
|
|
1109
|
+
if (isLargest && forceLength === null && token.length > 1) {
|
|
1110
|
+
forceLength = true;
|
|
1111
|
+
}
|
|
1112
|
+
|
|
1113
|
+
// Update remainder.
|
|
1114
|
+
remainder.subtract(wholeValue, momentType);
|
|
1115
|
+
remainderMonths.subtract(wholeValue, momentType);
|
|
1116
|
+
|
|
1117
|
+
return {
|
|
1118
|
+
rawValue: rawValue,
|
|
1119
|
+
wholeValue: wholeValue,
|
|
1120
|
+
// Decimal value is only retained for the least-magnitude
|
|
1121
|
+
// moment type in the format template.
|
|
1122
|
+
decimalValue: isSmallest ? decimalValue : 0,
|
|
1123
|
+
isSmallest: isSmallest,
|
|
1124
|
+
isLargest: isLargest,
|
|
1125
|
+
type: momentType,
|
|
1126
|
+
// Tokens can appear multiple times in a template string,
|
|
1127
|
+
// but all instances must share the same length.
|
|
1128
|
+
tokenLength: token.length
|
|
1129
|
+
};
|
|
1130
|
+
});
|
|
1131
|
+
|
|
1132
|
+
var truncMethod = trunc ? Math.floor : Math.round;
|
|
1133
|
+
var truncate = function (value, places) {
|
|
1134
|
+
var factor = Math.pow(10, places);
|
|
1135
|
+
return truncMethod(value * factor) / factor;
|
|
1136
|
+
};
|
|
1137
|
+
|
|
1138
|
+
var foundFirst = false;
|
|
1139
|
+
var bubbled = false;
|
|
1140
|
+
|
|
1141
|
+
var formatValue = function (momentType, index) {
|
|
1142
|
+
var formatOptions = {
|
|
1143
|
+
useGrouping: useGrouping,
|
|
1144
|
+
groupingSeparator: groupingSeparator,
|
|
1145
|
+
decimalSeparator: decimalSeparator,
|
|
1146
|
+
grouping: grouping,
|
|
1147
|
+
useToLocaleString: useToLocaleString
|
|
1148
|
+
};
|
|
1149
|
+
|
|
1150
|
+
if (useSignificantDigits) {
|
|
1151
|
+
if (significantDigits <= 0) {
|
|
1152
|
+
momentType.rawValue = 0;
|
|
1153
|
+
momentType.wholeValue = 0;
|
|
1154
|
+
momentType.decimalValue = 0;
|
|
1155
|
+
} else {
|
|
1156
|
+
formatOptions.maximumSignificantDigits = significantDigits;
|
|
1157
|
+
momentType.significantDigits = significantDigits;
|
|
1158
|
+
}
|
|
1159
|
+
}
|
|
1160
|
+
|
|
1161
|
+
if (isMaxValue && !bubbled) {
|
|
1162
|
+
if (momentType.isLargest) {
|
|
1163
|
+
momentType.wholeValue = maxValue;
|
|
1164
|
+
momentType.decimalValue = 0;
|
|
1165
|
+
} else {
|
|
1166
|
+
momentType.wholeValue = 0;
|
|
1167
|
+
momentType.decimalValue = 0;
|
|
1168
|
+
}
|
|
1169
|
+
}
|
|
1170
|
+
|
|
1171
|
+
if (isMinValue && !bubbled) {
|
|
1172
|
+
if (momentType.isSmallest) {
|
|
1173
|
+
momentType.wholeValue = minValue;
|
|
1174
|
+
momentType.decimalValue = 0;
|
|
1175
|
+
} else {
|
|
1176
|
+
momentType.wholeValue = 0;
|
|
1177
|
+
momentType.decimalValue = 0;
|
|
1178
|
+
}
|
|
1179
|
+
}
|
|
1180
|
+
|
|
1181
|
+
if (momentType.isSmallest || momentType.significantDigits && momentType.significantDigits - momentType.wholeValue.toString().length <= 0) {
|
|
1182
|
+
// Apply precision to least significant token value.
|
|
1183
|
+
if (precision < 0) {
|
|
1184
|
+
momentType.value = truncate(momentType.wholeValue, precision);
|
|
1185
|
+
} else if (precision === 0) {
|
|
1186
|
+
momentType.value = truncMethod(momentType.wholeValue + momentType.decimalValue);
|
|
1187
|
+
} else { // precision > 0
|
|
1188
|
+
if (useSignificantDigits) {
|
|
1189
|
+
if (trunc) {
|
|
1190
|
+
momentType.value = truncate(momentType.rawValue, significantDigits - momentType.wholeValue.toString().length);
|
|
1191
|
+
} else {
|
|
1192
|
+
momentType.value = momentType.rawValue;
|
|
1193
|
+
}
|
|
1194
|
+
|
|
1195
|
+
if (momentType.wholeValue) {
|
|
1196
|
+
significantDigits -= momentType.wholeValue.toString().length;
|
|
1197
|
+
}
|
|
1198
|
+
} else {
|
|
1199
|
+
formatOptions.fractionDigits = precision;
|
|
1200
|
+
|
|
1201
|
+
if (trunc) {
|
|
1202
|
+
momentType.value = momentType.wholeValue + truncate(momentType.decimalValue, precision);
|
|
1203
|
+
} else {
|
|
1204
|
+
momentType.value = momentType.wholeValue + momentType.decimalValue;
|
|
1205
|
+
}
|
|
1206
|
+
}
|
|
1207
|
+
}
|
|
1208
|
+
} else {
|
|
1209
|
+
if (useSignificantDigits && momentType.wholeValue) {
|
|
1210
|
+
// Outer Math.round required here to handle floating point errors.
|
|
1211
|
+
momentType.value = Math.round(truncate(momentType.wholeValue, momentType.significantDigits - momentType.wholeValue.toString().length));
|
|
1212
|
+
|
|
1213
|
+
significantDigits -= momentType.wholeValue.toString().length;
|
|
1214
|
+
} else {
|
|
1215
|
+
momentType.value = momentType.wholeValue;
|
|
1216
|
+
}
|
|
1217
|
+
}
|
|
1218
|
+
|
|
1219
|
+
if (momentType.tokenLength > 1 && (forceLength || foundFirst)) {
|
|
1220
|
+
formatOptions.minimumIntegerDigits = momentType.tokenLength;
|
|
1221
|
+
|
|
1222
|
+
if (bubbled && formatOptions.maximumSignificantDigits < momentType.tokenLength) {
|
|
1223
|
+
delete formatOptions.maximumSignificantDigits;
|
|
1224
|
+
}
|
|
1225
|
+
}
|
|
1226
|
+
|
|
1227
|
+
if (!foundFirst && (momentType.value > 0 || trim === "" /* trim: false */ || find(stopTrim, momentType.type) || find(outputTypes, momentType.type))) {
|
|
1228
|
+
foundFirst = true;
|
|
1229
|
+
}
|
|
1230
|
+
|
|
1231
|
+
momentType.formattedValue = formatNumber(momentType.value, formatOptions, userLocale);
|
|
1232
|
+
|
|
1233
|
+
formatOptions.useGrouping = false;
|
|
1234
|
+
formatOptions.decimalSeparator = ".";
|
|
1235
|
+
momentType.formattedValueEn = formatNumber(momentType.value, formatOptions, "en");
|
|
1236
|
+
|
|
1237
|
+
if (momentType.tokenLength === 2 && momentType.type === "milliseconds") {
|
|
1238
|
+
momentType.formattedValueMS = formatNumber(momentType.value, {
|
|
1239
|
+
minimumIntegerDigits: 3,
|
|
1240
|
+
useGrouping: false
|
|
1241
|
+
}, "en").slice(0, 2);
|
|
1242
|
+
}
|
|
1243
|
+
|
|
1244
|
+
return momentType;
|
|
1245
|
+
};
|
|
1246
|
+
|
|
1247
|
+
// Calculate formatted values.
|
|
1248
|
+
momentTypes = map(momentTypes, formatValue);
|
|
1249
|
+
momentTypes = compact(momentTypes);
|
|
1250
|
+
|
|
1251
|
+
// Bubble rounded values.
|
|
1252
|
+
if (momentTypes.length > 1) {
|
|
1253
|
+
var findType = function (type) {
|
|
1254
|
+
return find(momentTypes, function (momentType) {
|
|
1255
|
+
return momentType.type === type;
|
|
1256
|
+
});
|
|
1257
|
+
};
|
|
1258
|
+
|
|
1259
|
+
var bubbleTypes = function (bubble) {
|
|
1260
|
+
var bubbleMomentType = findType(bubble.type);
|
|
1261
|
+
|
|
1262
|
+
if (!bubbleMomentType) {
|
|
1263
|
+
return;
|
|
1264
|
+
}
|
|
1265
|
+
|
|
1266
|
+
each(bubble.targets, function (target) {
|
|
1267
|
+
var targetMomentType = findType(target.type);
|
|
1268
|
+
|
|
1269
|
+
if (!targetMomentType) {
|
|
1270
|
+
return;
|
|
1271
|
+
}
|
|
1272
|
+
|
|
1273
|
+
if (parseInt(bubbleMomentType.formattedValueEn, 10) === target.value) {
|
|
1274
|
+
bubbleMomentType.rawValue = 0;
|
|
1275
|
+
bubbleMomentType.wholeValue = 0;
|
|
1276
|
+
bubbleMomentType.decimalValue = 0;
|
|
1277
|
+
targetMomentType.rawValue += 1;
|
|
1278
|
+
targetMomentType.wholeValue += 1;
|
|
1279
|
+
targetMomentType.decimalValue = 0;
|
|
1280
|
+
targetMomentType.formattedValueEn = targetMomentType.wholeValue.toString();
|
|
1281
|
+
bubbled = true;
|
|
1282
|
+
}
|
|
1283
|
+
});
|
|
1284
|
+
};
|
|
1285
|
+
|
|
1286
|
+
each(bubbles, bubbleTypes);
|
|
1287
|
+
}
|
|
1288
|
+
|
|
1289
|
+
// Recalculate formatted values.
|
|
1290
|
+
if (bubbled) {
|
|
1291
|
+
foundFirst = false;
|
|
1292
|
+
significantDigits = significantDigitsCache;
|
|
1293
|
+
momentTypes = map(momentTypes, formatValue);
|
|
1294
|
+
momentTypes = compact(momentTypes);
|
|
1295
|
+
}
|
|
1296
|
+
|
|
1297
|
+
if (outputTypes && !(isMaxValue && !settings.trim)) {
|
|
1298
|
+
momentTypes = map(momentTypes, function (momentType) {
|
|
1299
|
+
if (find(outputTypes, function (outputType) {
|
|
1300
|
+
return momentType.type === outputType;
|
|
1301
|
+
})) {
|
|
1302
|
+
return momentType;
|
|
1303
|
+
}
|
|
1304
|
+
|
|
1305
|
+
return null;
|
|
1306
|
+
});
|
|
1307
|
+
|
|
1308
|
+
momentTypes = compact(momentTypes);
|
|
1309
|
+
} else {
|
|
1310
|
+
// Trim Large.
|
|
1311
|
+
if (trimLarge) {
|
|
1312
|
+
momentTypes = rest(momentTypes, function (momentType) {
|
|
1313
|
+
// Stop trimming on:
|
|
1314
|
+
// - the smallest moment type
|
|
1315
|
+
// - a type marked for stopTrim
|
|
1316
|
+
// - a type that has a whole value
|
|
1317
|
+
return !momentType.isSmallest && !momentType.wholeValue && !find(stopTrim, momentType.type);
|
|
1318
|
+
});
|
|
1319
|
+
}
|
|
1320
|
+
|
|
1321
|
+
// Largest.
|
|
1322
|
+
if (largest && momentTypes.length) {
|
|
1323
|
+
momentTypes = momentTypes.slice(0, largest);
|
|
1324
|
+
}
|
|
1325
|
+
|
|
1326
|
+
// Trim Small.
|
|
1327
|
+
if (trimSmall && momentTypes.length > 1) {
|
|
1328
|
+
momentTypes = initial(momentTypes, function (momentType) {
|
|
1329
|
+
// Stop trimming on:
|
|
1330
|
+
// - a type marked for stopTrim
|
|
1331
|
+
// - a type that has a whole value
|
|
1332
|
+
// - the largest momentType
|
|
1333
|
+
return !momentType.wholeValue && !find(stopTrim, momentType.type) && !momentType.isLargest;
|
|
1334
|
+
});
|
|
1335
|
+
}
|
|
1336
|
+
|
|
1337
|
+
// Trim Mid.
|
|
1338
|
+
if (trimMid) {
|
|
1339
|
+
momentTypes = map(momentTypes, function (momentType, index) {
|
|
1340
|
+
if (index > 0 && index < momentTypes.length - 1 && !momentType.wholeValue) {
|
|
1341
|
+
return null;
|
|
1342
|
+
}
|
|
1343
|
+
|
|
1344
|
+
return momentType;
|
|
1345
|
+
});
|
|
1346
|
+
|
|
1347
|
+
momentTypes = compact(momentTypes);
|
|
1348
|
+
}
|
|
1349
|
+
|
|
1350
|
+
// Trim Final.
|
|
1351
|
+
if (trimFinal && momentTypes.length === 1 && !momentTypes[0].wholeValue && !(!trunc && momentTypes[0].isSmallest && momentTypes[0].rawValue < minValue)) {
|
|
1352
|
+
momentTypes = [];
|
|
1353
|
+
}
|
|
1354
|
+
}
|
|
1355
|
+
|
|
1356
|
+
if (returnMomentTypes) {
|
|
1357
|
+
return momentTypes;
|
|
1358
|
+
}
|
|
1359
|
+
|
|
1360
|
+
// Localize and pluralize unit labels.
|
|
1361
|
+
each(tokens, function (token) {
|
|
1362
|
+
var key = momentTokens[token.type];
|
|
1363
|
+
|
|
1364
|
+
var momentType = find(momentTypes, function (momentType) {
|
|
1365
|
+
return momentType.type === token.type;
|
|
1366
|
+
});
|
|
1367
|
+
|
|
1368
|
+
if (!key || !momentType) {
|
|
1369
|
+
return;
|
|
1370
|
+
}
|
|
1371
|
+
|
|
1372
|
+
var values = momentType.formattedValueEn.split(".");
|
|
1373
|
+
|
|
1374
|
+
values[0] = parseInt(values[0], 10);
|
|
1375
|
+
|
|
1376
|
+
if (values[1]) {
|
|
1377
|
+
values[1] = parseFloat("0." + values[1], 10);
|
|
1378
|
+
} else {
|
|
1379
|
+
values[1] = null;
|
|
1380
|
+
}
|
|
1381
|
+
|
|
1382
|
+
var pluralKey = localeData.durationPluralKey(key, values[0], values[1]);
|
|
1383
|
+
|
|
1384
|
+
var labels = durationGetLabels(key, localeData);
|
|
1385
|
+
|
|
1386
|
+
var autoLocalized = false;
|
|
1387
|
+
|
|
1388
|
+
var pluralizedLabels = {};
|
|
1389
|
+
|
|
1390
|
+
// Auto-Localized unit labels.
|
|
1391
|
+
each(localeData._durationLabelTypes, function (labelType) {
|
|
1392
|
+
var label = find(labels, function (label) {
|
|
1393
|
+
return label.type === labelType.type && label.key === pluralKey;
|
|
1394
|
+
});
|
|
1395
|
+
|
|
1396
|
+
if (label) {
|
|
1397
|
+
pluralizedLabels[label.type] = label.label;
|
|
1398
|
+
|
|
1399
|
+
if (stringIncludes(token.text, labelType.string)) {
|
|
1400
|
+
token.text = token.text.replace(labelType.string, label.label);
|
|
1401
|
+
autoLocalized = true;
|
|
1402
|
+
}
|
|
1403
|
+
}
|
|
1404
|
+
});
|
|
1405
|
+
|
|
1406
|
+
// Auto-pluralized unit labels.
|
|
1407
|
+
if (usePlural && !autoLocalized) {
|
|
1408
|
+
labels.sort(durationLabelCompare);
|
|
1409
|
+
|
|
1410
|
+
each(labels, function (label) {
|
|
1411
|
+
if (pluralizedLabels[label.type] === label.label) {
|
|
1412
|
+
if (stringIncludes(token.text, label.label)) {
|
|
1413
|
+
// Stop checking this token if its label is already
|
|
1414
|
+
// correctly pluralized.
|
|
1415
|
+
return false;
|
|
1416
|
+
}
|
|
1417
|
+
|
|
1418
|
+
// Skip this label if it is correct, but not present in
|
|
1419
|
+
// the token's text.
|
|
1420
|
+
return;
|
|
1421
|
+
}
|
|
1422
|
+
|
|
1423
|
+
if (stringIncludes(token.text, label.label)) {
|
|
1424
|
+
// Replece this token's label and stop checking.
|
|
1425
|
+
token.text = token.text.replace(label.label, pluralizedLabels[label.type]);
|
|
1426
|
+
return false;
|
|
1427
|
+
}
|
|
1428
|
+
});
|
|
1429
|
+
}
|
|
1430
|
+
});
|
|
1431
|
+
|
|
1432
|
+
// Build ouptut.
|
|
1433
|
+
tokens = map(tokens, function (token) {
|
|
1434
|
+
if (!token.type) {
|
|
1435
|
+
return token.text;
|
|
1436
|
+
}
|
|
1437
|
+
|
|
1438
|
+
var momentType = find(momentTypes, function (momentType) {
|
|
1439
|
+
return momentType.type === token.type;
|
|
1440
|
+
});
|
|
1441
|
+
|
|
1442
|
+
if (!momentType) {
|
|
1443
|
+
return "";
|
|
1444
|
+
}
|
|
1445
|
+
|
|
1446
|
+
var out = "";
|
|
1447
|
+
|
|
1448
|
+
if (useLeftUnits) {
|
|
1449
|
+
out += token.text;
|
|
1450
|
+
}
|
|
1451
|
+
|
|
1452
|
+
if (isNegative && isMaxValue || !isNegative && isMinValue) {
|
|
1453
|
+
out += "< ";
|
|
1454
|
+
isMaxValue = false;
|
|
1455
|
+
isMinValue = false;
|
|
1456
|
+
}
|
|
1457
|
+
|
|
1458
|
+
if (isNegative && isMinValue || !isNegative && isMaxValue) {
|
|
1459
|
+
out += "> ";
|
|
1460
|
+
isMaxValue = false;
|
|
1461
|
+
isMinValue = false;
|
|
1462
|
+
}
|
|
1463
|
+
|
|
1464
|
+
if (isNegative && (momentType.value > 0 || trim === "" || find(stopTrim, momentType.type) || find(outputTypes, momentType.type))) {
|
|
1465
|
+
out += "-";
|
|
1466
|
+
isNegative = false;
|
|
1467
|
+
}
|
|
1468
|
+
|
|
1469
|
+
if (token.type === "milliseconds" && momentType.formattedValueMS) {
|
|
1470
|
+
out += momentType.formattedValueMS;
|
|
1471
|
+
} else {
|
|
1472
|
+
out += momentType.formattedValue;
|
|
1473
|
+
}
|
|
1474
|
+
|
|
1475
|
+
if (!useLeftUnits) {
|
|
1476
|
+
out += token.text;
|
|
1477
|
+
}
|
|
1478
|
+
|
|
1479
|
+
return out;
|
|
1480
|
+
});
|
|
1481
|
+
|
|
1482
|
+
// Trim leading and trailing comma, space, colon, and dot.
|
|
1483
|
+
return tokens.join("").replace(/(,| |:|\.)*$/, "").replace(/^(,| |:|\.)*/, "");
|
|
1484
|
+
}
|
|
1485
|
+
|
|
1486
|
+
// defaultFormatTemplate
|
|
1487
|
+
function defaultFormatTemplate() {
|
|
1488
|
+
var dur = this.duration;
|
|
1489
|
+
|
|
1490
|
+
var findType = function findType(type) {
|
|
1491
|
+
return dur._data[type];
|
|
1492
|
+
};
|
|
1493
|
+
|
|
1494
|
+
var firstType = find(this.types, findType);
|
|
1495
|
+
|
|
1496
|
+
var lastType = findLast(this.types, findType);
|
|
1497
|
+
|
|
1498
|
+
// Default template strings for each duration dimension type.
|
|
1499
|
+
switch (firstType) {
|
|
1500
|
+
case "milliseconds":
|
|
1501
|
+
return "S __";
|
|
1502
|
+
case "seconds": // Fallthrough.
|
|
1503
|
+
case "minutes":
|
|
1504
|
+
return "*_MS_";
|
|
1505
|
+
case "hours":
|
|
1506
|
+
return "_HMS_";
|
|
1507
|
+
case "days": // Possible Fallthrough.
|
|
1508
|
+
if (firstType === lastType) {
|
|
1509
|
+
return "d __";
|
|
1510
|
+
}
|
|
1511
|
+
case "weeks":
|
|
1512
|
+
if (firstType === lastType) {
|
|
1513
|
+
return "w __";
|
|
1514
|
+
}
|
|
1515
|
+
|
|
1516
|
+
if (this.trim === null) {
|
|
1517
|
+
this.trim = "both";
|
|
1518
|
+
}
|
|
1519
|
+
|
|
1520
|
+
return "w __, d __, h __";
|
|
1521
|
+
case "months": // Possible Fallthrough.
|
|
1522
|
+
if (firstType === lastType) {
|
|
1523
|
+
return "M __";
|
|
1524
|
+
}
|
|
1525
|
+
case "years":
|
|
1526
|
+
if (firstType === lastType) {
|
|
1527
|
+
return "y __";
|
|
1528
|
+
}
|
|
1529
|
+
|
|
1530
|
+
if (this.trim === null) {
|
|
1531
|
+
this.trim = "both";
|
|
1532
|
+
}
|
|
1533
|
+
|
|
1534
|
+
return "y __, M __, d __";
|
|
1535
|
+
default:
|
|
1536
|
+
if (this.trim === null) {
|
|
1537
|
+
this.trim = "both";
|
|
1538
|
+
}
|
|
1539
|
+
|
|
1540
|
+
return "y __, d __, h __, m __, s __";
|
|
1541
|
+
}
|
|
1542
|
+
}
|
|
1543
|
+
|
|
1544
|
+
// init
|
|
1545
|
+
function init(context) {
|
|
1546
|
+
if (!context) {
|
|
1547
|
+
throw "Moment Duration Format init cannot find moment instance.";
|
|
1548
|
+
}
|
|
1549
|
+
|
|
1550
|
+
context.duration.format = durationsFormat;
|
|
1551
|
+
context.duration.fn.format = durationFormat;
|
|
1552
|
+
|
|
1553
|
+
context.duration.fn.format.defaults = {
|
|
1554
|
+
// Many options are defaulted to `null` to distinguish between
|
|
1555
|
+
// 'not set' and 'set to `false`'
|
|
1556
|
+
|
|
1557
|
+
// trim
|
|
1558
|
+
// Can be a string, a delimited list of strings, an array of strings,
|
|
1559
|
+
// or a boolean.
|
|
1560
|
+
// "large" - will trim largest-magnitude zero-value tokens until
|
|
1561
|
+
// finding a token with a value, a token identified as 'stopTrim', or
|
|
1562
|
+
// the final token of the format string.
|
|
1563
|
+
// "small" - will trim smallest-magnitude zero-value tokens until
|
|
1564
|
+
// finding a token with a value, a token identified as 'stopTrim', or
|
|
1565
|
+
// the final token of the format string.
|
|
1566
|
+
// "both" - will execute "large" trim then "small" trim.
|
|
1567
|
+
// "mid" - will trim any zero-value tokens that are not the first or
|
|
1568
|
+
// last tokens. Usually used in conjunction with "large" or "both".
|
|
1569
|
+
// e.g. "large mid" or "both mid".
|
|
1570
|
+
// "final" - will trim the final token if it is zero-value. Use this
|
|
1571
|
+
// option with "large" or "both" to output an empty string when
|
|
1572
|
+
// formatting a zero-value duration. e.g. "large final" or "both final".
|
|
1573
|
+
// "all" - Will trim all zero-value tokens. Shorthand for "both mid final".
|
|
1574
|
+
// "left" - maps to "large" to support plugin's version 1 API.
|
|
1575
|
+
// "right" - maps to "large" to support plugin's version 1 API.
|
|
1576
|
+
// `false` - template tokens are not trimmed.
|
|
1577
|
+
// `true` - treated as "large".
|
|
1578
|
+
// `null` - treated as "large".
|
|
1579
|
+
trim: null,
|
|
1580
|
+
|
|
1581
|
+
// stopTrim
|
|
1582
|
+
// A moment token string, a delimited set of moment token strings,
|
|
1583
|
+
// or an array of moment token strings. Trimming will stop when a token
|
|
1584
|
+
// listed in this option is reached. A "*" character in the format
|
|
1585
|
+
// template string will also mark a moment token as stopTrim.
|
|
1586
|
+
// e.g. "d [days] *h:mm:ss" will always stop trimming at the 'hours' token.
|
|
1587
|
+
stopTrim: null,
|
|
1588
|
+
|
|
1589
|
+
// largest
|
|
1590
|
+
// Set to a positive integer to output only the "n" largest-magnitude
|
|
1591
|
+
// moment tokens that have a value. All lesser-magnitude moment tokens
|
|
1592
|
+
// will be ignored. This option takes effect even if `trim` is set
|
|
1593
|
+
// to `false`.
|
|
1594
|
+
largest: null,
|
|
1595
|
+
|
|
1596
|
+
// maxValue
|
|
1597
|
+
// Use `maxValue` to render generalized output for large duration values,
|
|
1598
|
+
// e.g. `"> 60 days"`. `maxValue` must be a positive integer and is
|
|
1599
|
+
/// applied to the greatest-magnitude moment token in the format template.
|
|
1600
|
+
maxValue: null,
|
|
1601
|
+
|
|
1602
|
+
// minValue
|
|
1603
|
+
// Use `minValue` to render generalized output for small duration values,
|
|
1604
|
+
// e.g. `"< 5 minutes"`. `minValue` must be a positive integer and is
|
|
1605
|
+
// applied to the least-magnitude moment token in the format template.
|
|
1606
|
+
minValue: null,
|
|
1607
|
+
|
|
1608
|
+
// precision
|
|
1609
|
+
// If a positive integer, number of decimal fraction digits to render.
|
|
1610
|
+
// If a negative integer, number of integer place digits to truncate to 0.
|
|
1611
|
+
// If `useSignificantDigits` is set to `true` and `precision` is a positive
|
|
1612
|
+
// integer, sets the maximum number of significant digits used in the
|
|
1613
|
+
// formatted output.
|
|
1614
|
+
precision: 0,
|
|
1615
|
+
|
|
1616
|
+
// trunc
|
|
1617
|
+
// Default behavior rounds final token value. Set to `true` to
|
|
1618
|
+
// truncate final token value, which was the default behavior in
|
|
1619
|
+
// version 1 of this plugin.
|
|
1620
|
+
trunc: false,
|
|
1621
|
+
|
|
1622
|
+
// forceLength
|
|
1623
|
+
// Force first moment token with a value to render at full length
|
|
1624
|
+
// even when template is trimmed and first moment token has length of 1.
|
|
1625
|
+
forceLength: null,
|
|
1626
|
+
|
|
1627
|
+
// userLocale
|
|
1628
|
+
// Formatted numerical output is rendered using `toLocaleString`
|
|
1629
|
+
// and the locale of the user's environment. Set this option to render
|
|
1630
|
+
// numerical output using a different locale. Unit names are rendered
|
|
1631
|
+
// and detected using the locale set in moment.js, which can be different
|
|
1632
|
+
// from the locale of user's environment.
|
|
1633
|
+
userLocale: null,
|
|
1634
|
+
|
|
1635
|
+
// usePlural
|
|
1636
|
+
// Will automatically singularize or pluralize unit names when they
|
|
1637
|
+
// appear in the text associated with each moment token. Standard and
|
|
1638
|
+
// short unit labels are singularized and pluralized, based on locale.
|
|
1639
|
+
// e.g. in english, "1 second" or "1 sec" would be rendered instead
|
|
1640
|
+
// of "1 seconds" or "1 secs". The default pluralization function
|
|
1641
|
+
// renders a plural label for a value with decimal precision.
|
|
1642
|
+
// e.g. "1.0 seconds" is never rendered as "1.0 second".
|
|
1643
|
+
// Label types and pluralization function are configurable in the
|
|
1644
|
+
// localeData extensions.
|
|
1645
|
+
usePlural: true,
|
|
1646
|
+
|
|
1647
|
+
// useLeftUnits
|
|
1648
|
+
// The text to the right of each moment token in a format string
|
|
1649
|
+
// is treated as that token's units for the purposes of trimming,
|
|
1650
|
+
// singularizing, and auto-localizing.
|
|
1651
|
+
// e.g. "h [hours], m [minutes], s [seconds]".
|
|
1652
|
+
// To properly singularize or localize a format string such as
|
|
1653
|
+
// "[hours] h, [minutes] m, [seconds] s", where the units appear
|
|
1654
|
+
// to the left of each moment token, set useLeftUnits to `true`.
|
|
1655
|
+
// This plugin is not tested in the context of rtl text.
|
|
1656
|
+
useLeftUnits: false,
|
|
1657
|
+
|
|
1658
|
+
// useGrouping
|
|
1659
|
+
// Enables locale-based digit grouping in the formatted output. See https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number/toLocaleString
|
|
1660
|
+
useGrouping: true,
|
|
1661
|
+
|
|
1662
|
+
// useSignificantDigits
|
|
1663
|
+
// Treat the `precision` option as the maximum significant digits
|
|
1664
|
+
// to be rendered. Precision must be a positive integer. Significant
|
|
1665
|
+
// digits extend across unit types,
|
|
1666
|
+
// e.g. "6 hours 37.5 minutes" represents 4 significant digits.
|
|
1667
|
+
// Enabling this option causes token length to be ignored. See https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number/toLocaleString
|
|
1668
|
+
useSignificantDigits: false,
|
|
1669
|
+
|
|
1670
|
+
// template
|
|
1671
|
+
// The template string used to format the duration. May be a function
|
|
1672
|
+
// or a string. Template functions are executed with the `this` binding
|
|
1673
|
+
// of the settings object so that template strings may be dynamically
|
|
1674
|
+
// generated based on the duration object (accessible via `this.duration`)
|
|
1675
|
+
// or any of the other settings. Leading and trailing space, comma,
|
|
1676
|
+
// period, and colon characters are trimmed from the resulting string.
|
|
1677
|
+
template: defaultFormatTemplate,
|
|
1678
|
+
|
|
1679
|
+
// useToLocaleString
|
|
1680
|
+
// Set this option to `false` to ignore the `toLocaleString` feature
|
|
1681
|
+
// test and force the use of the `formatNumber` fallback function
|
|
1682
|
+
// included in this plugin.
|
|
1683
|
+
useToLocaleString: true,
|
|
1684
|
+
|
|
1685
|
+
// formatNumber fallback options.
|
|
1686
|
+
// When `toLocaleString` is detected and passes the feature test, the
|
|
1687
|
+
// following options will have no effect: `toLocaleString` will be used
|
|
1688
|
+
// for formatting and the grouping separator, decimal separator, and
|
|
1689
|
+
// integer digit grouping will be determined by the user locale.
|
|
1690
|
+
|
|
1691
|
+
// groupingSeparator
|
|
1692
|
+
// The integer digit grouping separator used when using the fallback
|
|
1693
|
+
// formatNumber function.
|
|
1694
|
+
groupingSeparator: ",",
|
|
1695
|
+
|
|
1696
|
+
// decimalSeparator
|
|
1697
|
+
// The decimal separator used when using the fallback formatNumber
|
|
1698
|
+
// function.
|
|
1699
|
+
decimalSeparator: ".",
|
|
1700
|
+
|
|
1701
|
+
// grouping
|
|
1702
|
+
// The integer digit grouping used when using the fallback formatNumber
|
|
1703
|
+
// function. Must be an array. The default value of `[3]` gives the
|
|
1704
|
+
// standard 3-digit thousand/million/billion digit groupings for the
|
|
1705
|
+
// "en" locale. Setting this option to `[3, 2]` would generate the
|
|
1706
|
+
// thousand/lakh/crore digit groupings used in the "en-IN" locale.
|
|
1707
|
+
grouping: [3]
|
|
1708
|
+
};
|
|
1709
|
+
|
|
1710
|
+
context.updateLocale('en', engLocale);
|
|
1711
|
+
}
|
|
1712
|
+
|
|
1713
|
+
// Run feature tests for `Number#toLocaleString`.
|
|
1714
|
+
var toLocaleStringFormatter = function(number, locale, options) {
|
|
1715
|
+
return number.toLocaleString(locale, options);
|
|
1716
|
+
};
|
|
1717
|
+
|
|
1718
|
+
toLocaleStringWorks = toLocaleStringSupportsLocales() && featureTestFormatter(toLocaleStringFormatter);
|
|
1719
|
+
toLocaleStringRoundingWorks = toLocaleStringWorks && featureTestFormatterRounding(toLocaleStringFormatter);
|
|
1720
|
+
|
|
1721
|
+
// Run feature tests for `Intl.NumberFormat#format`.
|
|
1722
|
+
var intlNumberFormatFormatter = function(number, locale, options) {
|
|
1723
|
+
if (typeof window !== 'undefined' && window && window.Intl && window.Intl.NumberFormat) {
|
|
1724
|
+
return window.Intl.NumberFormat(locale, options).format(number);
|
|
1725
|
+
}
|
|
1726
|
+
};
|
|
1727
|
+
|
|
1728
|
+
intlNumberFormatWorks = featureTestFormatter(intlNumberFormatFormatter);
|
|
1729
|
+
intlNumberFormatRoundingWorks = intlNumberFormatWorks && featureTestFormatterRounding(intlNumberFormatFormatter);
|
|
1730
|
+
|
|
1731
|
+
// Initialize duration format on the global moment instance.
|
|
1732
|
+
init(moment);
|
|
1733
|
+
|
|
1734
|
+
// Return the init function so that duration format can be
|
|
1735
|
+
// initialized on other moment instances.
|
|
1736
|
+
return init;
|
|
1737
|
+
});
|