PageSourceSearch

https://app.flourish.studio/interpreter_worker.js

js flourish.studio collected 2026-10-01 06:28:48 UTC 69,525 bytes, 2,182 lines download raw bytes

vendor: 8,023 bytes, lines 1-268
1(function () {
2  'use strict';
3
4  var t0 = new Date,
5      t1 = new Date;
6
7  function newInterval(floori, offseti, count, field) {
8
9    function interval(date) {
10      return floori(date = arguments.length === 0 ? new Date : new Date(+date)), date;
11    }
12
13    interval.floor = function(date) {
14      return floori(date = new Date(+date)), date;
15    };
16
17    interval.ceil = function(date) {
18      return floori(date = new Date(date - 1)), offseti(date, 1), floori(date), date;
19    };
20
21    interval.round = function(date) {
22      var d0 = interval(date),
23          d1 = interval.ceil(date);
24      return date - d0 < d1 - date ? d0 : d1;
25    };
26
27    interval.offset = function(date, step) {
28      return offseti(date = new Date(+date), step == null ? 1 : Math.floor(step)), date;
29    };
30
31    interval.range = function(start, stop, step) {
32      var range = [], previous;
33      start = interval.ceil(start);
34      step = step == null ? 1 : Math.floor(step);
35      if (!(start < stop) || !(step > 0)) return range; // also handles Invalid Date
36      do range.push(previous = new Date(+start)), offseti(start, step), floori(start);
37      while (previous < start && start < stop);
38      return range;
39    };
40
41    interval.filter = function(test) {
42      return newInterval(function(date) {
43        if (date >= date) while (floori(date), !test(date)) date.setTime(date - 1);
44      }, function(date, step) {
45        if (date >= date) {
46          if (step < 0) while (++step <= 0) {
47            while (offseti(date, -1), !test(date)) {} // eslint-disable-line no-empty
48          } else while (--step >= 0) {
49            while (offseti(date, +1), !test(date)) {} // eslint-disable-line no-empty
50          }
51        }
52      });
53    };
54
55    if (count) {
56      interval.count = function(start, end) {
57        t0.setTime(+start), t1.setTime(+end);
58        floori(t0), floori(t1);
59        return Math.floor(count(t0, t1));
60      };
61
62      interval.every = function(step) {
63        step = Math.floor(step);
64        return !isFinite(step) || !(step > 0) ? null
65            : !(step > 1) ? interval
66            : interval.filter(field
67                ? function(d) { return field(d) % step === 0; }
68                : function(d) { return interval.count(0, d) % step === 0; });
69      };
70    }
71
72    return interval;
73  }
74
75  var durationMinute = 6e4;
76  var durationDay = 864e5;
77  var durationWeek = 6048e5;
78
79  var day = newInterval(function(date) {
80    date.setHours(0, 0, 0, 0);
81  }, function(date, step) {
82    date.setDate(date.getDate() + step);
83  }, function(start, end) {
84    return (end - start - (end.getTimezoneOffset() - start.getTimezoneOffset()) * durationMinute) / durationDay;
85  }, function(date) {
86    return date.getDate() - 1;
87  });
88
89  var timeDay = day;
90  day.range;
91
92  function weekday(i) {
93    return newInterval(function(date) {
94      date.setDate(date.getDate() - (date.getDay() + 7 - i) % 7);
95      date.setHours(0, 0, 0, 0);
96    }, function(date, step) {
97      date.setDate(date.getDate() + step * 7);
98    }, function(start, end) {
99      return (end - start - (end.getTimezoneOffset() - start.getTimezoneOffset()) * durationMinute) / durationWeek;
100    });
101  }
102
103  var sunday = weekday(0);
104  var monday = weekday(1);
105  var tuesday = weekday(2);
106  var wednesday = weekday(3);
107  var thursday = weekday(4);
108  var friday = weekday(5);
109  var saturday = weekday(6);
110
111  sunday.range;
112  monday.range;
113  tuesday.range;
114  wednesday.range;
115  thursday.range;
116  friday.range;
117  saturday.range;
118
119  var year = newInterval(function(date) {
120    date.setMonth(0, 1);
121    date.setHours(0, 0, 0, 0);
122  }, function(date, step) {
123    date.setFullYear(date.getFullYear() + step);
124  }, function(start, end) {
125    return end.getFullYear() - start.getFullYear();
126  }, function(date) {
127    return date.getFullYear();
128  });
129
130  // An optimized implementation for this simple case.
131  year.every = function(k) {
132    return !isFinite(k = Math.floor(k)) || !(k > 0) ? null : newInterval(function(date) {
133      date.setFullYear(Math.floor(date.getFullYear() / k) * k);
134      date.setMonth(0, 1);
135      date.setHours(0, 0, 0, 0);
136    }, function(date, step) {
137      date.setFullYear(date.getFullYear() + step * k);
138    });
139  };
140
141  var timeYear = year;
142  year.range;
143
144  var utcDay = newInterval(function(date) {
145    date.setUTCHours(0, 0, 0, 0);
146  }, function(date, step) {
147    date.setUTCDate(date.getUTCDate() + step);
148  }, function(start, end) {
149    return (end - start) / durationDay;
150  }, function(date) {
151    return date.getUTCDate() - 1;
152  });
153
154  var utcDay$1 = utcDay;
155  utcDay.range;
156
157  function utcWeekday(i) {
158    return newInterval(function(date) {
159      date.setUTCDate(date.getUTCDate() - (date.getUTCDay() + 7 - i) % 7);
160      date.setUTCHours(0, 0, 0, 0);
161    }, function(date, step) {
162      date.setUTCDate(date.getUTCDate() + step * 7);
163    }, function(start, end) {
164      return (end - start) / durationWeek;
165    });
166  }
167
168  var utcSunday = utcWeekday(0);
169  var utcMonday = utcWeekday(1);
170  var utcTuesday = utcWeekday(2);
171  var utcWednesday = utcWeekday(3);
172  var utcThursday = utcWeekday(4);
173  var utcFriday = utcWeekday(5);
174  var utcSaturday = utcWeekday(6);
175
176  utcSunday.range;
177  utcMonday.range;
178  utcTuesday.range;
179  utcWednesday.range;
180  utcThursday.range;
181  utcFriday.range;
182  utcSaturday.range;
183
184  var utcYear = newInterval(function(date) {
185    date.setUTCMonth(0, 1);
186    date.setUTCHours(0, 0, 0, 0);
187  }, function(date, step) {
188    date.setUTCFullYear(date.getUTCFullYear() + step);
189  }, function(start, end) {
190    return end.getUTCFullYear() - start.getUTCFullYear();
191  }, function(date) {
192    return date.getUTCFullYear();
193  });
194
195  // An optimized implementation for this simple case.
196  utcYear.every = function(k) {
197    return !isFinite(k = Math.floor(k)) || !(k > 0) ? null : newInterval(function(date) {
198      date.setUTCFullYear(Math.floor(date.getUTCFullYear() / k) * k);
199      date.setUTCMonth(0, 1);
200      date.setUTCHours(0, 0, 0, 0);
201    }, function(date, step) {
202      date.setUTCFullYear(date.getUTCFullYear() + step * k);
203    });
204  };
205
206  var utcYear$1 = utcYear;
207  utcYear.range;
208
209  function localDate(d) {
210    if (0 <= d.y && d.y < 100) {
211      var date = new Date(-1, d.m, d.d, d.H, d.M, d.S, d.L);
212      date.setFullYear(d.y);
213      return date;
214    }
215    return new Date(d.y, d.m, d.d, d.H, d.M, d.S, d.L);
216  }
217
218  function utcDate(d) {
219    if (0 <= d.y && d.y < 100) {
220      var date = new Date(Date.UTC(-1, d.m, d.d, d.H, d.M, d.S, d.L));
221      date.setUTCFullYear(d.y);
222      return date;
223    }
224    return new Date(Date.UTC(d.y, d.m, d.d, d.H, d.M, d.S, d.L));
225  }
226
227  function newDate(y, m, d) {
228    return {y: y, m: m, d: d, H: 0, M: 0, S: 0, L: 0};
229  }
230
231  function formatLocale$1(locale) {
232    var locale_dateTime = locale.dateTime,
233        locale_date = locale.date,
234        locale_time = locale.time,
235        locale_periods = locale.periods,
236        locale_weekdays = locale.days,
237        locale_shortWeekdays = locale.shortDays,
238        locale_months = locale.months,
239        locale_shortMonths = locale.shortMonths;
240
241    var periodRe = formatRe(locale_periods),
242        periodLookup = formatLookup(locale_periods),
243        weekdayRe = formatRe(locale_weekdays),
244        weekdayLookup = formatLookup(locale_weekdays),
245        shortWeekdayRe = formatRe(locale_shortWeekdays),
246        shortWeekdayLookup = formatLookup(locale_shortWeekdays),
247        monthRe = formatRe(locale_months),
248        monthLookup = formatLookup(locale_months),
249        shortMonthRe = formatRe(locale_shortMonths),
250        shortMonthLookup = formatLookup(locale_shortMonths);
251
252    var formats = {
253      "a": formatShortWeekday,
254      "A": formatWeekday,
255      "b": formatShortMonth,
256      "B": formatMonth,
257      "c": null,
258      "d": formatDayOfMonth,
259      "e": formatDayOfMonth,
260      "f": formatMicroseconds,
261      "g": formatYearISO,
262      "G": formatFullYearISO,
263      "H": formatHour24,
264      "I": formatHour12,
265      "j": formatDayOfYear,
266      "L": formatMilliseconds,
267      "m": formatMonthNumber,
268      "M": formatMinutes,
vendor: 6,677 bytes, lines 269-478
269      "p": formatPeriod,
270      "q": formatQuarter,
271      "Q": formatUnixTimestamp,
272      "s": formatUnixTimestampSeconds,
273      "S": formatSeconds,
274      "u": formatWeekdayNumberMonday,
275      "U": formatWeekNumberSunday,
276      "V": formatWeekNumberISO,
277      "w": formatWeekdayNumberSunday,
278      "W": formatWeekNumberMonday,
279      "x": null,
280      "X": null,
281      "y": formatYear,
282      "Y": formatFullYear,
283      "Z": formatZone,
284      "%": formatLiteralPercent
285    };
286
287    var utcFormats = {
288      "a": formatUTCShortWeekday,
289      "A": formatUTCWeekday,
290      "b": formatUTCShortMonth,
291      "B": formatUTCMonth,
292      "c": null,
293      "d": formatUTCDayOfMonth,
294      "e": formatUTCDayOfMonth,
295      "f": formatUTCMicroseconds,
296      "g": formatUTCYearISO,
297      "G": formatUTCFullYearISO,
298      "H": formatUTCHour24,
299      "I": formatUTCHour12,
300      "j": formatUTCDayOfYear,
301      "L": formatUTCMilliseconds,
302      "m": formatUTCMonthNumber,
303      "M": formatUTCMinutes,
304      "p": formatUTCPeriod,
305      "q": formatUTCQuarter,
306      "Q": formatUnixTimestamp,
307      "s": formatUnixTimestampSeconds,
308      "S": formatUTCSeconds,
309      "u": formatUTCWeekdayNumberMonday,
310      "U": formatUTCWeekNumberSunday,
311      "V": formatUTCWeekNumberISO,
312      "w": formatUTCWeekdayNumberSunday,
313      "W": formatUTCWeekNumberMonday,
314      "x": null,
315      "X": null,
316      "y": formatUTCYear,
317      "Y": formatUTCFullYear,
318      "Z": formatUTCZone,
319      "%": formatLiteralPercent
320    };
321
322    var parses = {
323      "a": parseShortWeekday,
324      "A": parseWeekday,
325      "b": parseShortMonth,
326      "B": parseMonth,
327      "c": parseLocaleDateTime,
328      "d": parseDayOfMonth,
329      "e": parseDayOfMonth,
330      "f": parseMicroseconds,
331      "g": parseYear,
332      "G": parseFullYear,
333      "H": parseHour24,
334      "I": parseHour24,
335      "j": parseDayOfYear,
336      "L": parseMilliseconds,
337      "m": parseMonthNumber,
338      "M": parseMinutes,
339      "p": parsePeriod,
340      "q": parseQuarter,
341      "Q": parseUnixTimestamp,
342      "s": parseUnixTimestampSeconds,
343      "S": parseSeconds,
344      "u": parseWeekdayNumberMonday,
345      "U": parseWeekNumberSunday,
346      "V": parseWeekNumberISO,
347      "w": parseWeekdayNumberSunday,
348      "W": parseWeekNumberMonday,
349      "x": parseLocaleDate,
350      "X": parseLocaleTime,
351      "y": parseYear,
352      "Y": parseFullYear,
353      "Z": parseZone,
354      "%": parseLiteralPercent
355    };
356
357    // These recursive directive definitions must be deferred.
358    formats.x = newFormat(locale_date, formats);
359    formats.X = newFormat(locale_time, formats);
360    formats.c = newFormat(locale_dateTime, formats);
361    utcFormats.x = newFormat(locale_date, utcFormats);
362    utcFormats.X = newFormat(locale_time, utcFormats);
363    utcFormats.c = newFormat(locale_dateTime, utcFormats);
364
365    function newFormat(specifier, formats) {
366      return function(date) {
367        var string = [],
368            i = -1,
369            j = 0,
370            n = specifier.length,
371            c,
372            pad,
373            format;
374
375        if (!(date instanceof Date)) date = new Date(+date);
376
377        while (++i < n) {
378          if (specifier.charCodeAt(i) === 37) {
379            string.push(specifier.slice(j, i));
380            if ((pad = pads[c = specifier.charAt(++i)]) != null) c = specifier.charAt(++i);
381            else pad = c === "e" ? " " : "0";
382            if (format = formats[c]) c = format(date, pad);
383            string.push(c);
384            j = i + 1;
385          }
386        }
387
388        string.push(specifier.slice(j, i));
389        return string.join("");
390      };
391    }
392
393    function newParse(specifier, Z) {
394      return function(string) {
395        var d = newDate(1900, undefined, 1),
396            i = parseSpecifier(d, specifier, string += "", 0),
397            week, day;
398        if (i != string.length) return null;
399
400        // If a UNIX timestamp is specified, return it.
401        if ("Q" in d) return new Date(d.Q);
402        if ("s" in d) return new Date(d.s * 1000 + ("L" in d ? d.L : 0));
403
404        // If this is utcParse, never use the local timezone.
405        if (Z && !("Z" in d)) d.Z = 0;
406
407        // The am-pm flag is 0 for AM, and 1 for PM.
408        if ("p" in d) d.H = d.H % 12 + d.p * 12;
409
410        // If the month was not specified, inherit from the quarter.
411        if (d.m === undefined) d.m = "q" in d ? d.q : 0;
412
413        // Convert day-of-week and week-of-year to day-of-year.
414        if ("V" in d) {
415          if (d.V < 1 || d.V > 53) return null;
416          if (!("w" in d)) d.w = 1;
417          if ("Z" in d) {
418            week = utcDate(newDate(d.y, 0, 1)), day = week.getUTCDay();
419            week = day > 4 || day === 0 ? utcMonday.ceil(week) : utcMonday(week);
420            week = utcDay$1.offset(week, (d.V - 1) * 7);
421            d.y = week.getUTCFullYear();
422            d.m = week.getUTCMonth();
423            d.d = week.getUTCDate() + (d.w + 6) % 7;
424          } else {
425            week = localDate(newDate(d.y, 0, 1)), day = week.getDay();
426            week = day > 4 || day === 0 ? monday.ceil(week) : monday(week);
427            week = timeDay.offset(week, (d.V - 1) * 7);
428            d.y = week.getFullYear();
429            d.m = week.getMonth();
430            d.d = week.getDate() + (d.w + 6) % 7;
431          }
432        } else if ("W" in d || "U" in d) {
433          if (!("w" in d)) d.w = "u" in d ? d.u % 7 : "W" in d ? 1 : 0;
434          day = "Z" in d ? utcDate(newDate(d.y, 0, 1)).getUTCDay() : localDate(newDate(d.y, 0, 1)).getDay();
435          d.m = 0;
436          d.d = "W" in d ? (d.w + 6) % 7 + d.W * 7 - (day + 5) % 7 : d.w + d.U * 7 - (day + 6) % 7;
437        }
438
439        // If a time zone is specified, all fields are interpreted as UTC and then
440        // offset according to the specified time zone.
441        if ("Z" in d) {
442          d.H += d.Z / 100 | 0;
443          d.M += d.Z % 100;
444          return utcDate(d);
445        }
446
447        // Otherwise, all fields are in local time.
448        return localDate(d);
449      };
450    }
451
452    function parseSpecifier(d, specifier, string, j) {
453      var i = 0,
454          n = specifier.length,
455          m = string.length,
456          c,
457          parse;
458
459      while (i < n) {
460        if (j >= m) return -1;
461        c = specifier.charCodeAt(i++);
462        if (c === 37) {
463          c = specifier.charAt(i++);
464          parse = parses[c in pads ? specifier.charAt(i++) : c];
465          if (!parse || ((j = parse(d, string, j)) < 0)) return -1;
466        } else if (c != string.charCodeAt(j++)) {
467          return -1;
468        }
469      }
470
471      return j;
472    }
473
474    function parsePeriod(d, string, i) {
475      var n = periodRe.exec(string.slice(i));
476      return n ? (d.p = periodLookup[n[0].toLowerCase()], i + n[0].length) : -1;
477    }
478
vendor: 3,735 bytes, lines 479-613
479    function parseShortWeekday(d, string, i) {
480      var n = shortWeekdayRe.exec(string.slice(i));
481      return n ? (d.w = shortWeekdayLookup[n[0].toLowerCase()], i + n[0].length) : -1;
482    }
483
484    function parseWeekday(d, string, i) {
485      var n = weekdayRe.exec(string.slice(i));
486      return n ? (d.w = weekdayLookup[n[0].toLowerCase()], i + n[0].length) : -1;
487    }
488
489    function parseShortMonth(d, string, i) {
490      var n = shortMonthRe.exec(string.slice(i));
491      return n ? (d.m = shortMonthLookup[n[0].toLowerCase()], i + n[0].length) : -1;
492    }
493
494    function parseMonth(d, string, i) {
495      var n = monthRe.exec(string.slice(i));
496      return n ? (d.m = monthLookup[n[0].toLowerCase()], i + n[0].length) : -1;
497    }
498
499    function parseLocaleDateTime(d, string, i) {
500      return parseSpecifier(d, locale_dateTime, string, i);
501    }
502
503    function parseLocaleDate(d, string, i) {
504      return parseSpecifier(d, locale_date, string, i);
505    }
506
507    function parseLocaleTime(d, string, i) {
508      return parseSpecifier(d, locale_time, string, i);
509    }
510
511    function formatShortWeekday(d) {
512      return locale_shortWeekdays[d.getDay()];
513    }
514
515    function formatWeekday(d) {
516      return locale_weekdays[d.getDay()];
517    }
518
519    function formatShortMonth(d) {
520      return locale_shortMonths[d.getMonth()];
521    }
522
523    function formatMonth(d) {
524      return locale_months[d.getMonth()];
525    }
526
527    function formatPeriod(d) {
528      return locale_periods[+(d.getHours() >= 12)];
529    }
530
531    function formatQuarter(d) {
532      return 1 + ~~(d.getMonth() / 3);
533    }
534
535    function formatUTCShortWeekday(d) {
536      return locale_shortWeekdays[d.getUTCDay()];
537    }
538
539    function formatUTCWeekday(d) {
540      return locale_weekdays[d.getUTCDay()];
541    }
542
543    function formatUTCShortMonth(d) {
544      return locale_shortMonths[d.getUTCMonth()];
545    }
546
547    function formatUTCMonth(d) {
548      return locale_months[d.getUTCMonth()];
549    }
550
551    function formatUTCPeriod(d) {
552      return locale_periods[+(d.getUTCHours() >= 12)];
553    }
554
555    function formatUTCQuarter(d) {
556      return 1 + ~~(d.getUTCMonth() / 3);
557    }
558
559    return {
560      format: function(specifier) {
561        var f = newFormat(specifier += "", formats);
562        f.toString = function() { return specifier; };
563        return f;
564      },
565      parse: function(specifier) {
566        var p = newParse(specifier += "", false);
567        p.toString = function() { return specifier; };
568        return p;
569      },
570      utcFormat: function(specifier) {
571        var f = newFormat(specifier += "", utcFormats);
572        f.toString = function() { return specifier; };
573        return f;
574      },
575      utcParse: function(specifier) {
576        var p = newParse(specifier += "", true);
577        p.toString = function() { return specifier; };
578        return p;
579      }
580    };
581  }
582
583  var pads = {"-": "", "_": " ", "0": "0"},
584      numberRe = /^\s*\d+/, // note: ignores next directive
585      percentRe = /^%/,
586      requoteRe = /[\\^$*+?|[\]().{}]/g;
587
588  function pad(value, fill, width) {
589    var sign = value < 0 ? "-" : "",
590        string = (sign ? -value : value) + "",
591        length = string.length;
592    return sign + (length < width ? new Array(width - length + 1).join(fill) + string : string);
593  }
594
595  function requote(s) {
596    return s.replace(requoteRe, "\\$&");
597  }
598
599  function formatRe(names) {
600    return new RegExp("^(?:" + names.map(requote).join("|") + ")", "i");
601  }
602
603  function formatLookup(names) {
604    var map = {}, i = -1, n = names.length;
605    while (++i < n) map[names[i].toLowerCase()] = i;
606    return map;
607  }
608
609  function parseWeekdayNumberSunday(d, string, i) {
610    var n = numberRe.exec(string.slice(i, i + 1));
611    return n ? (d.w = +n[0], i + n[0].length) : -1;
612  }
613
vendor: 4,363 bytes, lines 614-771
614  function parseWeekdayNumberMonday(d, string, i) {
615    var n = numberRe.exec(string.slice(i, i + 1));
616    return n ? (d.u = +n[0], i + n[0].length) : -1;
617  }
618
619  function parseWeekNumberSunday(d, string, i) {
620    var n = numberRe.exec(string.slice(i, i + 2));
621    return n ? (d.U = +n[0], i + n[0].length) : -1;
622  }
623
624  function parseWeekNumberISO(d, string, i) {
625    var n = numberRe.exec(string.slice(i, i + 2));
626    return n ? (d.V = +n[0], i + n[0].length) : -1;
627  }
628
629  function parseWeekNumberMonday(d, string, i) {
630    var n = numberRe.exec(string.slice(i, i + 2));
631    return n ? (d.W = +n[0], i + n[0].length) : -1;
632  }
633
634  function parseFullYear(d, string, i) {
635    var n = numberRe.exec(string.slice(i, i + 4));
636    return n ? (d.y = +n[0], i + n[0].length) : -1;
637  }
638
639  function parseYear(d, string, i) {
640    var n = numberRe.exec(string.slice(i, i + 2));
641    return n ? (d.y = +n[0] + (+n[0] > 68 ? 1900 : 2000), i + n[0].length) : -1;
642  }
643
644  function parseZone(d, string, i) {
645    var n = /^(Z)|([+-]\d\d)(?::?(\d\d))?/.exec(string.slice(i, i + 6));
646    return n ? (d.Z = n[1] ? 0 : -(n[2] + (n[3] || "00")), i + n[0].length) : -1;
647  }
648
649  function parseQuarter(d, string, i) {
650    var n = numberRe.exec(string.slice(i, i + 1));
651    return n ? (d.q = n[0] * 3 - 3, i + n[0].length) : -1;
652  }
653
654  function parseMonthNumber(d, string, i) {
655    var n = numberRe.exec(string.slice(i, i + 2));
656    return n ? (d.m = n[0] - 1, i + n[0].length) : -1;
657  }
658
659  function parseDayOfMonth(d, string, i) {
660    var n = numberRe.exec(string.slice(i, i + 2));
661    return n ? (d.d = +n[0], i + n[0].length) : -1;
662  }
663
664  function parseDayOfYear(d, string, i) {
665    var n = numberRe.exec(string.slice(i, i + 3));
666    return n ? (d.m = 0, d.d = +n[0], i + n[0].length) : -1;
667  }
668
669  function parseHour24(d, string, i) {
670    var n = numberRe.exec(string.slice(i, i + 2));
671    return n ? (d.H = +n[0], i + n[0].length) : -1;
672  }
673
674  function parseMinutes(d, string, i) {
675    var n = numberRe.exec(string.slice(i, i + 2));
676    return n ? (d.M = +n[0], i + n[0].length) : -1;
677  }
678
679  function parseSeconds(d, string, i) {
680    var n = numberRe.exec(string.slice(i, i + 2));
681    return n ? (d.S = +n[0], i + n[0].length) : -1;
682  }
683
684  function parseMilliseconds(d, string, i) {
685    var n = numberRe.exec(string.slice(i, i + 3));
686    return n ? (d.L = +n[0], i + n[0].length) : -1;
687  }
688
689  function parseMicroseconds(d, string, i) {
690    var n = numberRe.exec(string.slice(i, i + 6));
691    return n ? (d.L = Math.floor(n[0] / 1000), i + n[0].length) : -1;
692  }
693
694  function parseLiteralPercent(d, string, i) {
695    var n = percentRe.exec(string.slice(i, i + 1));
696    return n ? i + n[0].length : -1;
697  }
698
699  function parseUnixTimestamp(d, string, i) {
700    var n = numberRe.exec(string.slice(i));
701    return n ? (d.Q = +n[0], i + n[0].length) : -1;
702  }
703
704  function parseUnixTimestampSeconds(d, string, i) {
705    var n = numberRe.exec(string.slice(i));
706    return n ? (d.s = +n[0], i + n[0].length) : -1;
707  }
708
709  function formatDayOfMonth(d, p) {
710    return pad(d.getDate(), p, 2);
711  }
712
713  function formatHour24(d, p) {
714    return pad(d.getHours(), p, 2);
715  }
716
717  function formatHour12(d, p) {
718    return pad(d.getHours() % 12 || 12, p, 2);
719  }
720
721  function formatDayOfYear(d, p) {
722    return pad(1 + timeDay.count(timeYear(d), d), p, 3);
723  }
724
725  function formatMilliseconds(d, p) {
726    return pad(d.getMilliseconds(), p, 3);
727  }
728
729  function formatMicroseconds(d, p) {
730    return formatMilliseconds(d, p) + "000";
731  }
732
733  function formatMonthNumber(d, p) {
734    return pad(d.getMonth() + 1, p, 2);
735  }
736
737  function formatMinutes(d, p) {
738    return pad(d.getMinutes(), p, 2);
739  }
740
741  function formatSeconds(d, p) {
742    return pad(d.getSeconds(), p, 2);
743  }
744
745  function formatWeekdayNumberMonday(d) {
746    var day = d.getDay();
747    return day === 0 ? 7 : day;
748  }
749
750  function formatWeekNumberSunday(d, p) {
751    return pad(sunday.count(timeYear(d) - 1, d), p, 2);
752  }
753
754  function dISO(d) {
755    var day = d.getDay();
756    return (day >= 4 || day === 0) ? thursday(d) : thursday.ceil(d);
757  }
758
759  function formatWeekNumberISO(d, p) {
760    d = dISO(d);
761    return pad(thursday.count(timeYear(d), d) + (timeYear(d).getDay() === 4), p, 2);
762  }
763
764  function formatWeekdayNumberSunday(d) {
765    return d.getDay();
766  }
767
768  function formatWeekNumberMonday(d, p) {
769    return pad(monday.count(timeYear(d) - 1, d), p, 2);
770  }
771
vendor: 3,279 bytes, lines 772-907
772  function formatYear(d, p) {
773    return pad(d.getFullYear() % 100, p, 2);
774  }
775
776  function formatYearISO(d, p) {
777    d = dISO(d);
778    return pad(d.getFullYear() % 100, p, 2);
779  }
780
781  function formatFullYear(d, p) {
782    return pad(d.getFullYear() % 10000, p, 4);
783  }
784
785  function formatFullYearISO(d, p) {
786    var day = d.getDay();
787    d = (day >= 4 || day === 0) ? thursday(d) : thursday.ceil(d);
788    return pad(d.getFullYear() % 10000, p, 4);
789  }
790
791  function formatZone(d) {
792    var z = d.getTimezoneOffset();
793    return (z > 0 ? "-" : (z *= -1, "+"))
794        + pad(z / 60 | 0, "0", 2)
795        + pad(z % 60, "0", 2);
796  }
797
798  function formatUTCDayOfMonth(d, p) {
799    return pad(d.getUTCDate(), p, 2);
800  }
801
802  function formatUTCHour24(d, p) {
803    return pad(d.getUTCHours(), p, 2);
804  }
805
806  function formatUTCHour12(d, p) {
807    return pad(d.getUTCHours() % 12 || 12, p, 2);
808  }
809
810  function formatUTCDayOfYear(d, p) {
811    return pad(1 + utcDay$1.count(utcYear$1(d), d), p, 3);
812  }
813
814  function formatUTCMilliseconds(d, p) {
815    return pad(d.getUTCMilliseconds(), p, 3);
816  }
817
818  function formatUTCMicroseconds(d, p) {
819    return formatUTCMilliseconds(d, p) + "000";
820  }
821
822  function formatUTCMonthNumber(d, p) {
823    return pad(d.getUTCMonth() + 1, p, 2);
824  }
825
826  function formatUTCMinutes(d, p) {
827    return pad(d.getUTCMinutes(), p, 2);
828  }
829
830  function formatUTCSeconds(d, p) {
831    return pad(d.getUTCSeconds(), p, 2);
832  }
833
834  function formatUTCWeekdayNumberMonday(d) {
835    var dow = d.getUTCDay();
836    return dow === 0 ? 7 : dow;
837  }
838
839  function formatUTCWeekNumberSunday(d, p) {
840    return pad(utcSunday.count(utcYear$1(d) - 1, d), p, 2);
841  }
842
843  function UTCdISO(d) {
844    var day = d.getUTCDay();
845    return (day >= 4 || day === 0) ? utcThursday(d) : utcThursday.ceil(d);
846  }
847
848  function formatUTCWeekNumberISO(d, p) {
849    d = UTCdISO(d);
850    return pad(utcThursday.count(utcYear$1(d), d) + (utcYear$1(d).getUTCDay() === 4), p, 2);
851  }
852
853  function formatUTCWeekdayNumberSunday(d) {
854    return d.getUTCDay();
855  }
856
857  function formatUTCWeekNumberMonday(d, p) {
858    return pad(utcMonday.count(utcYear$1(d) - 1, d), p, 2);
859  }
860
861  function formatUTCYear(d, p) {
862    return pad(d.getUTCFullYear() % 100, p, 2);
863  }
864
865  function formatUTCYearISO(d, p) {
866    d = UTCdISO(d);
867    return pad(d.getUTCFullYear() % 100, p, 2);
868  }
869
870  function formatUTCFullYear(d, p) {
871    return pad(d.getUTCFullYear() % 10000, p, 4);
872  }
873
874  function formatUTCFullYearISO(d, p) {
875    var day = d.getUTCDay();
876    d = (day >= 4 || day === 0) ? utcThursday(d) : utcThursday.ceil(d);
877    return pad(d.getUTCFullYear() % 10000, p, 4);
878  }
879
880  function formatUTCZone() {
881    return "+0000";
882  }
883
884  function formatLiteralPercent() {
885    return "%";
886  }
887
888  function formatUnixTimestamp(d) {
889    return +d;
890  }
891
892  function formatUnixTimestampSeconds(d) {
893    return Math.floor(+d / 1000);
894  }
895
896  var locale;
897  var utcFormat;
898  var utcParse;
899
900  defaultLocale({
901    dateTime: "%x, %X",
902    date: "%-m/%-d/%Y",
903    time: "%-I:%M:%S %p",
904    periods: ["AM", "PM"],
905    days: ["Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"],
906    shortDays: ["Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"],
907    months: ["January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "
907November", "December"],
908    shortMonths: ["Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"]
909  });
910
911  function defaultLocale(definition) {
912    locale = formatLocale$1(definition);
913    locale.format;
914    locale.parse;
915    utcFormat = locale.utcFormat;
916    utcParse = locale.utcParse;
917    return locale;
918  }
919
920  function notAStringError(not_a_str) {
921  	throw new TypeError(
922  		"Expected a value of type string but got a value of type " +
923  			typeof not_a_str,
924  	);
925  }
926
927  function shield(func) {
928  	return function (str) {
929  		if (typeof str !== "string") notAStringError(str);
930  		str = str.trim();
931  		return str ? func(str) : null;
932  	};
933  }
934
935  var EXAMPLE_DATETIME = new Date(1972, 3, 27, 19, 45, 5); // End of Apollo 16 mission
936
937  var CUSTOM_FORMAT_REGEXES = {
938  	// Regexes matching dates where the month would commonly be written with 4-letters
939  	// e.g. Sept 21, june 09, July 7
940  	"%b %d": [
941  		{
942  			regex: /^june\s(30|[12][0-9]|0?[1-9])$/i, // matches dates from June 0-30
943  			toDate: function (str) {
944  				return new Date(null, 5, str.split(/\s/)[1]);
945  			},
946  		},
947  		{
948  			regex: /^july\s(3[01]|[12][0-9]|0?[1-9])$/i, // matches dates from July 0-31
949  			toDate: function (str) {
950  				return new Date(null, 6, str.split(/\s/)[1]);
951  			},
952  		},
953  		{
954  			regex: /^sept\s(30|[12][0-9]|0?[1-9])$/i, // matches dates from September 0-30 using the 4-letter 'Sept' abbreviation
955  			toDate: function (str) {
956  				return new Date(null, 8, str.split(/\s/)[1]);
957  			},
958  		},
959  	],
960  	// Regexes matching dates where the month would commonly be written with 4-letters
961  	// e.g. 21 Sept, 09 june, 7 July
962  	"%d %b": [
963  		{
964  			regex: /^(0?[1-9]|[1-9][0-9])\sjune$/i, // matches dates from 0-99 June
965  			toDate: function (str) {
966  				return new Date(null, 5, str.split(/\s/)[0]);
967  			},
968  		},
969  		{
970  			regex: /^(0?[1-9]|[1-9][0-9])\sjuly$/i, // matches dates from 0-99 July
971  			toDate: function (str) {
972  				return new Date(null, 6, str.split(/\s/)[0]);
973  			},
974  		},
975  		{
976  			regex: /^(0?[1-9]|[1-9][0-9])\ssept$/i, // matches dates from 0-99 September using the 4-letter 'Sept' abbreviation
977  			toDate: function (str) {
978  				return new Date(null, 8, str.split(/\s/)[0]);
979  			},
980  		},
981  	],
982  };
983
984  // Checks a string against datetime regexes for different strftime date formats so that
985  // non-standard datetime strings can still be parsed as dates by d3-time-parse
986  function customDatetimeParser(strftime_formats) {
987  	return function (str) {
988  		var parsed_datetime = null;
989  		strftime_formats.forEach(function (strftime_format) {
990  			var valid_datetime = str.match(strftime_format.regex);
991  			if (valid_datetime) parsed_datetime = strftime_format.toDate(str);
992  		});
993  		return parsed_datetime;
994  	};
995  }
996
997  function createDatetimeInterpretation(format_string, secondaryTest) {
998  	var parser = utcParse(format_string);
999  	var formatter = utcFormat(format_string);
1000  	var test;
1001  	if (typeof secondaryTest === "function") {
1002  		test = shield(function (str) {
1003  			return secondaryTest(str, parser(str) !== null);
1004  		});
1005  	} else {
1006  		test = shield(function (str) {
1007  			return parser(str) !== null;
1008  		});
1009  	}
1010
1011  	return Object.freeze({
1012  		test: test,
1013  		parse: shield(function (str) {
1014  			return (
1015  				parser(str) ||
1016  				(CUSTOM_FORMAT_REGEXES[format_string]
1017  					? customDatetimeParser(CUSTOM_FORMAT_REGEXES[format_string])(str)
1018  					: null)
1019  			);
1020  		}),
1021  		format: function (dt) {
1022  			return formatter(dt);
1023  		},
1024  		type: "datetime",
1025  		description: format_string,
1026  		id: "datetime$" + format_string,
1027  		example: formatter(EXAMPLE_DATETIME),
1028  	});
1029  }
1030
1031  var datetime_interpretations = Object.freeze([
1032  	createDatetimeInterpretation("%Y-%m-%dT%H:%M:%S.%LZ"), // 1972-04-27T10:10:10.303Z
1033  	createDatetimeInterpretation("%Y-%m-%d %H:%M:%S"), // 1972-04-27 07:45:05
1034  	createDatetimeInterpretation("%Y-%m-%dT%H:%M:%S"), // 1972-04-27T07:45:05
1035  	createDatetimeInterpretation("%Y-%m-%dT%H:%M:%SZ"), // 1972-04-27T10:10:10Z
1036
1037  	createDatetimeInterpretation("%d/%m/%Y", function (str, passed_primary_test) {
1038  		// 27/04/1972
1039  		if (!passed_primary_test) return false;
1040  		var arr = str.split("/").map(parseFloat);
1041  		return (
1042  			arr[0] > 0 && arr[0] <= 31 && arr[1] > 0 && arr[1] <= 12 && arr[2] >= 1000
1043  		);
1044  	}),
1045  	createDatetimeInterpretation(
1046  		"%d/%m/%Y %H:%M",
1047  		function (str, passed_primary_test) {
1048  			// 27/04/1972 19:45
1049  			if (!passed_primary_test) return false;
1050  			var arr = str.split(/[/ :]/).map(parseFloat);
1051  			return (
1052  				arr[0] > 0 &&
1053  				arr[0] <= 31 &&
1054  				arr[1] > 0 &&
1055  				arr[1] <= 12 &&
1056  				arr[2] >= 1000 &&
1057  				arr[3] >= 0 &&
1058  				arr[3] < 24 &&
1059  				arr[4] >= 0 &&
1060  				arr[4] < 60
1061  			);
1062  		},
1063  	),
1064  	createDatetimeInterpretation("%d/%m/%y", function (str, passed_primary_test) {
1065  		// 27/04/72
1066  		if (!passed_primary_test) return false;
1067  		var arr = str.split("/").map(parseFloat);
1068  		return (
1069  			arr[0] > 0 && arr[0] <= 31 && arr[1] > 0 && arr[1] <= 12 && !isNaN(arr[2])
1070  		);
1071  	}),
1072  	createDatetimeInterpretation("%m/%d/%Y", function (str, passed_primary_test) {
1073  		// 04/27/1972
1074  		if (!passed_primary_test) return false;
1075  		var arr = str.split("/").map(parseFloat);
1076  		return (
1077  			arr[0] > 0 && arr[0] <= 12 && arr[1] > 0 && arr[1] <= 31 && arr[2] >= 1000
1078  		);
1079  	}),
1080  	createDatetimeInterpretation(
1081  		"%m/%d/%Y %H:%M",
1082  		function (str, passed_primary_test) {
1083  			// 04/27/1972 19:45
1084  			if (!passed_primary_test) return false;
1085  			var arr = str.split(/[/ :]/).map(parseFloat);
1086  			return (
1087  				arr[0] > 0 &&
1088  				arr[0] <= 12 &&
1089  				arr[1] > 0 &&
1090  				arr[1] <= 31 &&
1091  				arr[2] >= 1000 &&
1092  				arr[3] >= 0 &&
1093  				arr[3] < 24 &&
1094  				arr[4] >= 0 &&
1095  				arr[4] < 60
1096  			);
1097  		},
1098  	),
1099  	createDatetimeInterpretation("%m/%d/%y", function (str, passed_primary_test) {
1100  		// 04/27/72
1101  		if (!passed_primary_test) return false;
1102  		var arr = str.split("/").map(parseFloat);
1103  		return (
1104  			arr[0] > 0 && arr[0] <= 12 && arr[1] > 0 && arr[1] <= 31 && !isNaN(arr[2])
1105  		);
1106  	}),
1107  	createDatetimeInterpretation("%Y/%m/%d", function (str, passed_primary_test) {
1108  		// 1972/04/27
1109  		if (!passed_primary_test) return false;
1110  		var arr = str.split("/").map(parseFloat);
1111  		return (
1112  			arr[0] >= 1000 && arr[1] > 0 && arr[1] <= 12 && arr[2] > 0 && arr[2] <= 31
1113  		);
1114  	}),
1115
1116  	createDatetimeInterpretation("%d-%m-%Y", function (str, passed_primary_test) {
1117  		// 27-04-1972
1118  		if (!passed_primary_test) return false;
1119  		var arr = str.split("-").map(parseFloat);
1120  		return (
1121  			arr[0] > 0 && arr[0] <= 31 && arr[1] > 0 && arr[1] <= 12 && arr[2] >= 1000
1122  		);
1123  	}),
1124  	createDatetimeInterpretation("%d-%m-%y", function (str, passed_primary_test) {
1125  		// 27-04-72
1126  		if (!passed_primary_test) return false;
1127  		var arr = str.split("-").map(parseFloat);
1128  		return (
1129  			arr[0] > 0 && arr[0] <= 31 && arr[1] > 0 && arr[1] <= 12 && !isNaN(arr[2])
1130  		);
1131  	}),
1132
1133  	createDatetimeInterpretation("%d.%m.%Y", function (str, passed_primary_test) {
1134  		// 27.04.1972
1135  		if (!passed_primary_test) return false;
1136
1137  		var arr = str.split(".").map(parseFloat);
1138  		return (
1139  			arr[0] > 0 && arr[0] <= 31 && arr[1] > 0 && arr[1] <= 12 && arr[2] >= 1000
1140  		);
1141  	}),
1142
1143  	createDatetimeInterpretation("%m.%d.%y", function (str, passed_primary_test) {
1144  		// 04.27.72
1145  		if (!passed_primary_test) return false;
1146
1147  		var arr = str.split(".").map(parseFloat);
1148  		return (
1149  			arr[0] > 0 && arr[0] <= 12 && arr[1] > 0 && arr[1] <= 31 && !isNaN(arr[2])
1150  		);
1151  	}),
1152
1153  	createDatetimeInterpretation("%m-%d-%Y", function (str, passed_primary_test) {
1154  		// 04-27-1972
1155  		if (!passed_primary_test) return false;
1156  		var arr = str.split("-").map(parseFloat);
1157  		return (
1158  			arr[0] > 0 && arr[0] <= 12 && arr[1] > 0 && arr[1] <= 31 && arr[2] >= 1000
1159  		);
1160  	}),
1161  	createDatetimeInterpretation("%m-%d-%y", function (str, passed_primary_test) {
1162  		// 04-27-72
1163  		if (!passed_primary_test) return false;
1164  		var arr = str.split("-").map(parseFloat);
1165  		return (
1166  			arr[0] > 0 && arr[0] <= 12 && arr[1] > 0 && arr[1] <= 31 && !isNaN(arr[2])
1167  		);
1168  	}),
1169  	createDatetimeInterpretation("%Y-%m-%d", function (str, passed_primary_test) {
1170  		// 1972-04-27
1171  		if (!passed_primary_test) return false;
1172  		var arr = str.split("-").map(parseFloat);
1173  		return (
1174  			arr[0] >= 1000 && arr[1] > 0 && arr[1] <= 12 && arr[2] > 0 && arr[2] <= 31
1175  		);
1176  	}),
1177  	createDatetimeInterpretation("%Y-%m", function (str, passed_primary_test) {
1178  		// 1972-04
1179  		if (!passed_primary_test) return false;
1180  		var arr = str.split("-").map(parseFloat);
1181  		return arr[0] >= 1000 && arr[1] > 0 && arr[1] <= 12;
1182  	}),
1183
1184  	createDatetimeInterpretation("%d %b %Y", function (str, passed_primary_test) {
1185  		// 27 Apr 1972
1186  		if (!passed_primary_test) return false;
1187  		var arr = str.split(" ").map(parseFloat);
1188  		return arr[0] > 0 && arr[0] <= 31 && arr[2] >= 1000;
1189  	}),
1190  	createDatetimeInterpretation("%d %B %Y", function (str, passed_primary_test) {
1191  		// 27 April 1972
1192  		if (!passed_primary_test) return false;
1193  		var arr = str.split(" ").map(parseFloat);
1194  		return arr[0] > 0 && arr[0] <= 31 && arr[2] >= 1000;
1195  	}),
1196  	createDatetimeInterpretation("%d %b %y"), // 27 Apr 72
1197  	createDatetimeInterpretation("%-d %b ’%y"), // 27 Apr ’72
1198  	createDatetimeInterpretation("%d %B %y"), // 27 April 72
1199  	createDatetimeInterpretation("%d-%b-%Y", function (str, passed_primary_test) {
1200  		// 27-Apr-1972
1201  		if (!passed_primary_test) return false;
1202  		var arr = str.split("-").map(parseFloat);
1203  		return arr[0] > 0 && arr[0] <= 31 && arr[2] >= 1000;
1204  	}),
1205  	createDatetimeInterpretation("%d-%B-%Y", function (str, passed_primary_test) {
1206  		// 27-April-1972
1207  		if (!passed_primary_test) return false;
1208  		var arr = str.split("-").map(parseFloat);
1209  		return arr[0] > 0 && arr[0] <= 31 && arr[2] >= 1000;
1210  	}),
1211  	createDatetimeInterpretation("%d-%b-%y"), // 27-Apr-72
1212  	createDatetimeInterpretation("%d-%B-%y"), // 27-April-72
1213
1214  	createDatetimeInterpretation("%m/%Y", function (str, passed_primary_test) {
1215  		// 04/1972
1216  		if (!passed_primary_test) return false;
1217  		var arr = str.split("/").map(parseFloat);
1218  		return arr[0] > 0 && arr[0] <= 12 && arr[1] >= 1000;
1219  	}),
1220  	createDatetimeInterpretation("%m/%y"), // 04/72
1221  	createDatetimeInterpretation("%b %Y", function (str, passed_primary_test) {
1222  		// Apr 1972
1223  		if (!passed_primary_test) return false;
1224  		var arr = str.split(" ").map(parseFloat);
1225  		return arr[1] >= 1000;
1226  	}),
1227  	createDatetimeInterpretation("%B %Y", function (str, passed_primary_test) {
1228  		// April 1972
1229  		if (!passed_primary_test) return false;
1230  		var arr = str.split(" ").map(parseFloat);
1231  		return arr[1] >= 1000;
1232  	}),
1233  	createDatetimeInterpretation("%b-%y"), // Apr-72
1234  	createDatetimeInterpretation("%b %y"), // Apr 72
1235  	createDatetimeInterpretation("%B %y"), // April 72
1236  	createDatetimeInterpretation("%b '%y"), // Apr '72
1237  	createDatetimeInterpretation("%b ’%y"), // Apr ’72
1238  	createDatetimeInterpretation("%B %-d %Y"), // April 27 1972
1239
1240  	createDatetimeInterpretation("%d %b", function (str, passed_primary_test) {
1241  		if (passed_primary_test) return true;
1242  		return !!customDatetimeParser(CUSTOM_FORMAT_REGEXES["%d %b"])(str);
1243  	}),
1244  	createDatetimeInterpretation("%d %B"), // 27 April
1245  	createDatetimeInterpretation("%b %d", function (str, passed_primary_test) {
1246  		if (passed_primary_test) return true;
1247  		return !!customDatetimeParser(CUSTOM_FORMAT_REGEXES["%b %d"])(str);
1248  	}),
1249  	createDatetimeInterpretation("%B %d"), // April 27
1250  	createDatetimeInterpretation("%d-%m", function (str, passed_primary_test) {
1251  		// 27-04
1252  		if (!passed_primary_test) return false;
1253  		var arr = str.split("-").map(parseFloat);
1254  		return arr[0] > 0 && arr[0] <= 31 && arr[1] > 0 && arr[1] <= 12;
1255  	}),
1256  	createDatetimeInterpretation("%m-%d"), // 04-27
1257  	createDatetimeInterpretation("%d/%m"), // 27/04
1258  	createDatetimeInterpretation("%m/%d"), // 04/27
1259  	createDatetimeInterpretation("%b %d %Y"), // Apr 27 1972
1260  	createDatetimeInterpretation("%b %d %Y, %-I.%M%p"), // Apr 27 1972, 5.30PM
1261
1262  	createDatetimeInterpretation("%B"), // April
1263  	createDatetimeInterpretation("%b"), // Apr
1264
1265  	createDatetimeInterpretation("%X"), // 7:45:05 PM
1266  	createDatetimeInterpretation("%I:%M %p"), // 07:45 PM
1267  	createDatetimeInterpretation("%-I.%M%p"), // 7.45PM
1268  	createDatetimeInterpretation("%H:%M", function (str, passed_primary_test) {
1269  		// 19:45
1270  		if (!passed_primary_test) return false;
1271  		var arr = str.split(":").map(parseFloat);
1272  		return arr[0] >= 0 && arr[0] < 24;
1273  	}),
1274  	createDatetimeInterpretation("%H:%M:%S"), // 19:45:05
1275  	createDatetimeInterpretation("%M:%S"), // 45:05
1276  	createDatetimeInterpretation("%-I%p"), // 7PM
1277
1278  	createDatetimeInterpretation("Q%q %Y", function (str, passed_primary_test) {
1279  		// Q2 1972
1280  		if (!passed_primary_test) return false;
1281  		return str.replace(/\s/g, "").length === 6;
1282  	}),
1283  	createDatetimeInterpretation("%Y Q%q", function (str, passed_primary_test) {
1284  		// 1972 Q2
1285  		if (!passed_primary_test) return false;
1286  		return str.replace(/\s/g, "").length === 6;
1287  	}),
1288  	createDatetimeInterpretation("%YM%m", function (str, passed_primary_test) {
1289  		// 1972M04
1290  		if (!passed_primary_test) return false;
1291  		var arr = str.split("M").map(parseFloat);
1292  		return arr[0] >= 1000 && arr[1] > 0 && arr[1] <= 12;
1293  	}),
1294  	createDatetimeInterpretation("%YQ%q", function (str, passed_primary_test) {
1295  		// 1972Q2
1296  		if (!passed_primary_test) return false;
1297  		var arr = str.split("Q").map(parseFloat);
1298  		return arr[0] >= 1000 && arr[1] > 0 && arr[1] <= 4;
1299  	}),
1300  	createDatetimeInterpretation("%YÁ%q", function (str, passed_primary_test) {
1301  		// 1972Á2
1302  		if (!passed_primary_test) return false;
1303  		var arr = str.split("Á").map(parseFloat);
1304  		return arr[0] >= 1000 && arr[1] > 0 && arr[1] <= 4;
1305  	}),
1306  ]);
1307
1308  // Datetime format-only interpretations - formats that could be confused with 
1308numbers
1309  // These are available for explicit formatting but not for auto-detection
1310  var datetime_format_only = Object.freeze([
1311  	createDatetimeInterpretation("%Y", function (str, passed_primary_test) {
1312  		// 1972 - could be confused with a plain number
1313  		if (!passed_primary_test) return false;
1314  		var val = parseFloat(str);
1315  		return val > 1499 && val < 2200;
1316  	}),
1317  	createDatetimeInterpretation("%Y%m", function (str, passed_primary_test) {
1318  		// 197204 - could be confused with a 6-digit number
1319  		if (!passed_primary_test) return false;
1320  		var year = parseFloat(str.slice(0, 4));
1321  		var month = parseFloat(str.slice(4));
1322  		return year > 1000 && month > 0 && month <= 12;
1323  	}),
1324  ]);
1325
1326  function formatDecimal(x) {
1327    return Math.abs(x = Math.round(x)) >= 1e21
1328        ? x.toLocaleString("en").replace(/,/g, "")
1329        : x.toString(10);
1330  }
1331
1332  // Computes the decimal coefficient and exponent of the specified number x with
1333  // significant digits p, where x is positive and p is in [1, 21] or undefined.
1334  // For example, formatDecimalParts(1.23) returns ["123", 0].
1335  function formatDecimalParts(x, p) {
1336    if ((i = (x = p ? x.toExponential(p - 1) : x.toExponential()).indexOf("e")) < 0) return null; // NaN, ±Infinity
1337    var i, coefficient = x.slice(0, i);
1338
1339    // The string returned by toExponential either has the form \d\.\d+e[-+]\d+
1340    // (e.g., 1.2e+3) or the form \de[-+]\d+ (e.g., 1e+3).
1341    return [
1342      coefficient.length > 1 ? coefficient[0] + coefficient.slice(2) : coefficient,
1343      +x.slice(i + 1)
1344    ];
1345  }
1346
1347  function exponent(x) {
1348    return x = formatDecimalParts(Math.abs(x)), x ? x[1] : NaN;
1349  }
1350
1351  function formatGroup(grouping, thousands) {
1352    return function(value, width) {
1353      var i = value.length,
1354          t = [],
1355          j = 0,
1356          g = grouping[0],
1357          length = 0;
1358
1359      while (i > 0 && g > 0) {
1360        if (length + g + 1 > width) g = Math.max(1, width - length);
1361        t.push(value.substring(i -= g, i + g));
1362        if ((length += g + 1) > width) break;
1363        g = grouping[j = (j + 1) % grouping.length];
1364      }
1365
1366      return t.reverse().join(thousands);
1367    };
1368  }
1369
1370  function formatNumerals(numerals) {
1371    return function(value) {
1372      return value.replace(/[0-9]/g, function(i) {
1373        return numerals[+i];
1374      });
1375    };
1376  }
1377
1378  // [[fill]align][sign][symbol][0][width][,][.precision][~][type]
1379  var re = /^(?:(.)?([<>=^]))?([+\-( ])?([$#])?(0)?(\d+)?(,)?(\.\d+)?(~)?([a-z%])?$/i;
1380
1381  function formatSpecifier(specifier) {
1382    if (!(match = re.exec(specifier))) throw new Error("invalid format: " + specifier);
1383    var match;
1384    return new FormatSpecifier({
1385      fill: match[1],
1386      align: match[2],
1387      sign: match[3],
1388      symbol: match[4],
1389      zero: match[5],
1390      width: match[6],
1391      comma: match[7],
1392      precision: match[8] && match[8].slice(1),
1393      trim: match[9],
1394      type: match[10]
1395    });
1396  }
1397
1398  formatSpecifier.prototype = FormatSpecifier.prototype; // instanceof
1399
1400  function FormatSpecifier(specifier) {
1401    this.fill = specifier.fill === undefined ? " " : specifier.fill + "";
1402    this.align = specifier.align === undefined ? ">" : specifier.align + "";
1403    this.sign = specifier.sign === undefined ? "-" : specifier.sign + "";
1404    this.symbol = specifier.symbol === undefined ? "" : specifier.symbol + "";
1405    this.zero = !!specifier.zero;
1406    this.width = specifier.width === undefined ? undefined : +specifier.width;
1407    this.comma = !!specifier.comma;
1408    this.precision = specifier.precision === undefined ? undefined : +specifier.precision;
1409    this.trim = !!specifier.trim;
1410    this.type = specifier.type === undefined ? "" : specifier.type + "";
1411  }
1412
1413  FormatSpecifier.prototype.toString = function() {
1414    return this.fill
1415        + this.align
1416        + this.sign
1417        + this.symbol
1418        + (this.zero ? "0" : "")
1419        + (this.width === undefined ? "" : Math.max(1, this.width | 0))
1420        + (this.comma ? "," : "")
1421        + (this.precision === undefined ? "" : "." + Math.max(0, this.precision | 0))
1422        + (this.trim ? "~" : "")
1423        + this.type;
1424  };
1425
1426  // Trims insignificant zeros, e.g., replaces 1.2000k with 1.2k.
1427  function formatTrim(s) {
1428    out: for (var n = s.length, i = 1, i0 = -1, i1; i < n; ++i) {
1429      switch (s[i]) {
1430        case ".": i0 = i1 = i; break;
1431        case "0": if (i0 === 0) i0 = i; i1 = i; break;
1432        default: if (!+s[i]) break out; if (i0 > 0) i0 = 0; break;
1433      }
1434    }
1435    return i0 > 0 ? s.slice(0, i0) + s.slice(i1 + 1) : s;
1436  }
1437
1438  var prefixExponent;
1439
1440  function formatPrefixAuto(x, p) {
1441    var d = formatDecimalParts(x, p);
1442    if (!d) return x + "";
1443    var coefficient = d[0],
1444        exponent = d[1],
vendor: 5,102 bytes, lines 1445-1559
1445        i = exponent - (prefixExponent = Math.max(-8, Math.min(8, Math.floor(exponent / 3))) * 3) + 1,
1446        n = coefficient.length;
1447    return i === n ? coefficient
1448        : i > n ? coefficient + new Array(i - n + 1).join("0")
1449        : i > 0 ? coefficient.slice(0, i) + "." + coefficient.slice(i)
1450        : "0." + new Array(1 - i).join("0") + formatDecimalParts(x, Math.max(0, p + i - 1))[0]; // less than 1y!
1451  }
1452
1453  function formatRounded(x, p) {
1454    var d = formatDecimalParts(x, p);
1455    if (!d) return x + "";
1456    var coefficient = d[0],
1457        exponent = d[1];
1458    return exponent < 0 ? "0." + new Array(-exponent).join("0") + coefficient
1459        : coefficient.length > exponent + 1 ? coefficient.slice(0, exponent + 1) + "." + coefficient.slice(exponent + 1)
1460        : coefficient + new Array(exponent - coefficient.length + 2).join("0");
1461  }
1462
1463  var formatTypes = {
1464    "%": function(x, p) { return (x * 100).toFixed(p); },
1465    "b": function(x) { return Math.round(x).toString(2); },
1466    "c": function(x) { return x + ""; },
1467    "d": formatDecimal,
1468    "e": function(x, p) { return x.toExponential(p); },
1469    "f": function(x, p) { return x.toFixed(p); },
1470    "g": function(x, p) { return x.toPrecision(p); },
1471    "o": function(x) { return Math.round(x).toString(8); },
1472    "p": function(x, p) { return formatRounded(x * 100, p); },
1473    "r": formatRounded,
1474    "s": formatPrefixAuto,
1475    "X": function(x) { return Math.round(x).toString(16).toUpperCase(); },
1476    "x": function(x) { return Math.round(x).toString(16); }
1477  };
1478
1479  function identity(x) {
1480    return x;
1481  }
1482
1483  var map = Array.prototype.map,
1484      prefixes = ["y","z","a","f","p","n","µ","m","","k","M","G","T","P","E","Z","Y"];
1485
1486  function formatLocale(locale) {
1487    var group = locale.grouping === undefined || locale.thousands === undefined ? identity : formatGroup(map.call(locale.grouping, Number), locale.thousands + ""),
1488        currencyPrefix = locale.currency === undefined ? "" : locale.currency[0] + "",
1489        currencySuffix = locale.currency === undefined ? "" : locale.currency[1] + "",
1490        decimal = locale.decimal === undefined ? "." : locale.decimal + "",
1491        numerals = locale.numerals === undefined ? identity : formatNumerals(map.call(locale.numerals, String)),
1492        percent = locale.percent === undefined ? "%" : locale.percent + "",
1493        minus = locale.minus === undefined ? "-" : locale.minus + "",
1494        nan = locale.nan === undefined ? "NaN" : locale.nan + "";
1495
1496    function newFormat(specifier) {
1497      specifier = formatSpecifier(specifier);
1498
1499      var fill = specifier.fill,
1500          align = specifier.align,
1501          sign = specifier.sign,
1502          symbol = specifier.symbol,
1503          zero = specifier.zero,
1504          width = specifier.width,
1505          comma = specifier.comma,
1506          precision = specifier.precision,
1507          trim = specifier.trim,
1508          type = specifier.type;
1509
1510      // The "n" type is an alias for ",g".
1511      if (type === "n") comma = true, type = "g";
1512
1513      // The "" type, and any invalid type, is an alias for ".12~g".
1514      else if (!formatTypes[type]) precision === undefined && (precision = 12), trim = true, type = "g";
1515
1516      // If zero fill is specified, padding goes after sign and before digits.
1517      if (zero || (fill === "0" && align === "=")) zero = true, fill = "0", align = "=";
1518
1519      // Compute the prefix and suffix.
1520      // For SI-prefix, the suffix is lazily computed.
1521      var prefix = symbol === "$" ? currencyPrefix : symbol === "#" && /[boxX]/.test(type) ? "0" + type.toLowerCase() : "",
1522          suffix = symbol === "$" ? currencySuffix : /[%p]/.test(type) ? percent : "";
1523
1524      // What format function should we use?
1525      // Is this an integer type?
1526      // Can this type generate exponential notation?
1527      var formatType = formatTypes[type],
1528          maybeSuffix = /[defgprs%]/.test(type);
1529
1530      // Set the default precision if not specified,
1531      // or clamp the specified precision to the supported range.
1532      // For significant precision, it must be in [1, 21].
1533      // For fixed precision, it must be in [0, 20].
1534      precision = precision === undefined ? 6
1535          : /[gprs]/.test(type) ? Math.max(1, Math.min(21, precision))
1536          : Math.max(0, Math.min(20, precision));
1537
1538      function format(value) {
1539        var valuePrefix = prefix,
1540            valueSuffix = suffix,
1541            i, n, c;
1542
1543        if (type === "c") {
1544          valueSuffix = formatType(value) + valueSuffix;
1545          value = "";
1546        } else {
1547          value = +value;
1548
1549          // Determine the sign. -0 is not less than 0, but 1 / -0 is!
1550          var valueNegative = value < 0 || 1 / value < 0;
1551
1552          // Perform the initial formatting.
1553          value = isNaN(value) ? nan : formatType(Math.abs(value), precision);
1554
1555          // Trim insignificant zeros.
1556          if (trim) value = formatTrim(value);
1557
1558          // If a negative value rounds to zero after formatting, and no explicit positive sign is requested, hide the sign.
1559          if (valueNegative && +value === 0 && sign !== "+") valueNegative = false;
1560
1561          // Compute the prefix and suffix.
1562          valuePrefix = (valueNegative ? (sign === "(" ? sign : minus) : sign === "-" || sign === "(" ? "" : sign) + valuePrefix;
1563          valueSuffix = (type === "s" ? prefixes[8 + prefixExponent / 3] : "") + valueSuffix + (valueNegative && sign === "(" ? ")" : "");
1564
1565          // Break the formatted value into the integer “value” part that can be
1566          // grouped, and fractional or exponential “suffix” part that is not.
1567          if (maybeSuffix) {
1568            i = -1, n = value.length;
1569            while (++i < n) {
1570              if (c = value.charCodeAt(i), 48 > c || c > 57) {
1571                valueSuffix = (c === 46 ? decimal + value.slice(i + 1) : value.slice(i)) + valueSuffix;
1572                value = value.slice(0, i);
1573                break;
1574              }
1575            }
1576          }
1577        }
1578
1579        // If the fill character is not "0", grouping is applied before padding.
1580        if (comma && !zero) value = group(value, Infinity);
1581
1582        // Compute the padding.
1583        var length = valuePrefix.length + value.length + valueSuffix.length,
1584            padding = length < width ? new Array(width - length + 1).join(fill) : "";
1585
1586        // If the fill character is "0", grouping is applied after padding.
1587        if (comma && zero) value = group(padding + value, padding.length ? width - valueSuffix.length : Infinity), padding = "";
1588
1589        // Reconstruct the final output based on the desired alignment.
1590        switch (align) {
1591          case "<": value = valuePrefix + value + valueSuffix + padding; break;
1592          case "=": value = valuePrefix + padding + value + valueSuffix; break;
1593          case "^": value = padding.slice(0, length = padding.length >> 1) + valuePrefix + value + valueSuffix + padding.slice(length); break;
1594          default: value = padding + valuePrefix + value + valueSuffix; break;
1595        }
1596
1597        return numerals(value);
1598      }
1599
1600      format.toString = function() {
1601        return specifier + "";
1602      };
1603
1604      return format;
1605    }
1606
1607    function formatPrefix(specifier, value) {
1608      var f = newFormat((specifier = formatSpecifier(specifier), specifier.type = "f", specifier)),
1609          e = Math.max(-8, Math.min(8, Math.floor(exponent(value) / 3))) * 3,
1610          k = Math.pow(10, -e),
1611          prefix = prefixes[8 + e / 3];
1612      return function(value) {
1613        return f(k * value) + prefix;
1614      };
1615    }
1616
1617    return {
1618      format: newFormat,
1619      formatPrefix: formatPrefix
1620    };
1621  }
1622
1623  function getFormatFunction(interp) {
1624  	var decimal = interp.decimal_mark;
1625  	var thousands = interp.thousand_separator;
1626  	var locale = formatLocale({
1627  		decimal: decimal,
1628  		thousands: thousands,
1629  		grouping: [3],
1630  		currency: ["", ""],
1631  	});
1632  	var format, specifier;
1633
1634  	return function (value, spec) {
1635  		if (value === null) return "";
1636  		if (!spec) spec = ",.2f";
1637  		if (spec !== specifier) {
1638  			specifier = spec;
1639  			format = locale.format(specifier);
1640  		}
1641  		return format(value);
1642  	};
1643  }
1644
1645  // https://stackoverflow.com/a/16148273
1646  var comma_point = {
1647  	test: shield(function (str) {
1648  		return /^(\+|-)?\d{1,3}(,\d{3})*(\.\d+)?((e|E)(\+|-)?\d+)?$/.test(
1649  			str.trim(),
1650  		);
1651  	}),
1652  	parse: shield(function (str) {
1653  		return parseFloat(str.replace(/,/g, ""));
1654  	}),
1655  	description: "Comma thousand separator, point decimal mark",
1656  	thousand_separator: ",",
1657  	decimal_mark: ".",
1658  	id: "number$comma_point",
1659  	example: "12,235.56",
1660  };
1661
1662  var space_point = {
1663  	test: shield(function (str) {
1664  		return /^(\+|-)?\d{1,3}(\s\d{3})*(\.\d+)?((e|E)(\+|-)?\d+)?$/.test(
1665  			str.trim(),
1666  		);
1667  	}),
1668  	parse: shield(function (str) {
1669  		return parseFloat(str.replace(/\s/g, ""));
1670  	}),
1671  	description: "Space thousand separator, point decimal mark",
1672  	thousand_separator: " ",
1673  	decimal_mark: ".",
1674  	id: "number$space_point",
1675  	example: "12 235.56",
1676  };
1677
1678  var none_point = {
1679  	test: shield(function (str) {
1680  		return /^(\+|-)?\d+(\.\d+)?((e|E)(\+|-)?\d+)?$/.test(str.trim());
1681  	}),
1682  	parse: shield(function (str) {
1683  		return parseFloat(str);
1684  	}),
1685  	description: "No thousand separator, point decimal mark",
1686  	thousand_separator: "",
1687  	decimal_mark: ".",
1688  	id: "number$none_point",
1689  	example: "12235.56",
1690  };
1691
1692  var point_comma = {
1693  	test: shield(function (str) {
1694  		return /^(\+|-)?\d{1,3}(\.\d{3})*(,\d+)?((e|E)(\+|-)?\d+)?$/.test(
1695  			str.trim(),
1696  		);
1697  	}),
1698  	parse: shield(function (str) {
1699  		return parseFloat(str.replace(/\./g, "").replace(/,/, "."));
1700  	}),
1701  	description: "Point thousand separator, comma decimal mark",
1702  	thousand_separator: ".",
1703  	decimal_mark: ",",
1704  	id: "number$point_comma",
1705  	example: "12.235,56",
1706  };
1707
1708  var space_comma = {
1709  	test: shield(function (str) {
1710  		return /^(\+|-)?\d{1,3}(\s\d{3})*(,\d+)?((e|E)(\+|-)?\d+)?$/.test(
1711  			str.trim(),
1712  		);
1713  	}),
1714  	parse: shield(function (str) {
1715  		return parseFloat(str.replace(/\s/g, "").replace(/,/, "."));
1716  	}),
1717  	description: "Space thousand separator, comma decimal mark",
1718  	thousand_separator: " ",
1719  	decimal_mark: ",",
1720  	id: "number$space_comma",
1721  	example: "12 235,56",
1722  };
1723
1724  var none_comma = {
1725  	test: shield(function (str) {
1726  		return /^(\+|-)?\d+(,\d+)?((e|E)(\+|-)?\d+)?$/.test(str.trim());
1727  	}),
1728  	parse: shield(function (str) {
1729  		return parseFloat(str.replace(/,/, "."));
1730  	}),
1731  	description: "No thousand separator, comma decimal mark",
1732  	thousand_separator: "",
1733  	decimal_mark: ",",
1734  	id: "number$none_comma",
1735  	example: "12235,56",
1736  };
1737
1738  var number_interpretations = Object.freeze([
1739  	comma_point,
1740  	space_point,
1741  	point_comma,
1742  	space_comma,
1743  	none_point,
1744  	none_comma,
1745  ]);
1746
1747  number_interpretations.forEach(function (interp) {
1748  	interp.type = "number";
1749  	interp.format = getFormatFunction(interp);
1750  	Object.freeze(interp);
1751  });
1752
1753  var string_interpretation = Object.freeze({
1754  	test: function (str) {
1755  		return typeof str === "string" ? true : notAStringError(str);
1756  	},
1757  	parse: function (str) {
1758  		return typeof str === "string" ? str : notAStringError(str);
1759  	},
1760  	format: function (str) {
1761  		if (typeof str === "string") return str;
1762  	},
1763  	type: "string",
1764  	description: "Arbitrary string",
1765  	id: "string$arbitrary_string",
1766  });
1767
1768  var INTERPRETATION_OPTIONS = Object.freeze({
1769  	datetime: datetime_interpretations,
1770  	number: number_interpretations,
1771  });
1772
1773  var DEFAULT_INTERPRETATIONS_ARRAY = Object.freeze([
1774  	"datetime",
1775  	"number",
1776  	"string",
1777  ]);
1778
1779  var DEFAULT_OPTIONS = Object.freeze({
1780  	n_max: 250,
1781  	n_failing_values: 0,
1782  	failure_fraction: 5 / 100,
1783  	sort: true,
1784  });
1785
1786  var OPTION_KEYS = Object.freeze(Object.keys(DEFAULT_OPTIONS));
1787
1788  function snakeToCamel(snake_string) {
1789  	return snake_string.replace(/_(\w)/g, function (match, capture) {
1790  		return capture.toUpperCase();
1791  	});
1792  }
1793
1794  function noSort(a, b) {
1795  	return a.index - b.index;
1796  }
1797  function sortBySuccess(a, b) {
1798  	return b.n_success - a.n_success || noSort(a, b);
1799  }
1800
1801  function trim(value) {
1802  	return ("" + value).trim();
1803  }
1804
1805  function createAccessorFunction(accessor) {
1806  	if (accessor === undefined)
1807  		return function (value) {
1808  			return trim(value);
1809  		};
1810  	if (typeof accessor === "function")
1811  		return function (value, index) {
1812  			return trim(accessor(value, index));
1813  		};
1814  	return function (value) {
1815  		return trim(value["" + accessor]);
1816  	};
1817  }
1818
1819  function createInterpreter(interpretations_array) {
1820  	if (!interpretations_array)
1821  		interpretations_array = DEFAULT_INTERPRETATIONS_ARRAY;
1822  	else if (!Array.isArray(interpretations_array))
1823  		interpretations_array = [interpretations_array];
1824
1825  	var interpretations = interpretations_array.reduce(function (
1826  		arr,
1827  		interp_string,
1828  	) {
1829  		var interps = INTERPRETATION_OPTIONS[interp_string];
1830  		if (interps) Array.prototype.push.apply(arr, interps);
1831  		return arr;
1832  	}, []);
1833
1834  	var include_string = interpretations_array.indexOf("string") !== -1;
1835
1836  	var options = OPTION_KEYS.reduce(function (obj, key) {
1837  		obj[key] = DEFAULT_OPTIONS[key];
1838  		return obj;
1839  	}, {});
1840
1841  	var interpreter = function (input_array, accessor) {
1842  		accessor = createAccessorFunction(accessor);
1843  		var data = input_array.map(accessor).filter(Boolean);
1844  		if (!data.length) return include_string ? [string_interpretation] : [];
1845  		var n = Math.min(options.n_max, data.length);
1846  		var n_max_failure = Math.floor(n * options.failure_fraction);
1847  		var n_failing_values = options.n_failing_values;
1848  		var sortMethod = options.sort ? sortBySuccess : noSort;
1849
1850  		var valid_interpreters = interpretations
1851  			.slice()
1852  			.reduce(function (keep, interp, index) {
1853  				var n_fail = (i = 0);
1854  				var failing_values = [];
1855  				var complete_failure = false;
1856
1857  				for (var i = 0; i < n; i++) {
1858  					var val = data[i];
1859  					var is_valid = interp.test(val);
1860  					if (is_valid) continue;
1861  					if (++n_fail > n_max_failure) complete_failure = true;
1862  					else if (failing_values.indexOf(val) === -1) {
1863  						failing_values.push(val);
1864  						if (failing_values.length > n_failing_values)
1865  							complete_failure = true;
1866  					}
1867  					if (complete_failure) break;
1868  				}
1869
1870  				if (!complete_failure)
1871  					keep.push({ interp: interp, n_success: n - n_fail, index: index });
1872
1873  				return keep;
1874  			}, [])
1875  			.sort(sortMethod)
1876  			.map(function (valid) {
1877  				return valid.interp;
1878  			});
1879
1880  		if (include_string) valid_interpreters.push(string_interpretation);
1881
1882  		return valid_interpreters;
1883  	};
1884
1885  	OPTION_KEYS.forEach(function (option) {
1886  		interpreter[snakeToCamel(option)] = function (value) {
1887  			if (value === undefined) return options[option];
1888  			options[option] = value;
1889  			return interpreter;
1890  		};
1891  	});
1892
1893  	return interpreter;
1894  }
1895
1896  createInterpreter.DATETIME_IDS = Object.freeze(
1897  	datetime_interpretations.concat(datetime_format_only).map(function (d) {
1898  		return d.id;
1899  	}),
1900  );
1901  createInterpreter.NUMBER_IDS = Object.freeze(
1902  	number_interpretations.map(function (d) {
1903  		return d.id;
1904  	}),
1905  );
1906  createInterpreter.STRING_IDS = Object.freeze([string_interpretation.id]);
1907  createInterpreter.DATETIME_FORMAT_ONLY_IDS = Object.freeze(
1908  	datetime_format_only.map(function (d) {
1909  		return d.id;
1910  	}),
1911  );
1912
1913  createInterpreter.getInterpretation = (function () {
1914  	var interpretations = datetime_interpretations.concat(
1915  		datetime_format_only,
1916  		number_interpretations,
1917  		string_interpretation,
1918  	);
1919  	var lookup = interpretations.reduce(function (l, d) {
1920  		l[d.id] = d;
1921  		return l;
1922  	}, {});
1923  	return function (id) {
1924  		return lookup[id];
1925  	};
1926  })();
1927
1928  createInterpreter._createAccessorFunction = createAccessorFunction;
1929
1930  // Polyfills for IE11 and Edge
1931
1932  // Add findIndex method to Array
1933  // https://tc39.github.io/ecma262/#sec-array.prototype.findindex
1934  if (!Array.prototype.findIndex) {
1935  	Object.defineProperty(Array.prototype, "findIndex", {
1936  		value: function(predicate) {
1937  			if (this == null) {
1938  				throw new TypeError("this is null or not defined");
1939  			}
1940  			var o = Object(this);
1941  			var len = o.length >>> 0;
1942  			if (typeof predicate !== "function") {
1943  				throw new TypeError("predicate must be a function");
1944  			}
1945  			var this_arg = arguments[1];
1946  			var k = 0;
1947  			while (k < len) {
1948  				var k_value = o[k];
1949  				if (predicate.call(this_arg, k_value, k, o)) {
1950  					return k;
1951  				}
1952  				k++;
1953  			}
1954  			return -1;
1955  		},
1956  		configurable: true,
1957  		writable: true,
1958  	});
1959  }
1960
1961  // Returns a random seeded sample of column values based on the column length.
1962  // The sample is consistent and will update if the length of column changes.
1963  function getRandomSeededSample(column, sample_size) {
1964      if (column.length <= sample_size * 2) {
1965          return column;
1966      }
1967      const rng = mulberry32(column.length);
1968      while (column.length > sample_size) {
1969          const random_index = Math.floor(rng() * column.length);
1970          column.splice(random_index, 1);
1971      }
1972      return column;
1973  }
1974  // Seeded RNG implementation taken from https://github.com/bryc/code/blob/master/jshash/PRNGs.md#mulberry32
1975  function mulberry32(seed) {
1976      let a = seed;
1977      return function () {
1978          a |= 0;
1979          a = a + 0x6D2B79F5 | 0;
1980          var t = Math.imul(a ^ a >>> 15, 1 | a);
1981          t = t + Math.imul(t ^ t >>> 7, 61 | t) ^ t;
1982          return ((t ^ t >>> 14) >>> 0) / 4294967296;
1983      };
1984  }
1985  function trimTrailingEmptyRows(data) {
1986      for (var i = data.length; i-- > 1;) {
1987          if (!data[i] || !data[i].length || (Array.isArray(data[i]) && data[i].findIndex(function (col) { return col !== null && col !== ""; }) == -1)) {
1988              data.splice(i, 1);
1989          }
1990          else {
1991              break;
1992          }
1993      }
1994      return data;
1995  }
1996  /**
1997   * Takes an array of arrays (typically tabular data) and rewrites
1998   * it so that:
1999   *   - Any trailing empty rows are removed
2000   *   - Any cell that was not a string is stringified
2001   *   - Any leading or trailing whitespace of a cell is removed
2002   *
2003   * (The potentially modified table is returned to match the convention
2004   * used by functions this is replacing, although (TODO) I think it
2005   * would be more obvious that this function has side-effects if it
2006   * did not return the table and the calling code was changed.)
2007   *
2008   * @param {any[][]} data
2009   * @returns {string[][]}
2010   */
2011  function tidyTable(data) {
2012      trimTrailingEmptyRows(data);
2013      for (let row of data) {
2014          for (let i = 0; i < row.length; i++) {
2015              let value = row[i];
2016              // Convert null or undefined values to the empty string
2017              if (value == null) {
2018                  value = "";
2019              }
2020              // If the value is not a string, convert it to one
2021              if (typeof value !== "string") {
2022                  value = "" + value;
2023              }
2024              if (typeof value !== "string") {
2025                  throw new Error("BUG: somehow value was not a string");
2026              }
2027              // Now value is a definitely a string, strip any leading
2028              // or trailing whitespace.
2029              row[i] = value.trim();
2030          }
2031      }
2032      // TypeScript can't infer that the returned data is definitely all
2033      // strings so use a cast.
2034      return data;
2035  }
2036  var ERROR_STRINGS = ["#DIV/0", "#N/A", "#NAME?", "#NULL!", "#NUM!", "#REF!", "#VALUE!", "#ERROR!"];
2037  var interpreter = createInterpreter().nMax(Infinity).nFailingValues(8).failureFraction(0.1);
2038  function stripCommonFixes(str) {
2039      str = str || "";
2040      return str.replace(/[€£$¥%º]/g, "");
2041  }
2042  function getSlicedData(arr) {
2043      const n = arr.length;
2044      if (n > 100) {
2045          return arr.slice(10, n - 10);
2046      }
2047      if (n > 50) {
2048          return arr.slice(5, n - 5);
2049      }
2050      if (n > 30) {
2051          return arr.slice(4, n - 4);
2052      }
2053      if (n > 20) {
2054          return arr.slice(3, n - 3);
2055      }
2056      if (n > 10) {
2057          return arr.slice(2, n - 2);
2058      }
2059      if (n > 1) {
2060          return arr.slice(1, n);
2061      }
2062      return arr.slice(0, 1);
2063  }
2064  function interpretColumn$1(arr) {
2065      var idata = arr.filter(function (d) {
2066          return d && !ERROR_STRINGS.includes(d.trim());
2067      })
2068          .map(stripCommonFixes);
2069      return interpreter(idata);
2070  }
2071
2072  createInterpreter.STRING_IDS[0];
2073
2074  function _defineProp(prop, getter, setter) {
2075  	var gs = {};
2076  	if (getter) { gs.get = getter; }
2077  	if (setter) { gs.set = setter; }
2078  	Object.defineProperty(this, prop, gs);
2079  }
2080
2081  function interpretColumn(d, i, column_type_from_backend) {
2082  	var type_id, interpretation, output_format_id, data, index, starting_index;
2083  	column_type_from_backend = column_type_from_backend || {};
2084
2085  	var setData = function(d) {
2086  		// If there are fewer than 10 rows in the data table,
2087  		// there will be rows of null values at the end.
2088  		data = d.map(x => x === null ? "" : x);
2089  	};
2090
2091  	var setIndex = function(i) {
2092  		index = i;
2093  	};
2094
2095  	function setStartingIndex(i, saved_col_type) {
2096  		if (saved_col_type !== undefined && saved_col_type.hasOwnProperty("starting_index")) {
2097  			starting_index = saved_col_type.starting_index;
2098  		}
2099  		else {
2100  			starting_index = i;
2101  		}
2102  	}
2103
2104  	var setInterpretation = function(input_id, output_id) {
2105  		if (!input_id) {
2106  			const SAMPLE_SIZE = 1000;
2107  			const sliced_data = getSlicedData(data);
2108  			let sample_data;
2109  			if (sliced_data.length > (SAMPLE_SIZE * 2)) { sample_data = getRandomSeededSample(sliced_data, SAMPLE_SIZE); }
2110  			else { sample_data = sliced_data; }
2111  			type_id = interpretColumn$1(sample_data)[0].id;
2112  		}
2113  		else { type_id = input_id; }
2114
2115  		interpretation = createInterpreter.getInterpretation(type_id);
2116  		output_format_id = output_id || input_id;
2117
2118  		// If on upload input doesn't contain thousand separators, overwrite output format id
2119  		// to have thousands separators
2120  		if (!input_id && !output_id) {
2121  			if (interpretation.id == "number$none_comma") { output_format_id = "number$point_comma"; }
2122  			else if (interpretation.id == "number$none_point") { output_format_id = "number$comma_point"; }
2123  		}
2124  	};
2125
2126  	var getParsedValues = function() {
2127  		return data.slice(1).map(function(d) {
2128  			var string_value = interpretation.type == "number" ? stripCommonFixes(d) : d;
2129  			return interpretation.parse(string_value);
2130  		});
2131  	};
2132
2133  	setData(d);
2134  	setIndex(i);
2135  	setStartingIndex(i, column_type_from_backend);
2136  	setInterpretation(column_type_from_backend.type_id, column_type_from_backend.output_format_id);
2137
2138  	var obj = {};
2139  	obj.setData = setData;
2140  	obj.setIndex = setIndex;
2141  	obj.setStartingIndex = setStartingIndex;
2142  	obj.setInterpretation = setInterpretation;
2143
2144  	var defineProp = _defineProp.bind(obj);
2145  	defineProp("type", function() { return type_id.split("$")[0]; });
2146  	defineProp("type_id", function() { return type_id; });
2147  	defineProp("output_format_id", function() { return output_format_id; });
2148  	defineProp("index", function() { return index; });
2149  	defineProp("header", function() { return data[0]; });
2150  	defineProp("values", function() { return getParsedValues(); });
2151  	// Assign a starting_index to each column representing the column's visual index when the data sheet is rendered.
2152  	// HoT uses this to render the correct headers for each column when column(s) are dragged and dropped. It has no purpose
2153  	// other than to make sure the column headers render correctly.
2154  	defineProp("starting_index", function() { return starting_index; });
2155
2156  	return obj;
2157  }
2158
2159  self.onmessage = event => {
2160      const { column, i, saved_column_type } = event.data.data;
2161      const trimmed_column = tidyTable([column])[0];
2162      const interpreted_column = interpretColumn(trimmed_column, i, saved_column_type);
2163      const interpreter = createInterpreter.getInterpretation(interpreted_column.type_id);
2164      const parsed_column = trimmed_column.slice(1).map(d => {
2165          var string_value = (interpreter && interpreter.type == "number") ? stripCommonFixes(d) : d;
2166          return interpreter.parse(string_value || "");
2167      });
2168      const column_type = {
2169          index: i,
2170          type: interpreted_column.type_id.split("$")[0],
2171          type_id: interpreted_column.type_id,
2172          output_format_id: interpreted_column.output_format_id,
2173          header: trimmed_column[0],
2174          values: parsed_column,
2175          starting_index: interpreted_column.starting_index,
2176          column: trimmed_column,
2177      };
2178      self.postMessage(column_type);
2179  };
2180
2181})();
2182//# sourceMappingURL=interpreter_worker.js.map

Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.