kibana-sinatra 0.0.7 → 0.0.8
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +1 -1
- data/kibana-sinatra.gemspec +1 -0
- data/lib/kibana/assets/app/app.js +8 -3
- data/lib/kibana/assets/app/components/kbn.js +45 -10
- data/lib/kibana/assets/app/components/{underscore.extended.js → lodash.extended.js} +2 -4
- data/lib/kibana/assets/app/components/require.config.js +5 -6
- data/lib/kibana/assets/app/components/settings.js +1 -1
- data/lib/kibana/assets/app/controllers/dash.js +10 -5
- data/lib/kibana/assets/app/controllers/dashLoader.js +1 -1
- data/lib/kibana/assets/app/controllers/pulldown.js +1 -1
- data/lib/kibana/assets/app/controllers/row.js +1 -1
- data/lib/kibana/assets/app/dashboards/default.json +1 -1
- data/lib/kibana/assets/app/dashboards/logstash.js +4 -4
- data/lib/kibana/assets/app/dashboards/logstash.json +1 -1
- data/lib/kibana/assets/app/directives/addPanel.js +1 -1
- data/lib/kibana/assets/app/directives/arrayJoin.js +1 -1
- data/lib/kibana/assets/app/directives/configModal.js +23 -5
- data/lib/kibana/assets/app/directives/kibanaPanel.js +70 -50
- data/lib/kibana/assets/app/directives/kibanaSimplePanel.js +1 -1
- data/lib/kibana/assets/app/factories/store.js +59 -0
- data/lib/kibana/assets/app/filters/all.js +6 -13
- data/lib/kibana/assets/app/panels/bettermap/module.html +5 -0
- data/lib/kibana/assets/app/panels/bettermap/module.js +1 -1
- data/lib/kibana/assets/app/panels/column/editor.html +1 -1
- data/lib/kibana/assets/app/panels/column/module.js +7 -6
- data/lib/kibana/assets/app/panels/dashcontrol/module.js +1 -1
- data/lib/kibana/assets/app/panels/derivequeries/module.js +1 -1
- data/lib/kibana/assets/app/panels/fields/module.js +1 -1
- data/lib/kibana/assets/app/panels/filtering/module.html +10 -17
- data/lib/kibana/assets/app/panels/filtering/module.js +19 -1
- data/lib/kibana/assets/app/panels/histogram/module.html +4 -4
- data/lib/kibana/assets/app/panels/histogram/module.js +62 -12
- data/lib/kibana/assets/app/panels/histogram/timeSeries.js +6 -3
- data/lib/kibana/assets/app/panels/hits/module.js +1 -1
- data/lib/kibana/assets/app/panels/map/module.js +1 -1
- data/lib/kibana/assets/app/panels/pie/editor.html +1 -1
- data/lib/kibana/assets/app/panels/pie/module.js +1 -1
- data/lib/kibana/assets/app/panels/query/meta.html +1 -1
- data/lib/kibana/assets/app/panels/query/module.html +1 -1
- data/lib/kibana/assets/app/panels/query/module.js +2 -7
- data/lib/kibana/assets/app/panels/query/query.css +9 -7
- data/lib/kibana/assets/app/panels/sparklines/module.js +2 -2
- data/lib/kibana/assets/app/panels/sparklines/timeSeries.js +3 -3
- data/lib/kibana/assets/app/panels/stats/editor.html +36 -0
- data/lib/kibana/assets/app/panels/stats/module.html +15 -0
- data/lib/kibana/assets/app/panels/stats/module.js +199 -0
- data/lib/kibana/assets/app/panels/table/editor.html +23 -27
- data/lib/kibana/assets/app/panels/table/micropanel.html +3 -1
- data/lib/kibana/assets/app/panels/table/module.js +7 -1
- data/lib/kibana/assets/app/panels/terms/editor.html +16 -3
- data/lib/kibana/assets/app/panels/terms/module.html +14 -5
- data/lib/kibana/assets/app/panels/terms/module.js +66 -18
- data/lib/kibana/assets/app/panels/text/module.js +1 -1
- data/lib/kibana/assets/app/panels/timepicker/editor.html +14 -12
- data/lib/kibana/assets/app/panels/timepicker/module.html +3 -8
- data/lib/kibana/assets/app/panels/timepicker/module.js +1 -1
- data/lib/kibana/assets/app/panels/trends/module.js +1 -1
- data/lib/kibana/assets/app/partials/dashLoader.html +10 -10
- data/lib/kibana/assets/app/partials/dashboard.html +35 -44
- data/lib/kibana/assets/app/partials/dasheditor.html +7 -5
- data/lib/kibana/assets/app/partials/paneleditor.html +2 -1
- data/lib/kibana/assets/app/partials/panelgeneral.html +1 -1
- data/lib/kibana/assets/app/partials/roweditor.html +11 -9
- data/lib/kibana/assets/app/services/alertSrv.js +1 -1
- data/lib/kibana/assets/app/services/dashboard.js +27 -14
- data/lib/kibana/assets/app/services/esVersion.js +70 -31
- data/lib/kibana/assets/app/services/fields.js +14 -37
- data/lib/kibana/assets/app/services/filterSrv.js +7 -11
- data/lib/kibana/assets/app/services/kbnIndex.js +24 -15
- data/lib/kibana/assets/app/services/panelMove.js +1 -1
- data/lib/kibana/assets/app/services/querySrv.js +20 -6
- data/lib/kibana/assets/app/services/timer.js +1 -1
- data/lib/kibana/assets/css/bootstrap.dark.min.css +1 -1
- data/lib/kibana/assets/css/bootstrap.light.min.css +1 -1
- data/lib/kibana/assets/img/cubes.png +0 -0
- data/lib/kibana/assets/img/light.png +0 -0
- data/lib/kibana/assets/index.html +3 -2
- data/lib/kibana/assets/vendor/LICENSE.json +90 -0
- data/lib/kibana/assets/vendor/angular/angular-cookies.js +185 -0
- data/lib/kibana/assets/vendor/angular/angular-dragdrop.js +33 -4
- data/lib/kibana/assets/vendor/blob.js +178 -0
- data/lib/kibana/assets/vendor/bootstrap/bootstrap.js +6 -1
- data/lib/kibana/assets/vendor/bootstrap/less/bak/bootswatch.dark.less +555 -0
- data/lib/kibana/assets/vendor/bootstrap/less/bak/variables.dark.less +304 -0
- data/lib/kibana/assets/vendor/bootstrap/less/bootswatch.dark.less +349 -327
- data/lib/kibana/assets/vendor/bootstrap/less/bootswatch.light.less +590 -7
- data/lib/kibana/assets/vendor/bootstrap/less/modals.less +1 -1
- data/lib/kibana/assets/vendor/bootstrap/less/overrides.less +191 -75
- data/lib/kibana/assets/vendor/bootstrap/less/variables.dark.less +96 -97
- data/lib/kibana/assets/vendor/bootstrap/less/variables.light.less +84 -81
- data/lib/kibana/assets/vendor/jquery/jquery.flot.events.js +39 -51
- data/lib/kibana/assets/vendor/lodash.js +6785 -0
- data/lib/kibana/assets/vendor/numeral.js +565 -0
- data/lib/kibana/sinatra/version.rb +1 -1
- data/lib/kibana/views/config.erb +1 -0
- data/test/sinatra_test.rb +2 -2
- metadata +30 -4
- data/lib/kibana/assets/vendor/underscore.js +0 -1246
@@ -0,0 +1,565 @@
|
|
1
|
+
/*!
|
2
|
+
* numeral.js
|
3
|
+
* version : 1.5.2
|
4
|
+
* author : Adam Draper
|
5
|
+
* license : MIT
|
6
|
+
* http://adamwdraper.github.com/Numeral-js/
|
7
|
+
*/
|
8
|
+
|
9
|
+
(function () {
|
10
|
+
|
11
|
+
/************************************
|
12
|
+
Constants
|
13
|
+
************************************/
|
14
|
+
|
15
|
+
var numeral,
|
16
|
+
VERSION = '1.5.2',
|
17
|
+
// internal storage for language config files
|
18
|
+
languages = {},
|
19
|
+
currentLanguage = 'en',
|
20
|
+
zeroFormat = null,
|
21
|
+
defaultFormat = '0,0',
|
22
|
+
// check for nodeJS
|
23
|
+
hasModule = (typeof module !== 'undefined' && module.exports);
|
24
|
+
|
25
|
+
|
26
|
+
/************************************
|
27
|
+
Constructors
|
28
|
+
************************************/
|
29
|
+
|
30
|
+
|
31
|
+
// Numeral prototype object
|
32
|
+
function Numeral (number) {
|
33
|
+
this._value = number;
|
34
|
+
}
|
35
|
+
|
36
|
+
/**
|
37
|
+
* Implementation of toFixed() that treats floats more like decimals
|
38
|
+
*
|
39
|
+
* Fixes binary rounding issues (eg. (0.615).toFixed(2) === '0.61') that present
|
40
|
+
* problems for accounting- and finance-related software.
|
41
|
+
*/
|
42
|
+
function toFixed (value, precision, roundingFunction, optionals) {
|
43
|
+
var power = Math.pow(10, precision),
|
44
|
+
optionalsRegExp,
|
45
|
+
output;
|
46
|
+
|
47
|
+
//roundingFunction = (roundingFunction !== undefined ? roundingFunction : Math.round);
|
48
|
+
// Multiply up by precision, round accurately, then divide and use native toFixed():
|
49
|
+
output = (roundingFunction(value * power) / power).toFixed(precision);
|
50
|
+
|
51
|
+
if (optionals) {
|
52
|
+
optionalsRegExp = new RegExp('0{1,' + optionals + '}$');
|
53
|
+
output = output.replace(optionalsRegExp, '');
|
54
|
+
}
|
55
|
+
|
56
|
+
return output;
|
57
|
+
}
|
58
|
+
|
59
|
+
/************************************
|
60
|
+
Formatting
|
61
|
+
************************************/
|
62
|
+
|
63
|
+
// determine what type of formatting we need to do
|
64
|
+
function formatNumeral (n, format, roundingFunction) {
|
65
|
+
var output;
|
66
|
+
|
67
|
+
// figure out what kind of format we are dealing with
|
68
|
+
if (format.indexOf('$') > -1) { // currency!!!!!
|
69
|
+
output = formatCurrency(n, format, roundingFunction);
|
70
|
+
} else if (format.indexOf('%') > -1) { // percentage
|
71
|
+
output = formatPercentage(n, format, roundingFunction);
|
72
|
+
} else if (format.indexOf(':') > -1) { // time
|
73
|
+
output = formatTime(n, format);
|
74
|
+
} else { // plain ol' numbers or bytes
|
75
|
+
output = formatNumber(n._value, format, roundingFunction);
|
76
|
+
}
|
77
|
+
|
78
|
+
// return string
|
79
|
+
return output;
|
80
|
+
}
|
81
|
+
|
82
|
+
// revert to number
|
83
|
+
function unformatNumeral (n, string) {
|
84
|
+
var stringOriginal = string,
|
85
|
+
thousandRegExp,
|
86
|
+
millionRegExp,
|
87
|
+
billionRegExp,
|
88
|
+
trillionRegExp,
|
89
|
+
suffixes = ['KB', 'MB', 'GB', 'TB', 'PB', 'EB', 'ZB', 'YB'],
|
90
|
+
bytesMultiplier = false,
|
91
|
+
power;
|
92
|
+
|
93
|
+
if (string.indexOf(':') > -1) {
|
94
|
+
n._value = unformatTime(string);
|
95
|
+
} else {
|
96
|
+
if (string === zeroFormat) {
|
97
|
+
n._value = 0;
|
98
|
+
} else {
|
99
|
+
if (languages[currentLanguage].delimiters.decimal !== '.') {
|
100
|
+
string = string.replace(/\./g,'').replace(languages[currentLanguage].delimiters.decimal, '.');
|
101
|
+
}
|
102
|
+
|
103
|
+
// see if abbreviations are there so that we can multiply to the correct number
|
104
|
+
thousandRegExp = new RegExp('[^a-zA-Z]' + languages[currentLanguage].abbreviations.thousand + '(?:\\)|(\\' + languages[currentLanguage].currency.symbol + ')?(?:\\))?)?$');
|
105
|
+
millionRegExp = new RegExp('[^a-zA-Z]' + languages[currentLanguage].abbreviations.million + '(?:\\)|(\\' + languages[currentLanguage].currency.symbol + ')?(?:\\))?)?$');
|
106
|
+
billionRegExp = new RegExp('[^a-zA-Z]' + languages[currentLanguage].abbreviations.billion + '(?:\\)|(\\' + languages[currentLanguage].currency.symbol + ')?(?:\\))?)?$');
|
107
|
+
trillionRegExp = new RegExp('[^a-zA-Z]' + languages[currentLanguage].abbreviations.trillion + '(?:\\)|(\\' + languages[currentLanguage].currency.symbol + ')?(?:\\))?)?$');
|
108
|
+
|
109
|
+
// see if bytes are there so that we can multiply to the correct number
|
110
|
+
for (power = 0; power <= suffixes.length; power++) {
|
111
|
+
bytesMultiplier = (string.indexOf(suffixes[power]) > -1) ? Math.pow(1024, power + 1) : false;
|
112
|
+
|
113
|
+
if (bytesMultiplier) {
|
114
|
+
break;
|
115
|
+
}
|
116
|
+
}
|
117
|
+
|
118
|
+
// do some math to create our number
|
119
|
+
n._value = ((bytesMultiplier) ? bytesMultiplier : 1) * ((stringOriginal.match(thousandRegExp)) ? Math.pow(10, 3) : 1) * ((stringOriginal.match(millionRegExp)) ? Math.pow(10, 6) : 1) * ((stringOriginal.match(billionRegExp)) ? Math.pow(10, 9) : 1) * ((stringOriginal.match(trillionRegExp)) ? Math.pow(10, 12) : 1) * ((string.indexOf('%') > -1) ? 0.01 : 1) * (((string.split('-').length + Math.min(string.split('(').length-1, string.split(')').length-1)) % 2)? 1: -1) * Number(string.replace(/[^0-9\.]+/g, ''));
|
120
|
+
|
121
|
+
// round if we are talking about bytes
|
122
|
+
n._value = (bytesMultiplier) ? Math.ceil(n._value) : n._value;
|
123
|
+
}
|
124
|
+
}
|
125
|
+
return n._value;
|
126
|
+
}
|
127
|
+
|
128
|
+
function formatCurrency (n, format, roundingFunction) {
|
129
|
+
var prependSymbol = format.indexOf('$') <= 1 ? true : false,
|
130
|
+
space = '',
|
131
|
+
output;
|
132
|
+
|
133
|
+
// check for space before or after currency
|
134
|
+
if (format.indexOf(' $') > -1) {
|
135
|
+
space = ' ';
|
136
|
+
format = format.replace(' $', '');
|
137
|
+
} else if (format.indexOf('$ ') > -1) {
|
138
|
+
space = ' ';
|
139
|
+
format = format.replace('$ ', '');
|
140
|
+
} else {
|
141
|
+
format = format.replace('$', '');
|
142
|
+
}
|
143
|
+
|
144
|
+
// format the number
|
145
|
+
output = formatNumber(n._value, format, roundingFunction);
|
146
|
+
|
147
|
+
// position the symbol
|
148
|
+
if (prependSymbol) {
|
149
|
+
if (output.indexOf('(') > -1 || output.indexOf('-') > -1) {
|
150
|
+
output = output.split('');
|
151
|
+
output.splice(1, 0, languages[currentLanguage].currency.symbol + space);
|
152
|
+
output = output.join('');
|
153
|
+
} else {
|
154
|
+
output = languages[currentLanguage].currency.symbol + space + output;
|
155
|
+
}
|
156
|
+
} else {
|
157
|
+
if (output.indexOf(')') > -1) {
|
158
|
+
output = output.split('');
|
159
|
+
output.splice(-1, 0, space + languages[currentLanguage].currency.symbol);
|
160
|
+
output = output.join('');
|
161
|
+
} else {
|
162
|
+
output = output + space + languages[currentLanguage].currency.symbol;
|
163
|
+
}
|
164
|
+
}
|
165
|
+
|
166
|
+
return output;
|
167
|
+
}
|
168
|
+
|
169
|
+
function formatPercentage (n, format, roundingFunction) {
|
170
|
+
var space = '',
|
171
|
+
output,
|
172
|
+
value = n._value * 100;
|
173
|
+
|
174
|
+
// check for space before %
|
175
|
+
if (format.indexOf(' %') > -1) {
|
176
|
+
space = ' ';
|
177
|
+
format = format.replace(' %', '');
|
178
|
+
} else {
|
179
|
+
format = format.replace('%', '');
|
180
|
+
}
|
181
|
+
|
182
|
+
output = formatNumber(value, format, roundingFunction);
|
183
|
+
|
184
|
+
if (output.indexOf(')') > -1 ) {
|
185
|
+
output = output.split('');
|
186
|
+
output.splice(-1, 0, space + '%');
|
187
|
+
output = output.join('');
|
188
|
+
} else {
|
189
|
+
output = output + space + '%';
|
190
|
+
}
|
191
|
+
|
192
|
+
return output;
|
193
|
+
}
|
194
|
+
|
195
|
+
function formatTime (n) {
|
196
|
+
var hours = Math.floor(n._value/60/60),
|
197
|
+
minutes = Math.floor((n._value - (hours * 60 * 60))/60),
|
198
|
+
seconds = Math.round(n._value - (hours * 60 * 60) - (minutes * 60));
|
199
|
+
return hours + ':' + ((minutes < 10) ? '0' + minutes : minutes) + ':' + ((seconds < 10) ? '0' + seconds : seconds);
|
200
|
+
}
|
201
|
+
|
202
|
+
function unformatTime (string) {
|
203
|
+
var timeArray = string.split(':'),
|
204
|
+
seconds = 0;
|
205
|
+
// turn hours and minutes into seconds and add them all up
|
206
|
+
if (timeArray.length === 3) {
|
207
|
+
// hours
|
208
|
+
seconds = seconds + (Number(timeArray[0]) * 60 * 60);
|
209
|
+
// minutes
|
210
|
+
seconds = seconds + (Number(timeArray[1]) * 60);
|
211
|
+
// seconds
|
212
|
+
seconds = seconds + Number(timeArray[2]);
|
213
|
+
} else if (timeArray.length === 2) {
|
214
|
+
// minutes
|
215
|
+
seconds = seconds + (Number(timeArray[0]) * 60);
|
216
|
+
// seconds
|
217
|
+
seconds = seconds + Number(timeArray[1]);
|
218
|
+
}
|
219
|
+
return Number(seconds);
|
220
|
+
}
|
221
|
+
|
222
|
+
function formatNumber (value, format, roundingFunction) {
|
223
|
+
var negP = false,
|
224
|
+
signed = false,
|
225
|
+
optDec = false,
|
226
|
+
abbr = '',
|
227
|
+
bytes = '',
|
228
|
+
ord = '',
|
229
|
+
abs = Math.abs(value),
|
230
|
+
suffixes = ['B', 'KB', 'MB', 'GB', 'TB', 'PB', 'EB', 'ZB', 'YB'],
|
231
|
+
min,
|
232
|
+
max,
|
233
|
+
power,
|
234
|
+
w,
|
235
|
+
precision,
|
236
|
+
thousands,
|
237
|
+
d = '',
|
238
|
+
neg = false;
|
239
|
+
|
240
|
+
// check if number is zero and a custom zero format has been set
|
241
|
+
if (value === 0 && zeroFormat !== null) {
|
242
|
+
return zeroFormat;
|
243
|
+
} else {
|
244
|
+
// see if we should use parentheses for negative number or if we should prefix with a sign
|
245
|
+
// if both are present we default to parentheses
|
246
|
+
if (format.indexOf('(') > -1) {
|
247
|
+
negP = true;
|
248
|
+
format = format.slice(1, -1);
|
249
|
+
} else if (format.indexOf('+') > -1) {
|
250
|
+
signed = true;
|
251
|
+
format = format.replace(/\+/g, '');
|
252
|
+
}
|
253
|
+
|
254
|
+
// see if abbreviation is wanted
|
255
|
+
if (format.indexOf('a') > -1) {
|
256
|
+
// check for space before abbreviation
|
257
|
+
if (format.indexOf(' a') > -1) {
|
258
|
+
abbr = ' ';
|
259
|
+
format = format.replace(' a', '');
|
260
|
+
} else {
|
261
|
+
format = format.replace('a', '');
|
262
|
+
}
|
263
|
+
|
264
|
+
if (abs >= Math.pow(10, 12)) {
|
265
|
+
// trillion
|
266
|
+
abbr = abbr + languages[currentLanguage].abbreviations.trillion;
|
267
|
+
value = value / Math.pow(10, 12);
|
268
|
+
} else if (abs < Math.pow(10, 12) && abs >= Math.pow(10, 9)) {
|
269
|
+
// billion
|
270
|
+
abbr = abbr + languages[currentLanguage].abbreviations.billion;
|
271
|
+
value = value / Math.pow(10, 9);
|
272
|
+
} else if (abs < Math.pow(10, 9) && abs >= Math.pow(10, 6)) {
|
273
|
+
// million
|
274
|
+
abbr = abbr + languages[currentLanguage].abbreviations.million;
|
275
|
+
value = value / Math.pow(10, 6);
|
276
|
+
} else if (abs < Math.pow(10, 6) && abs >= Math.pow(10, 3)) {
|
277
|
+
// thousand
|
278
|
+
abbr = abbr + languages[currentLanguage].abbreviations.thousand;
|
279
|
+
value = value / Math.pow(10, 3);
|
280
|
+
}
|
281
|
+
}
|
282
|
+
|
283
|
+
// see if we are formatting bytes
|
284
|
+
if (format.indexOf('b') > -1) {
|
285
|
+
// check for space before
|
286
|
+
if (format.indexOf(' b') > -1) {
|
287
|
+
bytes = ' ';
|
288
|
+
format = format.replace(' b', '');
|
289
|
+
} else {
|
290
|
+
format = format.replace('b', '');
|
291
|
+
}
|
292
|
+
|
293
|
+
for (power = 0; power <= suffixes.length; power++) {
|
294
|
+
min = Math.pow(1024, power);
|
295
|
+
max = Math.pow(1024, power+1);
|
296
|
+
|
297
|
+
if (value >= min && value < max) {
|
298
|
+
bytes = bytes + suffixes[power];
|
299
|
+
if (min > 0) {
|
300
|
+
value = value / min;
|
301
|
+
}
|
302
|
+
break;
|
303
|
+
}
|
304
|
+
}
|
305
|
+
}
|
306
|
+
|
307
|
+
// see if ordinal is wanted
|
308
|
+
if (format.indexOf('o') > -1) {
|
309
|
+
// check for space before
|
310
|
+
if (format.indexOf(' o') > -1) {
|
311
|
+
ord = ' ';
|
312
|
+
format = format.replace(' o', '');
|
313
|
+
} else {
|
314
|
+
format = format.replace('o', '');
|
315
|
+
}
|
316
|
+
|
317
|
+
ord = ord + languages[currentLanguage].ordinal(value);
|
318
|
+
}
|
319
|
+
|
320
|
+
if (format.indexOf('[.]') > -1) {
|
321
|
+
optDec = true;
|
322
|
+
format = format.replace('[.]', '.');
|
323
|
+
}
|
324
|
+
|
325
|
+
w = value.toString().split('.')[0];
|
326
|
+
precision = format.split('.')[1];
|
327
|
+
thousands = format.indexOf(',');
|
328
|
+
|
329
|
+
if (precision) {
|
330
|
+
if (precision.indexOf('[') > -1) {
|
331
|
+
precision = precision.replace(']', '');
|
332
|
+
precision = precision.split('[');
|
333
|
+
d = toFixed(value, (precision[0].length + precision[1].length), roundingFunction, precision[1].length);
|
334
|
+
} else {
|
335
|
+
d = toFixed(value, precision.length, roundingFunction);
|
336
|
+
}
|
337
|
+
|
338
|
+
w = d.split('.')[0];
|
339
|
+
|
340
|
+
if (d.split('.')[1].length) {
|
341
|
+
d = languages[currentLanguage].delimiters.decimal + d.split('.')[1];
|
342
|
+
} else {
|
343
|
+
d = '';
|
344
|
+
}
|
345
|
+
|
346
|
+
if (optDec && Number(d.slice(1)) === 0) {
|
347
|
+
d = '';
|
348
|
+
}
|
349
|
+
} else {
|
350
|
+
w = toFixed(value, null, roundingFunction);
|
351
|
+
}
|
352
|
+
|
353
|
+
// format number
|
354
|
+
if (w.indexOf('-') > -1) {
|
355
|
+
w = w.slice(1);
|
356
|
+
neg = true;
|
357
|
+
}
|
358
|
+
|
359
|
+
if (thousands > -1) {
|
360
|
+
w = w.toString().replace(/(\d)(?=(\d{3})+(?!\d))/g, '$1' + languages[currentLanguage].delimiters.thousands);
|
361
|
+
}
|
362
|
+
|
363
|
+
if (format.indexOf('.') === 0) {
|
364
|
+
w = '';
|
365
|
+
}
|
366
|
+
|
367
|
+
return ((negP && neg) ? '(' : '') + ((!negP && neg) ? '-' : '') + ((!neg && signed) ? '+' : '') + w + d + ((ord) ? ord : '') + ((abbr) ? abbr : '') + ((bytes) ? bytes : '') + ((negP && neg) ? ')' : '');
|
368
|
+
}
|
369
|
+
}
|
370
|
+
|
371
|
+
/************************************
|
372
|
+
Top Level Functions
|
373
|
+
************************************/
|
374
|
+
|
375
|
+
numeral = function (input) {
|
376
|
+
if (numeral.isNumeral(input)) {
|
377
|
+
input = input.value();
|
378
|
+
} else if (input === 0 || typeof input === 'undefined') {
|
379
|
+
input = 0;
|
380
|
+
} else if (!Number(input)) {
|
381
|
+
input = numeral.fn.unformat(input);
|
382
|
+
}
|
383
|
+
|
384
|
+
return new Numeral(Number(input));
|
385
|
+
};
|
386
|
+
|
387
|
+
// version number
|
388
|
+
numeral.version = VERSION;
|
389
|
+
|
390
|
+
// compare numeral object
|
391
|
+
numeral.isNumeral = function (obj) {
|
392
|
+
return obj instanceof Numeral;
|
393
|
+
};
|
394
|
+
|
395
|
+
// This function will load languages and then set the global language. If
|
396
|
+
// no arguments are passed in, it will simply return the current global
|
397
|
+
// language key.
|
398
|
+
numeral.language = function (key, values) {
|
399
|
+
if (!key) {
|
400
|
+
return currentLanguage;
|
401
|
+
}
|
402
|
+
|
403
|
+
if (key && !values) {
|
404
|
+
if(!languages[key]) {
|
405
|
+
throw new Error('Unknown language : ' + key);
|
406
|
+
}
|
407
|
+
currentLanguage = key;
|
408
|
+
}
|
409
|
+
|
410
|
+
if (values || !languages[key]) {
|
411
|
+
loadLanguage(key, values);
|
412
|
+
}
|
413
|
+
|
414
|
+
return numeral;
|
415
|
+
};
|
416
|
+
|
417
|
+
// This function provides access to the loaded language data. If
|
418
|
+
// no arguments are passed in, it will simply return the current
|
419
|
+
// global language object.
|
420
|
+
numeral.languageData = function (key) {
|
421
|
+
if (!key) {
|
422
|
+
return languages[currentLanguage];
|
423
|
+
}
|
424
|
+
|
425
|
+
if (!languages[key]) {
|
426
|
+
throw new Error('Unknown language : ' + key);
|
427
|
+
}
|
428
|
+
|
429
|
+
return languages[key];
|
430
|
+
};
|
431
|
+
|
432
|
+
numeral.language('en', {
|
433
|
+
delimiters: {
|
434
|
+
thousands: ',',
|
435
|
+
decimal: '.'
|
436
|
+
},
|
437
|
+
abbreviations: {
|
438
|
+
thousand: 'k',
|
439
|
+
million: 'm',
|
440
|
+
billion: 'b',
|
441
|
+
trillion: 't'
|
442
|
+
},
|
443
|
+
ordinal: function (number) {
|
444
|
+
var b = number % 10;
|
445
|
+
return (~~ (number % 100 / 10) === 1) ? 'th' :
|
446
|
+
(b === 1) ? 'st' :
|
447
|
+
(b === 2) ? 'nd' :
|
448
|
+
(b === 3) ? 'rd' : 'th';
|
449
|
+
},
|
450
|
+
currency: {
|
451
|
+
symbol: '$'
|
452
|
+
}
|
453
|
+
});
|
454
|
+
|
455
|
+
numeral.zeroFormat = function (format) {
|
456
|
+
zeroFormat = typeof(format) === 'string' ? format : null;
|
457
|
+
};
|
458
|
+
|
459
|
+
numeral.defaultFormat = function (format) {
|
460
|
+
defaultFormat = typeof(format) === 'string' ? format : '0.0';
|
461
|
+
};
|
462
|
+
|
463
|
+
/************************************
|
464
|
+
Helpers
|
465
|
+
************************************/
|
466
|
+
|
467
|
+
function loadLanguage(key, values) {
|
468
|
+
languages[key] = values;
|
469
|
+
}
|
470
|
+
|
471
|
+
|
472
|
+
/************************************
|
473
|
+
Numeral Prototype
|
474
|
+
************************************/
|
475
|
+
|
476
|
+
|
477
|
+
numeral.fn = Numeral.prototype = {
|
478
|
+
|
479
|
+
clone : function () {
|
480
|
+
return numeral(this);
|
481
|
+
},
|
482
|
+
|
483
|
+
format : function (inputString, roundingFunction) {
|
484
|
+
return formatNumeral(this,
|
485
|
+
inputString ? inputString : defaultFormat,
|
486
|
+
(roundingFunction !== undefined) ? roundingFunction : Math.round
|
487
|
+
);
|
488
|
+
},
|
489
|
+
|
490
|
+
unformat : function (inputString) {
|
491
|
+
if (Object.prototype.toString.call(inputString) === '[object Number]') {
|
492
|
+
return inputString;
|
493
|
+
}
|
494
|
+
return unformatNumeral(this, inputString ? inputString : defaultFormat);
|
495
|
+
},
|
496
|
+
|
497
|
+
value : function () {
|
498
|
+
return this._value;
|
499
|
+
},
|
500
|
+
|
501
|
+
valueOf : function () {
|
502
|
+
return this._value;
|
503
|
+
},
|
504
|
+
|
505
|
+
set : function (value) {
|
506
|
+
this._value = Number(value);
|
507
|
+
return this;
|
508
|
+
},
|
509
|
+
|
510
|
+
add : function (value) {
|
511
|
+
this._value = this._value + Number(value);
|
512
|
+
return this;
|
513
|
+
},
|
514
|
+
|
515
|
+
subtract : function (value) {
|
516
|
+
this._value = this._value - Number(value);
|
517
|
+
return this;
|
518
|
+
},
|
519
|
+
|
520
|
+
multiply : function (value) {
|
521
|
+
this._value = this._value * Number(value);
|
522
|
+
return this;
|
523
|
+
},
|
524
|
+
|
525
|
+
divide : function (value) {
|
526
|
+
this._value = this._value / Number(value);
|
527
|
+
return this;
|
528
|
+
},
|
529
|
+
|
530
|
+
difference : function (value) {
|
531
|
+
var difference = this._value - Number(value);
|
532
|
+
|
533
|
+
if (difference < 0) {
|
534
|
+
difference = -difference;
|
535
|
+
}
|
536
|
+
|
537
|
+
return difference;
|
538
|
+
}
|
539
|
+
|
540
|
+
};
|
541
|
+
|
542
|
+
/************************************
|
543
|
+
Exposing Numeral
|
544
|
+
************************************/
|
545
|
+
|
546
|
+
// CommonJS module is defined
|
547
|
+
if (hasModule) {
|
548
|
+
module.exports = numeral;
|
549
|
+
}
|
550
|
+
|
551
|
+
/*global ender:false */
|
552
|
+
if (typeof ender === 'undefined') {
|
553
|
+
// here, `this` means `window` in the browser, or `global` on the server
|
554
|
+
// add `numeral` as a global object via a string identifier,
|
555
|
+
// for Closure Compiler 'advanced' mode
|
556
|
+
this['numeral'] = numeral;
|
557
|
+
}
|
558
|
+
|
559
|
+
/*global define:false */
|
560
|
+
if (typeof define === 'function' && define.amd) {
|
561
|
+
define([], function () {
|
562
|
+
return numeral;
|
563
|
+
});
|
564
|
+
}
|
565
|
+
}).call(this);
|