@visactor/vutils 0.17.4 → 0.18.0-alpha.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (63) hide show
  1. package/cjs/format/number/formatDecimal.d.ts +2 -0
  2. package/cjs/format/number/formatDecimal.js +18 -0
  3. package/cjs/format/number/formatDecimal.js.map +1 -0
  4. package/cjs/format/number/formatGroup.d.ts +1 -0
  5. package/cjs/format/number/formatGroup.js +17 -0
  6. package/cjs/format/number/formatGroup.js.map +1 -0
  7. package/cjs/format/number/formatPrefixAuto.d.ts +2 -0
  8. package/cjs/format/number/formatPrefixAuto.js +18 -0
  9. package/cjs/format/number/formatPrefixAuto.js.map +1 -0
  10. package/cjs/format/number/formatRounded.d.ts +1 -0
  11. package/cjs/format/number/formatRounded.js +17 -0
  12. package/cjs/format/number/formatRounded.js.map +1 -0
  13. package/cjs/format/number/formatTrim.d.ts +1 -0
  14. package/cjs/format/number/formatTrim.js +25 -0
  15. package/cjs/format/number/formatTrim.js.map +1 -0
  16. package/cjs/format/number/index.d.ts +2 -0
  17. package/cjs/format/number/index.js +21 -0
  18. package/cjs/format/number/index.js.map +1 -0
  19. package/cjs/format/number/number.d.ts +53 -0
  20. package/cjs/format/number/number.js +121 -0
  21. package/cjs/format/number/number.js.map +1 -0
  22. package/cjs/format/number/specifier.d.ts +28 -0
  23. package/cjs/format/number/specifier.js +41 -0
  24. package/cjs/format/number/specifier.js.map +1 -0
  25. package/cjs/format/time.d.ts +79 -0
  26. package/cjs/format/time.js +204 -0
  27. package/cjs/format/time.js.map +1 -0
  28. package/cjs/index.d.ts +2 -0
  29. package/cjs/index.js +2 -1
  30. package/cjs/index.js.map +1 -1
  31. package/dist/index.js +686 -0
  32. package/dist/index.min.js +1 -1
  33. package/es/format/number/formatDecimal.d.ts +2 -0
  34. package/es/format/number/formatDecimal.js +11 -0
  35. package/es/format/number/formatDecimal.js.map +1 -0
  36. package/es/format/number/formatGroup.d.ts +1 -0
  37. package/es/format/number/formatGroup.js +11 -0
  38. package/es/format/number/formatGroup.js.map +1 -0
  39. package/es/format/number/formatPrefixAuto.d.ts +2 -0
  40. package/es/format/number/formatPrefixAuto.js +11 -0
  41. package/es/format/number/formatPrefixAuto.js.map +1 -0
  42. package/es/format/number/formatRounded.d.ts +1 -0
  43. package/es/format/number/formatRounded.js +9 -0
  44. package/es/format/number/formatRounded.js.map +1 -0
  45. package/es/format/number/formatTrim.d.ts +1 -0
  46. package/es/format/number/formatTrim.js +19 -0
  47. package/es/format/number/formatTrim.js.map +1 -0
  48. package/es/format/number/index.d.ts +2 -0
  49. package/es/format/number/index.js +4 -0
  50. package/es/format/number/index.js.map +1 -0
  51. package/es/format/number/number.d.ts +53 -0
  52. package/es/format/number/number.js +125 -0
  53. package/es/format/number/number.js.map +1 -0
  54. package/es/format/number/specifier.d.ts +28 -0
  55. package/es/format/number/specifier.js +34 -0
  56. package/es/format/number/specifier.js.map +1 -0
  57. package/es/format/time.d.ts +79 -0
  58. package/es/format/time.js +196 -0
  59. package/es/format/time.js.map +1 -0
  60. package/es/index.d.ts +2 -0
  61. package/es/index.js +4 -0
  62. package/es/index.js.map +1 -1
  63. package/package.json +3 -3
package/dist/index.js CHANGED
@@ -4784,6 +4784,684 @@
4784
4784
  return { x: lng, y: lat };
4785
4785
  }
4786
4786
 
4787
+ class TimeUtil {
4788
+ static getInstance() {
4789
+ if (!TimeUtil.instance) {
4790
+ TimeUtil.instance = new TimeUtil();
4791
+ }
4792
+ return TimeUtil.instance;
4793
+ }
4794
+ constructor() {
4795
+ this.locale_shortWeekdays = ['Sun', 'Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat'];
4796
+ this.locale_periods = ['AM', 'PM'];
4797
+ this.locale_weekdays = ['Sunday', 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday'];
4798
+ this.locale_shortMonths = ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec'];
4799
+ this.numberRe = /^\s*\d+/;
4800
+ this.pads = { '-': '', _: ' ', '0': '0' };
4801
+ this.requoteRe = /[\\^$*+?|[\]().{}]/g;
4802
+ this.locale_months = [
4803
+ 'January',
4804
+ 'February',
4805
+ 'March',
4806
+ 'April',
4807
+ 'May',
4808
+ 'June',
4809
+ 'July',
4810
+ 'August',
4811
+ 'September',
4812
+ 'October',
4813
+ 'November',
4814
+ 'December'
4815
+ ];
4816
+ this.formatShortWeekday = (d) => {
4817
+ return this.locale_shortWeekdays[d.getDay()];
4818
+ };
4819
+ this.formatWeekday = (d) => {
4820
+ return this.locale_weekdays[d.getDay()];
4821
+ };
4822
+ this.formatShortMonth = (d) => {
4823
+ return this.locale_shortMonths[d.getMonth()];
4824
+ };
4825
+ this.formatMonth = (d) => {
4826
+ return this.locale_months[d.getMonth()];
4827
+ };
4828
+ this.formatDayOfMonth = (d, p) => {
4829
+ return this.pad(d.getDate(), p, 2);
4830
+ };
4831
+ this.formatHour24 = (d, p) => {
4832
+ return this.pad(d.getHours(), p, 2);
4833
+ };
4834
+ this.formatHour12 = (d, p) => {
4835
+ return this.pad(d.getHours() % 12 || 12, p, 2);
4836
+ };
4837
+ this.formatMilliseconds = (d, p) => {
4838
+ return this.pad(d.getMilliseconds(), p, 3);
4839
+ };
4840
+ this.formatMonthNumber = (d, p) => {
4841
+ return this.pad(d.getMonth() + 1, p, 2);
4842
+ };
4843
+ this.formatMinutes = (d, p) => {
4844
+ return this.pad(d.getMinutes(), p, 2);
4845
+ };
4846
+ this.formatPeriod = (d) => {
4847
+ return this.locale_periods[+(d.getHours() >= 12)];
4848
+ };
4849
+ this.formatSeconds = (d, p) => {
4850
+ return this.pad(d.getSeconds(), p, 2);
4851
+ };
4852
+ this.formatFullYear = (d, p) => {
4853
+ return this.pad(d.getFullYear() % 10000, p, 4);
4854
+ };
4855
+ this.formatUTCShortWeekday = (d) => {
4856
+ return this.locale_shortWeekdays[d.getUTCDay()];
4857
+ };
4858
+ this.formatUTCWeekday = (d) => {
4859
+ return this.locale_weekdays[d.getUTCDay()];
4860
+ };
4861
+ this.formatUTCShortMonth = (d) => {
4862
+ return this.locale_shortMonths[d.getUTCMonth()];
4863
+ };
4864
+ this.formatUTCMonth = (d) => {
4865
+ return this.locale_months[d.getUTCMonth()];
4866
+ };
4867
+ this.formatUTCDayOfMonth = (d, p) => {
4868
+ return this.pad(d.getUTCDate(), p, 2);
4869
+ };
4870
+ this.formatUTCHour24 = (d, p) => {
4871
+ return this.pad(d.getUTCHours(), p, 2);
4872
+ };
4873
+ this.formatUTCHour12 = (d, p) => {
4874
+ return this.pad(d.getUTCHours() % 12 || 12, p, 2);
4875
+ };
4876
+ this.formatUTCMilliseconds = (d, p) => {
4877
+ return this.pad(d.getUTCMilliseconds(), p, 3);
4878
+ };
4879
+ this.formatUTCMonthNumber = (d, p) => {
4880
+ return this.pad(d.getUTCMonth() + 1, p, 2);
4881
+ };
4882
+ this.formatUTCMinutes = (d, p) => {
4883
+ return this.pad(d.getUTCMinutes(), p, 2);
4884
+ };
4885
+ this.formatUTCPeriod = (d) => {
4886
+ return this.locale_periods[+(d.getUTCHours() >= 12)];
4887
+ };
4888
+ this.formatUTCSeconds = (d, p) => {
4889
+ return this.pad(d.getUTCSeconds(), p, 2);
4890
+ };
4891
+ this.formatUTCFullYear = (d, p) => {
4892
+ return this.pad(d.getUTCFullYear() % 10000, p, 4);
4893
+ };
4894
+ this.formats = {
4895
+ a: this.formatShortWeekday,
4896
+ A: this.formatWeekday,
4897
+ b: this.formatShortMonth,
4898
+ B: this.formatMonth,
4899
+ d: this.formatDayOfMonth,
4900
+ e: this.formatDayOfMonth,
4901
+ H: this.formatHour24,
4902
+ I: this.formatHour12,
4903
+ L: this.formatMilliseconds,
4904
+ m: this.formatMonthNumber,
4905
+ M: this.formatMinutes,
4906
+ p: this.formatPeriod,
4907
+ S: this.formatSeconds,
4908
+ Y: this.formatFullYear
4909
+ };
4910
+ this.utcFormats = {
4911
+ a: this.formatUTCShortWeekday,
4912
+ A: this.formatUTCWeekday,
4913
+ b: this.formatUTCShortMonth,
4914
+ B: this.formatUTCMonth,
4915
+ d: this.formatUTCDayOfMonth,
4916
+ e: this.formatUTCDayOfMonth,
4917
+ H: this.formatUTCHour24,
4918
+ I: this.formatUTCHour12,
4919
+ L: this.formatUTCMilliseconds,
4920
+ m: this.formatUTCMonthNumber,
4921
+ M: this.formatUTCMinutes,
4922
+ p: this.formatUTCPeriod,
4923
+ S: this.formatUTCSeconds,
4924
+ Y: this.formatUTCFullYear
4925
+ };
4926
+ this.parseShortWeekday = (d, string, i) => {
4927
+ const n = this.shortWeekdayRe.exec(string.slice(i));
4928
+ return n ? ((d.w = this.shortWeekdayLookup.get(n[0].toLowerCase())), i + n[0].length) : -1;
4929
+ };
4930
+ this.parseWeekday = (d, string, i) => {
4931
+ const n = this.weekdayRe.exec(string.slice(i));
4932
+ return n ? ((d.w = this.weekdayLookup.get(n[0].toLowerCase())), i + n[0].length) : -1;
4933
+ };
4934
+ this.parseShortMonth = (d, string, i) => {
4935
+ const n = this.shortMonthRe.exec(string.slice(i));
4936
+ return n ? ((d.m = this.shortMonthLookup.get(n[0].toLowerCase())), i + n[0].length) : -1;
4937
+ };
4938
+ this.parseMonth = (d, string, i) => {
4939
+ const n = this.monthRe.exec(string.slice(i));
4940
+ return n ? ((d.m = this.monthLookup.get(n[0].toLowerCase())), i + n[0].length) : -1;
4941
+ };
4942
+ this.parseDayOfMonth = (d, string, i) => {
4943
+ const n = this.numberRe.exec(string.slice(i, i + 2));
4944
+ return n ? ((d.d = +n[0]), i + n[0].length) : -1;
4945
+ };
4946
+ this.parseHour24 = (d, string, i) => {
4947
+ const n = this.numberRe.exec(string.slice(i, i + 2));
4948
+ return n ? ((d.H = +n[0]), i + n[0].length) : -1;
4949
+ };
4950
+ this.parseMilliseconds = (d, string, i) => {
4951
+ const n = this.numberRe.exec(string.slice(i, i + 3));
4952
+ return n ? ((d.L = +n[0]), i + n[0].length) : -1;
4953
+ };
4954
+ this.parseMonthNumber = (d, string, i) => {
4955
+ const n = this.numberRe.exec(string.slice(i, i + 2));
4956
+ return n ? ((d.m = n - 1), i + n[0].length) : -1;
4957
+ };
4958
+ this.parseMinutes = (d, string, i) => {
4959
+ const n = this.numberRe.exec(string.slice(i, i + 2));
4960
+ return n ? ((d.M = +n[0]), i + n[0].length) : -1;
4961
+ };
4962
+ this.parsePeriod = (d, string, i) => {
4963
+ const n = this.periodRe.exec(string.slice(i));
4964
+ return n ? ((d.p = this.periodLookup.get(n[0].toLowerCase())), i + n[0].length) : -1;
4965
+ };
4966
+ this.parseSeconds = (d, string, i) => {
4967
+ const n = this.numberRe.exec(string.slice(i, i + 2));
4968
+ return n ? ((d.S = +n[0]), i + n[0].length) : -1;
4969
+ };
4970
+ this.parseFullYear = (d, string, i) => {
4971
+ const n = this.numberRe.exec(string.slice(i, i + 4));
4972
+ return n ? ((d.y = +n[0]), i + n[0].length) : -1;
4973
+ };
4974
+ this.parses = {
4975
+ a: this.parseShortWeekday,
4976
+ A: this.parseWeekday,
4977
+ b: this.parseShortMonth,
4978
+ B: this.parseMonth,
4979
+ d: this.parseDayOfMonth,
4980
+ e: this.parseDayOfMonth,
4981
+ H: this.parseHour24,
4982
+ I: this.parseHour24,
4983
+ L: this.parseMilliseconds,
4984
+ m: this.parseMonthNumber,
4985
+ M: this.parseMinutes,
4986
+ p: this.parsePeriod,
4987
+ S: this.parseSeconds,
4988
+ Y: this.parseFullYear
4989
+ };
4990
+ this.timeFormat = (specifier, timeText) => {
4991
+ return this.newFormat(specifier, this.formats)(new Date(this.getFullTimeStamp(timeText)));
4992
+ };
4993
+ this.timeUTCFormat = (specifier, timeText) => {
4994
+ return this.newFormat(specifier, this.utcFormats)(new Date(this.getFullTimeStamp(timeText)));
4995
+ };
4996
+ this.timeParse = (specifier, timeText) => {
4997
+ return this.newParse(specifier, false)(timeText + '');
4998
+ };
4999
+ this.requoteF = this.requote.bind(this);
5000
+ this.periodRe = this.formatRe(this.locale_periods);
5001
+ this.periodLookup = this.formatLookup(this.locale_periods);
5002
+ this.weekdayRe = this.formatRe(this.locale_weekdays);
5003
+ this.weekdayLookup = this.formatLookup(this.locale_weekdays);
5004
+ this.shortWeekdayRe = this.formatRe(this.locale_shortWeekdays);
5005
+ this.shortWeekdayLookup = this.formatLookup(this.locale_shortWeekdays);
5006
+ this.monthRe = this.formatRe(this.locale_months);
5007
+ this.monthLookup = this.formatLookup(this.locale_months);
5008
+ this.shortMonthRe = this.formatRe(this.locale_shortMonths);
5009
+ this.shortMonthLookup = this.formatLookup(this.locale_shortMonths);
5010
+ }
5011
+ requote(s) {
5012
+ return s.replace(this.requoteRe, '\\$&');
5013
+ }
5014
+ localDate(d) {
5015
+ if (0 <= d.y && d.y < 100) {
5016
+ const date = new Date(-1, d.m, d.d, d.H, d.M, d.S, d.L);
5017
+ date.setFullYear(d.y);
5018
+ return date;
5019
+ }
5020
+ return new Date(d.y, d.m, d.d, d.H, d.M, d.S, d.L);
5021
+ }
5022
+ utcDate(d) {
5023
+ if (0 <= d.y && d.y < 100) {
5024
+ const date = new Date(Date.UTC(-1, d.m, d.d, d.H, d.M, d.S, d.L));
5025
+ date.setUTCFullYear(d.y);
5026
+ return date;
5027
+ }
5028
+ return new Date(Date.UTC(d.y, d.m, d.d, d.H, d.M, d.S, d.L));
5029
+ }
5030
+ newDate(y, m, d) {
5031
+ return { y: y, m: m, d: d, H: 0, M: 0, S: 0, L: 0 };
5032
+ }
5033
+ formatRe(names) {
5034
+ return new RegExp('^(?:' + names.map(this.requoteF).join('|') + ')', 'i');
5035
+ }
5036
+ formatLookup(names) {
5037
+ return new Map(names.map((name, i) => [name.toLowerCase(), i]));
5038
+ }
5039
+ pad(value, fill, width) {
5040
+ const sign = value < 0 ? '-' : '';
5041
+ const string = (sign ? -value : value) + '';
5042
+ const length = string.length;
5043
+ return sign + (length < width ? new Array(width - length + 1).join(fill) + string : string);
5044
+ }
5045
+ parseSpecifier(d, specifier, string, j) {
5046
+ let i = 0;
5047
+ const n = specifier.length;
5048
+ const m = string.length;
5049
+ let c;
5050
+ let parse;
5051
+ while (i < n) {
5052
+ if (j >= m) {
5053
+ return -1;
5054
+ }
5055
+ c = specifier.charCodeAt(i++);
5056
+ if (c === 37) {
5057
+ c = specifier.charAt(i++);
5058
+ parse = this.parses[c in this.pads ? specifier.charAt(i++) : c];
5059
+ if (!parse || (j = parse(d, string, j)) < 0) {
5060
+ return -1;
5061
+ }
5062
+ }
5063
+ else if (c !== string.charCodeAt(j++)) {
5064
+ return -1;
5065
+ }
5066
+ }
5067
+ return j;
5068
+ }
5069
+ newParse(specifier, Z) {
5070
+ const that = this;
5071
+ return function (string) {
5072
+ const d = that.newDate(1900, undefined, 1);
5073
+ const i = that.parseSpecifier(d, specifier, (string += ''), 0);
5074
+ if (i !== string.length) {
5075
+ return null;
5076
+ }
5077
+ if ('Q' in d) {
5078
+ return new Date(d.Q);
5079
+ }
5080
+ if ('s' in d) {
5081
+ return new Date(d.s * 1000 + ('L' in d ? d.L : 0));
5082
+ }
5083
+ if (Z && !('Z' in d)) {
5084
+ d.Z = 0;
5085
+ }
5086
+ if ('p' in d) {
5087
+ d.H = (d.H % 12) + d.p * 12;
5088
+ }
5089
+ if (d.m === undefined) {
5090
+ d.m = 'q' in d ? d.q : 0;
5091
+ }
5092
+ if ('Z' in d) {
5093
+ d.H += (d.Z / 100) | 0;
5094
+ d.M += d.Z % 100;
5095
+ return that.utcDate(d);
5096
+ }
5097
+ return that.localDate(d);
5098
+ };
5099
+ }
5100
+ newFormat(specifier, formats) {
5101
+ const that = this;
5102
+ return function (date) {
5103
+ const string = [];
5104
+ let i = -1;
5105
+ let j = 0;
5106
+ const n = specifier.length;
5107
+ let c;
5108
+ let pad;
5109
+ let format;
5110
+ if (!(date instanceof Date)) {
5111
+ date = new Date(+date);
5112
+ }
5113
+ while (++i < n) {
5114
+ if (specifier.charCodeAt(i) === 37) {
5115
+ string.push(specifier.slice(j, i));
5116
+ if ((pad = that.pads[(c = specifier.charAt(++i))])) {
5117
+ c = specifier.charAt(++i);
5118
+ }
5119
+ else {
5120
+ pad = c === 'e' ? ' ' : '0';
5121
+ }
5122
+ format = formats[c];
5123
+ c = format(date, pad);
5124
+ string.push(c);
5125
+ j = i + 1;
5126
+ }
5127
+ }
5128
+ string.push(specifier.slice(j, i));
5129
+ return string.join('');
5130
+ };
5131
+ }
5132
+ getFullTimeStamp(timeText) {
5133
+ const timeOriStamp = parseInt(timeText + '', 10);
5134
+ return String(timeOriStamp).length === 10 ? timeOriStamp * 1000 : timeOriStamp;
5135
+ }
5136
+ }
5137
+
5138
+ function formatDecimal(x) {
5139
+ return Math.abs((x = Math.round(x))) >= 1e21 ? x.toLocaleString('en').replace(/,/g, '') : x.toString(10);
5140
+ }
5141
+ function formatDecimalParts(x, p) {
5142
+ const _x = p ? x.toExponential(p - 1) : x.toExponential();
5143
+ const i = _x.indexOf('e');
5144
+ if (i < 0) {
5145
+ return null;
5146
+ }
5147
+ const coefficient = _x.slice(0, i);
5148
+ return [coefficient.length > 1 ? coefficient[0] + coefficient.slice(2) : coefficient, +_x.slice(i + 1)];
5149
+ }
5150
+
5151
+ function formatGroup(grouping, thousands) {
5152
+ return function (value, width) {
5153
+ let i = value.length;
5154
+ const t = [];
5155
+ let j = 0;
5156
+ let g = grouping[0];
5157
+ let length = 0;
5158
+ while (i > 0 && g > 0) {
5159
+ if (length + g + 1 > width) {
5160
+ g = Math.max(1, width - length);
5161
+ }
5162
+ t.push(value.substring((i -= g), i + g));
5163
+ if ((length += g + 1) > width) {
5164
+ break;
5165
+ }
5166
+ g = grouping[(j = (j + 1) % grouping.length)];
5167
+ }
5168
+ return t.reverse().join(thousands);
5169
+ };
5170
+ }
5171
+
5172
+ let prefixExponent;
5173
+ function formatPrefixAuto(x, p) {
5174
+ const d = formatDecimalParts(x, p);
5175
+ if (!d) {
5176
+ return x + '';
5177
+ }
5178
+ const coefficient = d[0];
5179
+ const exponent = d[1];
5180
+ const i = exponent - (prefixExponent = Math.max(-8, Math.min(8, Math.floor(exponent / 3))) * 3) + 1;
5181
+ const n = coefficient.length;
5182
+ return i === n
5183
+ ? coefficient
5184
+ : i > n
5185
+ ? coefficient + new Array(i - n + 1).join('0')
5186
+ : i > 0
5187
+ ? coefficient.slice(0, i) + '.' + coefficient.slice(i)
5188
+ : '0.' + new Array(1 - i).join('0') + formatDecimalParts(x, Math.max(0, p + i - 1))[0];
5189
+ }
5190
+
5191
+ function formatRounded(x, p) {
5192
+ const d = formatDecimalParts(x, p);
5193
+ if (!d) {
5194
+ return x + '';
5195
+ }
5196
+ const coefficient = d[0];
5197
+ const exponent = d[1];
5198
+ return exponent < 0
5199
+ ? '0.' + new Array(-exponent).join('0') + coefficient
5200
+ : coefficient.length > exponent + 1
5201
+ ? coefficient.slice(0, exponent + 1) + '.' + coefficient.slice(exponent + 1)
5202
+ : coefficient + new Array(exponent - coefficient.length + 2).join('0');
5203
+ }
5204
+
5205
+ function formatTrim(s) {
5206
+ const n = s.length;
5207
+ let i0 = -1;
5208
+ let i1;
5209
+ out: for (let i = 1; i < n; ++i) {
5210
+ switch (s[i]) {
5211
+ case '.':
5212
+ i0 = i1 = i;
5213
+ break;
5214
+ case '0':
5215
+ if (i0 === 0) {
5216
+ i0 = i;
5217
+ }
5218
+ i1 = i;
5219
+ break;
5220
+ default:
5221
+ if (!+s[i]) {
5222
+ break out;
5223
+ }
5224
+ if (i0 > 0) {
5225
+ i0 = 0;
5226
+ }
5227
+ break;
5228
+ }
5229
+ }
5230
+ return i0 > 0 ? s.slice(0, i0) + s.slice(i1 + 1) : s;
5231
+ }
5232
+
5233
+ class FormatSpecifier {
5234
+ constructor(specifier = {}) {
5235
+ this.fill = specifier.fill === undefined ? ' ' : specifier.fill + '';
5236
+ this.align = specifier.align === undefined ? '>' : specifier.align + '';
5237
+ this.sign = specifier.sign === undefined ? '-' : specifier.sign + '';
5238
+ this.symbol = specifier.symbol === undefined ? '' : specifier.symbol + '';
5239
+ this.zero = !!specifier.zero;
5240
+ this.width = specifier.width === undefined ? undefined : +specifier.width;
5241
+ this.comma = !!specifier.comma;
5242
+ this.precision = specifier.precision === undefined ? undefined : +specifier.precision;
5243
+ this.trim = !!specifier.trim;
5244
+ this.type = specifier.type === undefined ? '' : specifier.type + '';
5245
+ }
5246
+ toString() {
5247
+ return (this.fill +
5248
+ this.align +
5249
+ this.sign +
5250
+ this.symbol +
5251
+ (this.zero ? '0' : '') +
5252
+ (this.width === undefined ? '' : Math.max(1, this.width | 0)) +
5253
+ (this.comma ? ',' : '') +
5254
+ (this.precision === undefined ? '' : '.' + Math.max(0, this.precision | 0)) +
5255
+ (this.trim ? '~' : '') +
5256
+ this.type);
5257
+ }
5258
+ }
5259
+ const numberSpecifierReg = /^(?:(.)?([<>=^]))?([+\-( ])?([$#])?(0)?(\d+)?(,)?(\.\d+)?(~)?([a-z%])?$/i;
5260
+ function formatSpecifier(specifier) {
5261
+ let match;
5262
+ if (!(match = numberSpecifierReg.exec(specifier))) {
5263
+ Logger.getInstance().error('invalid format: ' + specifier);
5264
+ return;
5265
+ }
5266
+ return new FormatSpecifier({
5267
+ fill: match[1],
5268
+ align: match[2],
5269
+ sign: match[3],
5270
+ symbol: match[4],
5271
+ zero: match[5],
5272
+ width: match[6],
5273
+ comma: match[7],
5274
+ precision: match[8] && match[8].slice(1),
5275
+ trim: match[9],
5276
+ type: match[10]
5277
+ });
5278
+ }
5279
+
5280
+ const prefixes = ['y', 'z', 'a', 'f', 'p', 'n', 'µ', 'm', '', 'k', 'M', 'G', 'T', 'P', 'E', 'Z', 'Y'];
5281
+ class NumberUtil {
5282
+ constructor() {
5283
+ this.locale = {
5284
+ thousands: ',',
5285
+ grouping: [3],
5286
+ currency: ['$', '']
5287
+ };
5288
+ this.group = this.locale.grouping === undefined || this.locale.thousands === undefined
5289
+ ? (group) => group
5290
+ : formatGroup([...this.locale.grouping].map(Number), `${this.locale.thousands}`);
5291
+ this.currencyPrefix = this.locale.currency === undefined ? '' : this.locale.currency[0] + '';
5292
+ this.currencySuffix = this.locale.currency === undefined ? '' : this.locale.currency[1] + '';
5293
+ this.decimal = this.locale.decimal === undefined ? '.' : this.locale.decimal + '';
5294
+ this.numerals = this.locale.numerals === undefined
5295
+ ? (numerals) => numerals
5296
+ : formatNumerals([...this.locale.numerals].map(String));
5297
+ this.percent = this.locale.percent === undefined ? '%' : this.locale.percent + '';
5298
+ this.minus = this.locale.minus === undefined ? '−' : this.locale.minus + '';
5299
+ this.nan = this.locale.nan === undefined ? 'NaN' : this.locale.nan + '';
5300
+ this.formatter = (specifier) => {
5301
+ return this.newFormat(specifier);
5302
+ };
5303
+ this.format = (specifier, value) => {
5304
+ return this.formatter(specifier)(value);
5305
+ };
5306
+ this.formatPrefix = (specifier, value) => {
5307
+ return this._formatPrefix(specifier, value);
5308
+ };
5309
+ }
5310
+ static getInstance() {
5311
+ if (!NumberUtil.instance) {
5312
+ NumberUtil.instance = new NumberUtil();
5313
+ }
5314
+ return NumberUtil.instance;
5315
+ }
5316
+ newFormat(specifier) {
5317
+ const specifierIns = formatSpecifier(specifier);
5318
+ let fill = specifierIns.fill;
5319
+ let align = specifierIns.align;
5320
+ const sign = specifierIns.sign;
5321
+ const symbol = specifierIns.symbol;
5322
+ let zero = specifierIns.zero;
5323
+ const width = specifierIns.width;
5324
+ let comma = specifierIns.comma;
5325
+ let precision = specifierIns.precision;
5326
+ let trim = specifierIns.trim;
5327
+ let type = specifierIns.type;
5328
+ if (type === 'n') {
5329
+ (comma = true), (type = 'g');
5330
+ }
5331
+ else if (!formatTypes[type]) {
5332
+ precision === undefined && (precision = 12), (trim = true), (type = 'g');
5333
+ }
5334
+ if (zero || (fill === '0' && align === '=')) {
5335
+ (zero = true), (fill = '0'), (align = '=');
5336
+ }
5337
+ const prefix = symbol === '$' ? this.currencyPrefix : symbol === '#' && /[boxX]/.test(type) ? '0' + type.toLowerCase() : '';
5338
+ const suffix = symbol === '$' ? this.currencySuffix : /[%p]/.test(type) ? this.percent : '';
5339
+ const formatType = formatTypes[type];
5340
+ const maybeSuffix = /[defgprstz%]/.test(type);
5341
+ precision =
5342
+ precision === undefined
5343
+ ? 6
5344
+ : /[gprs]/.test(type)
5345
+ ? Math.max(1, Math.min(21, precision))
5346
+ : Math.max(0, Math.min(20, precision));
5347
+ const { nan, minus, decimal, group, numerals } = this;
5348
+ function format(value) {
5349
+ let valuePrefix = prefix;
5350
+ let valueSuffix = suffix;
5351
+ let i;
5352
+ let n;
5353
+ let c;
5354
+ let _value = value;
5355
+ if (type === 'c') {
5356
+ valueSuffix = formatType(_value) + valueSuffix;
5357
+ _value = '';
5358
+ }
5359
+ else {
5360
+ _value = +_value;
5361
+ let valueNegative = _value < 0 || 1 / _value < 0;
5362
+ _value = isNaN(_value) ? nan : formatType(Math.abs(_value), precision);
5363
+ if (trim) {
5364
+ _value = formatTrim(_value);
5365
+ }
5366
+ if (valueNegative && +_value === 0 && sign !== '+') {
5367
+ valueNegative = false;
5368
+ }
5369
+ valuePrefix =
5370
+ (valueNegative ? (sign === '(' ? sign : minus) : sign === '-' || sign === '(' ? '' : sign) + valuePrefix;
5371
+ valueSuffix =
5372
+ (type === 's' ? prefixes[8 + prefixExponent / 3] : '') +
5373
+ valueSuffix +
5374
+ (valueNegative && sign === '(' ? ')' : '');
5375
+ if (maybeSuffix) {
5376
+ (i = -1), (n = _value.length);
5377
+ while (++i < n) {
5378
+ if (((c = _value.charCodeAt(i)), 48 > c || c > 57)) {
5379
+ valueSuffix = (c === 46 ? decimal + _value.slice(i + 1) : _value.slice(i)) + valueSuffix;
5380
+ _value = _value.slice(0, i);
5381
+ break;
5382
+ }
5383
+ }
5384
+ }
5385
+ }
5386
+ if (comma && !zero) {
5387
+ _value = group(_value, Infinity);
5388
+ }
5389
+ let length = valuePrefix.length + _value.length + valueSuffix.length;
5390
+ let padding = length < width ? new Array(width - length + 1).join(fill) : '';
5391
+ if (comma && zero) {
5392
+ _value = group(padding + _value, padding.length ? width - valueSuffix.length : Infinity);
5393
+ padding = '';
5394
+ }
5395
+ switch (align) {
5396
+ case '<':
5397
+ _value = valuePrefix + _value + valueSuffix + padding;
5398
+ break;
5399
+ case '=':
5400
+ _value = valuePrefix + padding + _value + valueSuffix;
5401
+ break;
5402
+ case '^':
5403
+ _value =
5404
+ padding.slice(0, (length = padding.length >> 1)) +
5405
+ valuePrefix +
5406
+ _value +
5407
+ valueSuffix +
5408
+ padding.slice(length);
5409
+ break;
5410
+ default:
5411
+ _value = padding + valuePrefix + _value + valueSuffix;
5412
+ break;
5413
+ }
5414
+ return numerals(_value);
5415
+ }
5416
+ format.toString = function () {
5417
+ return specifier + '';
5418
+ };
5419
+ return format;
5420
+ }
5421
+ _formatPrefix(specifier, value) {
5422
+ const _specifier = formatSpecifier(specifier);
5423
+ _specifier.type = 'f';
5424
+ const f = this.newFormat(_specifier.toString());
5425
+ const e = Math.max(-8, Math.min(8, Math.floor(exponent(value) / 3))) * 3;
5426
+ const k = Math.pow(10, -e);
5427
+ const prefix = prefixes[8 + e / 3];
5428
+ return function (value) {
5429
+ return f(k * value) + prefix;
5430
+ };
5431
+ }
5432
+ }
5433
+ const formatTypes = {
5434
+ '%': (x, p) => (x * 100).toFixed(p),
5435
+ b: (x) => Math.round(x).toString(2),
5436
+ c: (x) => x + '',
5437
+ d: formatDecimal,
5438
+ f: (x, p) => x.toFixed(p),
5439
+ e: (x, p) => x.toExponential(p),
5440
+ g: (x, p) => x.toPrecision(p),
5441
+ o: (x) => Math.round(x).toString(8),
5442
+ p: (x, p) => formatRounded(x * 100, p),
5443
+ r: formatRounded,
5444
+ s: formatPrefixAuto,
5445
+ X: (x) => Math.round(x).toString(16).toUpperCase(),
5446
+ x: (x) => Math.round(x).toString(16),
5447
+ t: (x, p) => {
5448
+ if (Number.isInteger(x)) {
5449
+ return x.toFixed(2);
5450
+ }
5451
+ return Math.floor(x * Math.pow(10, p)) / Math.pow(10, p) + '';
5452
+ },
5453
+ z: (x, p) => (x % 1 === 0 ? x + '' : x.toFixed(p))
5454
+ };
5455
+ function exponent(x) {
5456
+ const _x = formatDecimalParts(Math.abs(x));
5457
+ return _x ? _x[1] : NaN;
5458
+ }
5459
+ function formatNumerals(numerals) {
5460
+ return function (value) {
5461
+ return value.replace(/[0-9]/g, (i) => numerals[+i]);
5462
+ };
5463
+ }
5464
+
4787
5465
  exports.AABBBounds = AABBBounds;
4788
5466
  exports.Bounds = Bounds;
4789
5467
  exports.Color = Color;
@@ -4791,6 +5469,7 @@
4791
5469
  exports.DAY = DAY;
4792
5470
  exports.DEFAULT_COLORS = DEFAULT_COLORS;
4793
5471
  exports.EventEmitter = index$1;
5472
+ exports.FormatSpecifier = FormatSpecifier;
4794
5473
  exports.GraphicUtil = GraphicUtil;
4795
5474
  exports.HOUR = HOUR;
4796
5475
  exports.HashTable = HashTable;
@@ -4802,6 +5481,7 @@
4802
5481
  exports.Matrix = Matrix;
4803
5482
  exports.NEWTON_ITERATIONS = NEWTON_ITERATIONS;
4804
5483
  exports.NEWTON_MIN_SLOPE = NEWTON_MIN_SLOPE;
5484
+ exports.NumberUtil = NumberUtil;
4805
5485
  exports.OBBBounds = OBBBounds;
4806
5486
  exports.Point = Point;
4807
5487
  exports.PointService = PointService;
@@ -4811,6 +5491,7 @@
4811
5491
  exports.SUBDIVISION_MAX_ITERATIONS = SUBDIVISION_MAX_ITERATIONS;
4812
5492
  exports.SUBDIVISION_PRECISION = SUBDIVISION_PRECISION;
4813
5493
  exports.TextMeasure = TextMeasure;
5494
+ exports.TimeUtil = TimeUtil;
4814
5495
  exports.YEAR = YEAR;
4815
5496
  exports.abs = abs;
4816
5497
  exports.acos = acos;
@@ -4846,8 +5527,12 @@
4846
5527
  exports.deviation = deviation;
4847
5528
  exports.eastAsianCharacterInfo = eastAsianCharacterInfo;
4848
5529
  exports.epsilon = epsilon;
5530
+ exports.exponent = exponent;
4849
5531
  exports.fixPrecision = fixPrecision;
4850
5532
  exports.flattenArray = flattenArray;
5533
+ exports.formatNumerals = formatNumerals;
5534
+ exports.formatSpecifier = formatSpecifier;
5535
+ exports.formatTypes = formatTypes;
4851
5536
  exports.fullYearGetterName = fullYearGetterName;
4852
5537
  exports.fullYearSetterName = fullYearSetterName;
4853
5538
  exports.fuzzyEqualNumber = fuzzyEqualNumber;
@@ -4954,6 +5639,7 @@
4954
5639
  exports.monthSetterName = monthSetterName;
4955
5640
  exports.normalTransform = normalTransform;
4956
5641
  exports.normalizePadding = normalizePadding;
5642
+ exports.numberSpecifierReg = numberSpecifierReg;
4957
5643
  exports.pad = pad;
4958
5644
  exports.parseUint8ToImageData = parseUint8ToImageData;
4959
5645
  exports.pi = pi;