Initial import from local backup (Documents-Playground/pakerpale)

This commit is contained in:
jeonghwa
2026-07-03 05:27:29 +09:00
commit d918e2eddc
2971 changed files with 264195 additions and 0 deletions

View File

@@ -0,0 +1,454 @@
function _typeof(obj) { if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); }
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } }
function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }
import RelativeTimeFormat from 'relative-time-format';
import Cache from './cache';
import grade from './grade';
import chooseLocale from './locale';
import { twitterStyle, timeStyle, defaultStyle } from './style';
import { addLocaleData, getLocaleData as _getLocaleData } from './LocaleDataStore'; // const EXTRA_STYLES = [
// 'long-convenient',
// 'long-time',
// 'short-convenient',
// 'short-time',
// 'tiny'
// ]
// Valid time units.
var UNITS = ['now', // The rest are the same as in `Intl.RelativeTimeFormat`.
'second', 'minute', 'hour', 'day', 'week', 'month', 'quarter', 'year'];
var JavascriptTimeAgo =
/*#__PURE__*/
function () {
/**
* @param {(string|string[])} locales=[] - Preferred locales (or locale).
*/
function JavascriptTimeAgo() {
var locales = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : [];
_classCallCheck(this, JavascriptTimeAgo);
// Convert `locales` to an array.
if (typeof locales === 'string') {
locales = [locales];
} // Choose the most appropriate locale
// (one of the previously added ones)
// based on the list of preferred `locales` supplied by the user.
this.locale = chooseLocale(locales.concat(RelativeTimeFormat.getDefaultLocale()), _getLocaleData); // Use `Intl.NumberFormat` for formatting numbers (when available).
if (typeof Intl !== 'undefined' && Intl.NumberFormat) {
this.numberFormat = new Intl.NumberFormat(this.locale);
} // Cache `Intl.RelativeTimeFormat` instance.
this.relativeTimeFormatCache = new Cache();
} // Formats the relative date/time.
//
// @return {string} Returns the formatted relative date/time.
//
// @param {(Object|string)} [style] - Relative date/time formatting style.
//
// @param {string[]} [style.units] - A list of allowed time units
// (e.g. ['second', 'minute', 'hour', …])
//
// @param {Function} [style.custom] - `function ({ elapsed, time, date, now })`.
// If this function returns a value, then
// the `.format()` call will return that value.
// Otherwise it has no effect.
//
// @param {string} [style.flavour] - e.g. "long", "short", "tiny", etc.
//
// @param {Object[]} [style.gradation] - Time scale gradation steps.
//
// @param {string} style.gradation[].unit - Time interval measurement unit.
// (e.g. ['second', 'minute', 'hour', …])
//
// @param {Number} style.gradation[].factor - Time interval measurement unit factor.
// (e.g. `60` for 'minute')
//
// @param {Number} [style.gradation[].granularity] - A step for the unit's "amount" value.
// (e.g. `5` for '0 minutes', '5 minutes', etc)
//
// @param {Number} [style.gradation[].threshold] - Time interval measurement unit threshold.
// (e.g. `45` seconds for 'minute').
// There can also be specific `threshold_[unit]`
// thresholds for fine-tuning.
//
_createClass(JavascriptTimeAgo, [{
key: "format",
value: function format(input) {
var style = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : defaultStyle;
if (typeof style === 'string') {
switch (style) {
case 'twitter':
style = twitterStyle;
break;
case 'time':
style = timeStyle;
break;
default:
style = defaultStyle;
}
}
var _getDateAndTimeBeingF = getDateAndTimeBeingFormatted(input),
date = _getDateAndTimeBeingF.date,
time = _getDateAndTimeBeingF.time; // Get locale messages for this formatting flavour
var _this$getLocaleData = this.getLocaleData(style.flavour),
flavour = _this$getLocaleData.flavour,
localeData = _this$getLocaleData.localeData; // Can pass a custom `now`, e.g. for testing purposes.
// Technically it doesn't belong to `style`
// but since this is an undocumented internal feature,
// taking it from the `style` argument will do (for now).
var now = style.now || Date.now(); // how much time elapsed (in seconds)
var elapsed = (now - time) / 1000; // in seconds
// `custom` A function of `{ elapsed, time, date, now, locale }`.
// If this function returns a value, then the `.format()` call will return that value.
// Otherwise the relative date/time is formatted as usual.
// This feature is currently not used anywhere and is here
// just for providing the ultimate customization point
// in case anyone would ever need that. Prefer using
// `gradation[step].format(value, locale)` instead.
//
// I guess `custom` is deprecated and will be removed
// in some future major version release.
//
if (style.custom) {
var custom = style.custom({
now: now,
date: date,
time: time,
elapsed: elapsed,
locale: this.locale
});
if (custom !== undefined) {
return custom;
}
} // Available time interval measurement units.
var units = getTimeIntervalMeasurementUnits(localeData, style.units); // If no available time unit is suitable, just output an empty string.
if (units.length === 0) {
console.error("Units \"".concat(units.join(', '), "\" were not found in locale data for \"").concat(this.locale, "\"."));
return '';
} // Choose the appropriate time measurement unit
// and get the corresponding rounded time amount.
var step = grade(elapsed, now, units, style.gradation); // If no time unit is suitable, just output an empty string.
// E.g. when "now" unit is not available
// and "second" has a threshold of `0.5`
// (e.g. the "canonical" grading scale).
if (!step) {
return '';
}
if (step.format) {
return step.format(date || time, this.locale);
}
var unit = step.unit,
factor = step.factor,
granularity = step.granularity;
var amount = Math.abs(elapsed) / factor; // Apply granularity to the time amount
// (and fallback to the previous step
// if the first level of granularity
// isn't met by this amount)
if (granularity) {
// Recalculate the elapsed time amount based on granularity
amount = Math.round(amount / granularity) * granularity;
} // `Intl.RelativeTimeFormat` doesn't operate in "now" units.
if (unit === 'now') {
return getNowMessage(localeData, -1 * Math.sign(elapsed));
}
switch (flavour) {
case 'long':
case 'short':
case 'narrow':
// Format `value` using `Intl.RelativeTimeFormat`.
return this.getFormatter(flavour).format(-1 * Math.sign(elapsed) * Math.round(amount), unit);
default:
// Format `value`.
// (mimicks `Intl.RelativeTimeFormat` with the addition of extra styles)
return this.formatValue(-1 * Math.sign(elapsed) * Math.round(amount), unit, localeData);
}
}
/**
* Mimicks what `Intl.RelativeTimeFormat` does for additional locale styles.
* @param {number} value
* @param {string} unit
* @param {object} localeData — Relative time messages for the flavor.
* @return {string}
*/
}, {
key: "formatValue",
value: function formatValue(value, unit, localeData) {
return this.getRule(value, unit, localeData).replace('{0}', this.formatNumber(Math.abs(value)));
}
/**
* Returns formatting rule for `value` in `units` (either in past or in future).
* @param {number} value - Time interval value.
* @param {string} unit - Time interval measurement unit.
* @param {object} localeData — Relative time messages for the flavor.
* @return {string}
* @example
* // Returns "{0} days ago"
* getRule(-2, "day")
*/
}, {
key: "getRule",
value: function getRule(value, unit, localeData) {
var unitRules = localeData[unit]; // Bundle size optimization technique.
if (typeof unitRules === 'string') {
return unitRules;
} // Choose either "past" or "future" based on time `value` sign.
// If "past" is same as "future" then they're stored as "other".
// If there's only "other" then it's being collapsed.
var quantifierRules = unitRules[value <= 0 ? 'past' : 'future'] || unitRules; // Bundle size optimization technique.
if (typeof quantifierRules === 'string') {
return quantifierRules;
} // Quantify `value`.
var quantify = _getLocaleData(this.locale).quantify;
var quantifier = quantify && quantify(Math.abs(value)); // There seems to be no such locale in CLDR
// for which `quantify` is missing
// and still `past` and `future` messages
// contain something other than "other".
/* istanbul ignore next */
quantifier = quantifier || 'other'; // "other" rule is supposed to always be present.
// If only "other" rule is present then "rules" is not an object and is a string.
return quantifierRules[quantifier] || quantifierRules.other;
}
/**
* Formats a number into a string.
* Uses `Intl.NumberFormat` when available.
* @param {number} number
* @return {string}
*/
}, {
key: "formatNumber",
value: function formatNumber(number) {
return this.numberFormat ? this.numberFormat.format(number) : String(number);
}
/**
* Returns an `Intl.RelativeTimeFormat` for a given `flavor`.
* @param {string} flavor
* @return {object} `Intl.RelativeTimeFormat` instance
*/
}, {
key: "getFormatter",
value: function getFormatter(flavor) {
// `Intl.RelativeTimeFormat` instance creation is assumed a
// lengthy operation so the instances are cached and reused.
return this.relativeTimeFormatCache.get(this.locale, flavor) || this.relativeTimeFormatCache.put(this.locale, flavor, new RelativeTimeFormat(this.locale, {
style: flavor
}));
}
/**
* Gets locale messages for this formatting flavour
*
* @param {(string|string[])} flavour - Relative date/time formatting flavour.
* If it's an array then all flavours are tried in order.
*
* @returns {Object} Returns an object of shape { flavour, localeData }
*/
}, {
key: "getLocaleData",
value: function getLocaleData() {
var flavour = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : [];
// Get relative time formatting rules for this locale
var localeData = _getLocaleData(this.locale); // Convert `flavour` to an array.
if (typeof flavour === 'string') {
flavour = [flavour];
} // "long" flavour is the default one.
// (it's always present)
flavour = flavour.concat('long'); // Find a suitable flavour.
for (var _iterator = flavour, _isArray = Array.isArray(_iterator), _i = 0, _iterator = _isArray ? _iterator : _iterator[Symbol.iterator]();;) {
var _ref;
if (_isArray) {
if (_i >= _iterator.length) break;
_ref = _iterator[_i++];
} else {
_i = _iterator.next();
if (_i.done) break;
_ref = _i.value;
}
var _ = _ref;
if (localeData[_]) {
return {
flavour: _,
localeData: localeData[_]
};
}
} // Can't happen - "long" flavour is always present.
// throw new Error(`None of the flavours - ${flavour.join(', ')} - was found for locale "${this.locale}".`)
}
}]);
return JavascriptTimeAgo;
}();
/**
* Gets default locale.
* @return {string} locale
*/
export { JavascriptTimeAgo as default };
JavascriptTimeAgo.getDefaultLocale = RelativeTimeFormat.getDefaultLocale;
/**
* Sets default locale.
* @param {string} locale
*/
JavascriptTimeAgo.setDefaultLocale = RelativeTimeFormat.setDefaultLocale;
/**
* Adds locale data for a specific locale.
* @param {Object} localeData
*/
JavascriptTimeAgo.addLocale = function (localeData) {
addLocaleData(localeData);
RelativeTimeFormat.addLocale(localeData);
};
/**
* (legacy alias)
* Adds locale data for a specific locale.
* @param {Object} localeData
* @deprecated
*/
JavascriptTimeAgo.locale = JavascriptTimeAgo.addLocale; // Normalizes `.format()` `time` argument.
function getDateAndTimeBeingFormatted(input) {
if (input.constructor === Date || isMockedDate(input)) {
return {
date: input,
time: input.getTime()
};
}
if (typeof input === 'number') {
return {
time: input // `date` is not required for formatting
// relative times unless "twitter" preset is used.
// date : new Date(input)
};
} // For some weird reason istanbul doesn't see this `throw` covered.
/* istanbul ignore next */
throw new Error("Unsupported relative time formatter input: ".concat(_typeof(input), ", ").concat(input));
} // During testing via some testing libraries `Date`s aren't actually `Date`s.
// https://github.com/catamphetamine/javascript-time-ago/issues/22
function isMockedDate(object) {
return _typeof(object) === 'object' && typeof object.getTime === 'function';
} // Get available time interval measurement units.
function getTimeIntervalMeasurementUnits(localeData, restrictedSetOfUnits) {
// All available time interval measurement units.
var units = Object.keys(localeData); // If only a specific set of available
// time measurement units can be used.
if (restrictedSetOfUnits) {
// Reduce available time interval measurement units
// based on user's preferences.
units = restrictedSetOfUnits.filter(function (_) {
return units.indexOf(_) >= 0;
});
} // Stock `Intl.RelativeTimeFormat` locale data doesn't have "now" units.
// So either "now" is present in extended locale data
// or it's taken from ".second.current".
if ((!restrictedSetOfUnits || restrictedSetOfUnits.indexOf('now') >= 0) && units.indexOf('now') < 0) {
if (localeData.second.current) {
units.unshift('now');
}
}
return units;
}
function getNowMessage(localeData, value) {
// Specific "now" message form extended locale data (if present).
if (localeData.now) {
// Bundle size optimization technique.
if (typeof localeData.now === 'string') {
return localeData.now;
} // Not handling `value === 0` as `localeData.now.current` here
// because it wouldn't make sense: "now" is a moment,
// so one can't possibly differentiate between a
// "previous" moment, a "current" moment and a "next moment".
// It can only be differentiated between "past" and "future".
if (value <= 0) {
return localeData.now.past;
} else {
return localeData.now.future;
}
} // Use ".second.current" as "now" message.
return localeData.second.current; // If this function was called then
// it means that either "now" unit messages are
// available or ".second.current" message is present.
}
//# sourceMappingURL=JavascriptTimeAgo.js.map

File diff suppressed because one or more lines are too long

View File

@@ -0,0 +1,248 @@
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; var ownKeys = Object.keys(source); if (typeof Object.getOwnPropertySymbols === 'function') { ownKeys = ownKeys.concat(Object.getOwnPropertySymbols(source).filter(function (sym) { return Object.getOwnPropertyDescriptor(source, sym).enumerable; })); } ownKeys.forEach(function (key) { _defineProperty(target, key, source[key]); }); } return target; }
function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
import JavascriptTimeAgo from '../source/JavascriptTimeAgo';
import { day, month, year } from '../source/gradation';
import { defaultStyle } from '../source/style';
import { getLocaleData } from '../source/LocaleDataStore'; // Load locale specific relative date/time messages
import english from '../locale/en'; // Just so this function code is covered.
JavascriptTimeAgo.setDefaultLocale('en');
describe("time ago", function () {
it("should try various flavours if some are not found", function () {
var timeAgo = new JavascriptTimeAgo('en');
timeAgo.format(Date.now(), {
flavour: ['exotic', 'short']
}).should.equal('now');
});
it("should not use Intl.NumberFormat if it's not available", function () {
var NumberFormat = Intl.NumberFormat;
delete Intl.NumberFormat;
var timeAgo = new JavascriptTimeAgo('en');
timeAgo.format(Date.now() + 60 * 1000).should.equal('in a minute');
Intl.NumberFormat = NumberFormat;
});
it("should work when \"past\"/\"future\" messages are same for all quantifiers", function () {
var timeAgo = new JavascriptTimeAgo('en');
timeAgo.format(Date.now() + 365 * 24 * 60 * 60 * 1000, {
flavour: ['short-convenient']
}).should.equal('in 1 yr.');
});
it("should work when \"now\" is a string (doesn't differentiate between \"past\" and \"future\")", function () {
var timeAgo = new JavascriptTimeAgo('en');
timeAgo.format(Date.now(), {
flavour: ['short-time']
}).should.equal('now');
});
it("should format \"now\" for \"past\" time", function () {
var timeAgo = new JavascriptTimeAgo('en');
timeAgo.format(Date.now() + 10, {
flavour: ['long-convenient']
}).should.equal('in a moment');
});
it("should accept a string style argument", function () {
var timeAgo = new JavascriptTimeAgo('en');
timeAgo.format(Date.now(), 'twitter').should.equal('');
timeAgo.format(Date.now(), 'time').should.equal('just now');
timeAgo.format(Date.now(), 'exotic').should.equal('just now');
});
it("should accept empty constructor parameters", function () {
var timeAgo = new JavascriptTimeAgo();
timeAgo.format(new Date()).should.equal('just now');
});
it("should accept Dates", function () {
var timeAgo = new JavascriptTimeAgo('en');
timeAgo.format(new Date()).should.equal('just now');
});
it("should accept mocked Dates when testing", function () {
var timeAgo = new JavascriptTimeAgo('en');
var mockedDate = {
getTime: function getTime() {
return Date.now();
}
};
timeAgo.format(mockedDate).should.equal('just now');
});
it("should not accept anything but Dates and timestamps", function () {
var timeAgo = new JavascriptTimeAgo('en');
var thrower = function thrower() {
return timeAgo.format('Jan 14, 2017');
};
thrower.should.throw('Unsupported relative time formatter input: string, Jan 14, 2017');
});
it("should return an empty string if the passed units are not available in locale data", function () {
var timeAgo = new JavascriptTimeAgo('en');
timeAgo.format(Date.now(), {
units: ['femtosecond']
}).should.equal('');
});
it("should return an empty string if no unit is suitable", function () {
var timeAgo = new JavascriptTimeAgo('en');
var now = Date.now(); // Remove 'now' unit formatting rule temporarily
var justNowFormatter = getLocaleData('en').long.now;
var currentSecondMessage = getLocaleData('en').long.second.current;
delete getLocaleData('en').long.now;
delete getLocaleData('en').long.second.current;
timeAgo.format(now, {
now: now
}).should.equal(''); // Restore 'now' unit formating rule
getLocaleData('en').long.now = justNowFormatter;
getLocaleData('en').long.second.current = currentSecondMessage;
});
it("should format for a style with \"custom\" function", function () {
var timeAgo = new JavascriptTimeAgo('en'); // `custom` returns a string
timeAgo.format(Date.now(), {
custom: function custom(_ref) {
var now = _ref.now,
time = _ref.time,
date = _ref.date,
locale = _ref.locale;
return locale;
}
}).should.equal('en'); // `custom` returns `undefined`
timeAgo.format(Date.now(), {
custom: function custom(_ref2) {
var now = _ref2.now,
time = _ref2.time,
date = _ref2.date,
locale = _ref2.locale;
return;
}
}).should.equal('now');
});
it("should format time correctly for English language (short)", function () {
convenientGradationTest(['now', '1 min. ago', '2 min. ago', '5 min. ago', '10 min. ago', '15 min. ago', '20 min. ago', '25 min. ago', '30 min. ago', '35 min. ago', '40 min. ago', '45 min. ago', '50 min. ago', '1 hr. ago', '2 hr. ago', '3 hr. ago', '4 hr. ago', '5 hr. ago', '6 hr. ago', '7 hr. ago', '8 hr. ago', '9 hr. ago', '10 hr. ago', '11 hr. ago', '12 hr. ago', '13 hr. ago', '14 hr. ago', '15 hr. ago', '16 hr. ago', '17 hr. ago', '18 hr. ago', '19 hr. ago', '20 hr. ago', '1 day ago', '2 days ago', '3 days ago', '4 days ago', '5 days ago', '1 wk. ago', '2 wk. ago', '3 wk. ago', '1 mo. ago', '2 mo. ago', '3 mo. ago', '4 mo. ago', '5 mo. ago', '6 mo. ago', '7 mo. ago', '8 mo. ago', '9 mo. ago', '9 mo. ago', '10 mo. ago', '1 yr. ago', '2 yr. ago', '3 yr. ago', '100 yr. ago'], 'en', {
flavour: 'short'
});
});
it("should format time correctly for English language (long)", function () {
convenientGradationTest(['just now', 'a minute ago', '2 minutes ago', '5 minutes ago', '10 minutes ago', '15 minutes ago', '20 minutes ago', '25 minutes ago', '30 minutes ago', '35 minutes ago', '40 minutes ago', '45 minutes ago', '50 minutes ago', 'an hour ago', '2 hours ago', '3 hours ago', '4 hours ago', '5 hours ago', '6 hours ago', '7 hours ago', '8 hours ago', '9 hours ago', '10 hours ago', '11 hours ago', '12 hours ago', '13 hours ago', '14 hours ago', '15 hours ago', '16 hours ago', '17 hours ago', '18 hours ago', '19 hours ago', '20 hours ago', 'a day ago', '2 days ago', '3 days ago', '4 days ago', '5 days ago', 'a week ago', '2 weeks ago', '3 weeks ago', 'a month ago', '2 months ago', '3 months ago', '4 months ago', '5 months ago', '6 months ago', '7 months ago', '8 months ago', '9 months ago', '9 months ago', '10 months ago', 'a year ago', '2 years ago', '3 years ago', '100 years ago'], 'en', defaultStyle);
});
it("should format time correctly for Russian language (short)", function () {
convenientGradationTest(['сейчас', '1 мин. назад', '2 мин. назад', '5 мин. назад', '10 мин. назад', '15 мин. назад', '20 мин. назад', '25 мин. назад', '30 мин. назад', '35 мин. назад', '40 мин. назад', '45 мин. назад', '50 мин. назад', '1 ч. назад', '2 ч. назад', '3 ч. назад', '4 ч. назад', '5 ч. назад', '6 ч. назад', '7 ч. назад', '8 ч. назад', '9 ч. назад', '10 ч. назад', '11 ч. назад', '12 ч. назад', '13 ч. назад', '14 ч. назад', '15 ч. назад', '16 ч. назад', '17 ч. назад', '18 ч. назад', '19 ч. назад', '20 ч. назад', '1 дн. назад', '2 дн. назад', '3 дн. назад', '4 дн. назад', '5 дн. назад', '1 нед. назад', '2 нед. назад', '3 нед. назад', '1 мес. назад', '2 мес. назад', '3 мес. назад', '4 мес. назад', '5 мес. назад', '6 мес. назад', '7 мес. назад', '8 мес. назад', '9 мес. назад', '9 мес. назад', '10 мес. назад', '1 г. назад', '2 г. назад', '3 г. назад', '100 л. назад'], 'ru', {
flavour: 'short'
});
});
it("should format time correctly for Russian language (long)", function () {
convenientGradationTest(['только что', '1 минуту назад', '2 минуты назад', '5 минут назад', '10 минут назад', '15 минут назад', '20 минут назад', '25 минут назад', '30 минут назад', '35 минут назад', '40 минут назад', '45 минут назад', '50 минут назад', '1 час назад', '2 часа назад', '3 часа назад', '4 часа назад', '5 часов назад', '6 часов назад', '7 часов назад', '8 часов назад', '9 часов назад', '10 часов назад', '11 часов назад', '12 часов назад', '13 часов назад', '14 часов назад', '15 часов назад', '16 часов назад', '17 часов назад', '18 часов назад', '19 часов назад', '20 часов назад', '1 день назад', '2 дня назад', '3 дня назад', '4 дня назад', '5 дней назад', '1 неделю назад', '2 недели назад', '3 недели назад', '1 месяц назад', '2 месяца назад', '3 месяца назад', '4 месяца назад', '5 месяцев назад', '6 месяцев назад', '7 месяцев назад', '8 месяцев назад', '9 месяцев назад', '9 месяцев назад', '10 месяцев назад', '1 год назад', '2 года назад', '3 года назад', '100 лет назад'], 'ru', defaultStyle);
});
it("should format future dates", function () {
new JavascriptTimeAgo('en').format(Date.now() + 60 * 60 * 1000).should.equal('in an hour');
new JavascriptTimeAgo('ru').format(Date.now() + 45.1 * 1000).should.equal('через 1 минуту');
});
it("should have generated missing quantifier functions", function () {
new JavascriptTimeAgo('ccp').format(Date.now() + 60 * 1000).should.equal('1 𑄟𑄨𑄚𑄨𑄘𑄬');
});
it("should throw for non-existing locales", function () {
(function () {
return JavascriptTimeAgo.addLocale();
}).should.throw('No locale data passed');
});
});
export function convenientGradationTest(convenientGradationLabels, timeAgo) {
var style = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
if (typeof timeAgo === 'string') {
timeAgo = new JavascriptTimeAgo(timeAgo);
}
var now = Date.now();
var elapsed = function elapsed(time) {
return timeAgo.format(now - time * 1000, _objectSpread({
now: now
}, style));
};
if (convenientGradation.length !== convenientGradationLabels.length) {
throw new Error("Array length mismatch. Gradation steps: ".concat(convenientGradation.length, ", labels: ").concat(convenientGradationLabels.length));
}
var i = 0;
while (i < convenientGradation.length) {
for (var _iterator = convenientGradation[i], _isArray = Array.isArray(_iterator), _i = 0, _iterator = _isArray ? _iterator : _iterator[Symbol.iterator]();;) {
var _ref3;
if (_isArray) {
if (_i >= _iterator.length) break;
_ref3 = _iterator[_i++];
} else {
_i = _iterator.next();
if (_i.done) break;
_ref3 = _i.value;
}
var time = _ref3;
elapsed(time).should.equal(convenientGradationLabels[i]);
}
i++;
}
}
var convenientGradation = [// 'just now':
[0, 44.9], // 'a minute ago':
[45.1, 1.49 * 60], // '2 minutes ago':
[1.51 * 60, 2.49 * 60], // '5 minutes ago':
[2.51 * 60, 7.49 * 60], // '10 minutes ago':
[7.51 * 60, 12.49 * 60], // '15 minutes ago':
[12.51 * 60, 17.49 * 60], // '20 minutes ago':
[17.51 * 60, 22.49 * 60], // '25 minutes ago':
[22.51 * 60, 27.49 * 60], // '30 minutes ago':
[27.51 * 60, 32.49 * 60], // '35 minutes ago':
[32.51 * 60, 37.49 * 60], // '40 minutes ago':
[37.51 * 60, 42.49 * 60], // '45 minutes ago':
[42.51 * 60, 47.49 * 60], // '50 minutes ago':
[47.51 * 60, 52.49 * 60], // 'an hour ago':
[55.01 * 60, 1.49 * 60 * 60], // '2 hours ago':
[1.51 * 60 * 60, 2.49 * 60 * 60], // '3 hours ago':
[2.51 * 60 * 60, 3.49 * 60 * 60], // '4 hours ago':
[3.51 * 60 * 60, 4.49 * 60 * 60], // '5 hours ago':
[4.51 * 60 * 60, 5.49 * 60 * 60], // '6 hours ago':
[5.51 * 60 * 60, 6.49 * 60 * 60], // '7 hours ago':
[6.51 * 60 * 60, 7.49 * 60 * 60], // '8 hours ago':
[7.51 * 60 * 60, 8.49 * 60 * 60], // '9 hours ago':
[8.51 * 60 * 60, 9.49 * 60 * 60], // '10 hours ago':
[9.51 * 60 * 60, 10.49 * 60 * 60], // '11 hours ago':
[10.51 * 60 * 60, 11.49 * 60 * 60], // '12 hours ago':
[11.51 * 60 * 60, 12.49 * 60 * 60], // '13 hours ago':
[12.51 * 60 * 60, 13.49 * 60 * 60], // '14 hours ago':
[13.51 * 60 * 60, 14.49 * 60 * 60], // '15 hours ago':
[14.51 * 60 * 60, 15.49 * 60 * 60], // '16 hours ago':
[15.51 * 60 * 60, 16.49 * 60 * 60], // '17 hours ago':
[16.51 * 60 * 60, 17.49 * 60 * 60], // '18 hours ago':
[17.51 * 60 * 60, 18.49 * 60 * 60], // '19 hours ago':
[18.51 * 60 * 60, 19.49 * 60 * 60], // '20 hours ago':
[19.51 * 60 * 60, 20.49 * 60 * 60], // 'a day ago':
[20.51 * 60 * 60, 1.49 * day], // '2 days ago':
[1.51 * day, 2.49 * day], // '3 days ago':
[2.51 * day, 3.49 * day], // '4 days ago':
[3.51 * day, 4.49 * day], // '5 days ago':
[4.51 * day, 5.49 * day], // 'a week ago':
[5.51 * day, 1.49 * 7 * day], // '2 weeks ago':
[1.51 * 7 * day, 2.49 * 7 * day], // '3 weeks ago':
[2.51 * 7 * day, 3.49 * 7 * day], // 'a month ago':
[3.51 * 7 * day, 1.49 * month], // '2 months ago':
[1.51 * month, 2.49 * month], // '3 months ago':
[2.51 * month, 3.49 * month], // '4 months ago':
[3.51 * month, 4.49 * month], // '5 months ago':
[4.51 * month, 5.49 * month], // '6 months ago':
[5.51 * month, 6.49 * month], // '7 months ago':
[6.51 * month, 7.49 * month], // '8 months ago':
[7.51 * month, 8.49 * month], // '9 months ago':
[8.51 * month, 8.99 * month], // '9 months ago':
[9.01 * month, 9.49 * month], // '10 months ago':
[9.51 * month, 10.49 * month], // 'a year ago':
[10.51 * month, 1.49 * year], // '2 years ago':
[1.51 * year, 2.49 * year], // '3 years ago':
[2.51 * year, 3.49 * year], // '100 years ago':
[99.51 * year, 100.49 * year]];
//# sourceMappingURL=JavascriptTimeAgo.test.js.map

File diff suppressed because one or more lines are too long

View File

@@ -0,0 +1,19 @@
// Fallback locale.
// (when not a single one of the supplied "preferred" locales is available)
var defaultLocale = 'en'; // For all locales added
// their relative time formatter messages will be stored here.
var localesData = {};
export function getLocaleData(locale) {
return localesData[locale];
}
export function addLocaleData(localeData) {
if (!localeData) {
throw new Error('[javascript-time-ago] No locale data passed.');
} // This locale data is stored in a global variable
// and later used when calling `.format(time)`.
localesData[localeData.locale] = localeData;
}
//# sourceMappingURL=LocaleDataStore.js.map

View File

@@ -0,0 +1 @@
{"version":3,"sources":["../source/LocaleDataStore.js"],"names":["defaultLocale","localesData","getLocaleData","locale","addLocaleData","localeData","Error"],"mappings":"AAAA;AACA;AACA,IAAIA,aAAa,GAAG,IAApB,C,CAEA;AACA;;AACA,IAAMC,WAAW,GAAG,EAApB;AAEA,OAAO,SAASC,aAAT,CAAuBC,MAAvB,EAA+B;AACrC,SAAOF,WAAW,CAACE,MAAD,CAAlB;AACA;AAED,OAAO,SAASC,aAAT,CAAuBC,UAAvB,EAAmC;AACzC,MAAI,CAACA,UAAL,EAAiB;AAChB,UAAM,IAAIC,KAAJ,CAAU,8CAAV,CAAN;AACA,GAHwC,CAIzC;AACA;;;AACAL,EAAAA,WAAW,CAACI,UAAU,CAACF,MAAZ,CAAX,GAAiCE,UAAjC;AACA","sourcesContent":["// Fallback locale.\r\n// (when not a single one of the supplied \"preferred\" locales is available)\r\nlet defaultLocale = 'en'\r\n\r\n// For all locales added\r\n// their relative time formatter messages will be stored here.\r\nconst localesData = {}\r\n\r\nexport function getLocaleData(locale) {\r\n\treturn localesData[locale]\r\n}\r\n\r\nexport function addLocaleData(localeData) {\r\n\tif (!localeData) {\r\n\t\tthrow new Error('[javascript-time-ago] No locale data passed.')\r\n\t}\r\n\t// This locale data is stored in a global variable\r\n\t// and later used when calling `.format(time)`.\r\n\tlocalesData[localeData.locale] = localeData\r\n}"],"file":"LocaleDataStore.js"}

22
node_modules/javascript-time-ago/modules/PropTypes.js generated vendored Normal file
View File

@@ -0,0 +1,22 @@
import { oneOfType, arrayOf, string, number, shape, func } from 'prop-types';
var threshold = oneOfType([number, func]);
var gradation = arrayOf(oneOfType([shape({
unit: string.isRequired,
factor: number,
granularity: number,
threshold: threshold // Specific `threshold_[unit]` properties may also be defined
}), shape({
format: func.isRequired,
threshold: threshold // Specific `threshold_[unit]` properties may also be defined
})])); // Date/time formatting style.
// E.g. 'twitter', 'fuzzy', or custom (`{ gradation: […], units: […], flavour: 'long', custom: function }`)
export var style = oneOfType([string, shape({
gradation: gradation,
units: arrayOf(string),
flavour: oneOfType([string, arrayOf(string)]),
custom: func
})]);
//# sourceMappingURL=PropTypes.js.map

View File

@@ -0,0 +1 @@
{"version":3,"sources":["../source/PropTypes.js"],"names":["oneOfType","arrayOf","string","number","shape","func","threshold","gradation","unit","isRequired","factor","granularity","format","style","units","flavour","custom"],"mappings":"AAAA,SACCA,SADD,EAECC,OAFD,EAGCC,MAHD,EAICC,MAJD,EAKCC,KALD,EAMCC,IAND,QAOO,YAPP;AASA,IAAMC,SAAS,GAAGN,SAAS,CAAC,CAC3BG,MAD2B,EAE3BE,IAF2B,CAAD,CAA3B;AAKA,IAAME,SAAS,GAAGN,OAAO,CAACD,SAAS,CAAC,CACnCI,KAAK,CAAC;AACLI,EAAAA,IAAI,EAAUN,MAAM,CAACO,UADhB;AAELC,EAAAA,MAAM,EAAQP,MAFT;AAGLQ,EAAAA,WAAW,EAAGR,MAHT;AAILG,EAAAA,SAAS,EAATA,SAJK,CAKL;;AALK,CAAD,CAD8B,EAQnCF,KAAK,CAAC;AACLQ,EAAAA,MAAM,EAAGP,IAAI,CAACI,UADT;AAELH,EAAAA,SAAS,EAATA,SAFK,CAGL;;AAHK,CAAD,CAR8B,CAAD,CAAV,CAAzB,C,CAeA;AACA;;AACA,OAAO,IAAMO,KAAK,GAAGb,SAAS,CAAC,CAC9BE,MAD8B,EAE9BE,KAAK,CAAC;AACLG,EAAAA,SAAS,EAATA,SADK;AAELO,EAAAA,KAAK,EAAKb,OAAO,CAACC,MAAD,CAFZ;AAGLa,EAAAA,OAAO,EAAGf,SAAS,CAAC,CACnBE,MADmB,EAEnBD,OAAO,CAACC,MAAD,CAFY,CAAD,CAHd;AAOLc,EAAAA,MAAM,EAAGX;AAPJ,CAAD,CAFyB,CAAD,CAAvB","sourcesContent":["import {\r\n\toneOfType,\r\n\tarrayOf,\r\n\tstring,\r\n\tnumber,\r\n\tshape,\r\n\tfunc\r\n} from 'prop-types'\r\n\r\nconst threshold = oneOfType([\r\n\tnumber,\r\n\tfunc\r\n])\r\n\r\nconst gradation = arrayOf(oneOfType([\r\n\tshape({\r\n\t\tunit : string.isRequired,\r\n\t\tfactor : number,\r\n\t\tgranularity : number,\r\n\t\tthreshold\r\n\t\t// Specific `threshold_[unit]` properties may also be defined\r\n\t}),\r\n\tshape({\r\n\t\tformat : func.isRequired,\r\n\t\tthreshold\r\n\t\t// Specific `threshold_[unit]` properties may also be defined\r\n\t})\r\n]))\r\n\r\n// Date/time formatting style.\r\n// E.g. 'twitter', 'fuzzy', or custom (`{ gradation: […], units: […], flavour: 'long', custom: function }`)\r\nexport const style = oneOfType([\r\n\tstring,\r\n\tshape({\r\n\t\tgradation,\r\n\t\tunits : arrayOf(string),\r\n\t\tflavour : oneOfType([\r\n\t\t\tstring,\r\n\t\t\tarrayOf(string)\r\n\t\t]),\r\n\t\tcustom : func\r\n\t})\r\n])"],"file":"PropTypes.js"}

77
node_modules/javascript-time-ago/modules/cache.js generated vendored Normal file
View File

@@ -0,0 +1,77 @@
function _typeof(obj) { if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); }
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } }
function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }
function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
/**
* A basic in-memory cache.
*
* import Cache from 'javascript-time-ago/Cache'
* const cache = new Cache()
* const object = cache.get('key1', 'key2', ...) || cache.put('key1', 'key2', ..., createObject())
*/
var Cache =
/*#__PURE__*/
function () {
function Cache() {
_classCallCheck(this, Cache);
_defineProperty(this, "cache", {});
}
_createClass(Cache, [{
key: "get",
value: function get() {
var cache = this.cache;
for (var _len = arguments.length, keys = new Array(_len), _key = 0; _key < _len; _key++) {
keys[_key] = arguments[_key];
}
for (var _i = 0; _i < keys.length; _i++) {
var key = keys[_i];
if (_typeof(cache) !== 'object') {
return;
}
cache = cache[key];
}
return cache;
}
}, {
key: "put",
value: function put() {
for (var _len2 = arguments.length, keys = new Array(_len2), _key2 = 0; _key2 < _len2; _key2++) {
keys[_key2] = arguments[_key2];
}
var value = keys.pop();
var lastKey = keys.pop();
var cache = this.cache;
for (var _i2 = 0; _i2 < keys.length; _i2++) {
var key = keys[_i2];
if (_typeof(cache[key]) !== 'object') {
cache[key] = {};
}
cache = cache[key];
}
return cache[lastKey] = value;
}
}]);
return Cache;
}();
export { Cache as default };
//# sourceMappingURL=cache.js.map

View File

@@ -0,0 +1 @@
{"version":3,"sources":["../source/cache.js"],"names":["Cache","cache","keys","key","value","pop","lastKey"],"mappings":";;;;;;;;;;AAAA;;;;;;;IAOqBA,K;;;;;;mCACZ,E;;;;;0BAEK;AACZ,UAAIC,KAAK,GAAG,KAAKA,KAAjB;;AADY,wCAANC,IAAM;AAANA,QAAAA,IAAM;AAAA;;AAEZ,4BAAkBA,IAAlB,eAAwB;AAAnB,YAAMC,GAAG,GAAID,IAAJ,IAAT;;AACJ,YAAI,QAAOD,KAAP,MAAiB,QAArB,EAA+B;AAC9B;AACA;;AACDA,QAAAA,KAAK,GAAGA,KAAK,CAACE,GAAD,CAAb;AACA;;AACD,aAAOF,KAAP;AACA;;;0BAEY;AAAA,yCAANC,IAAM;AAANA,QAAAA,IAAM;AAAA;;AACZ,UAAME,KAAK,GAAGF,IAAI,CAACG,GAAL,EAAd;AACA,UAAMC,OAAO,GAAGJ,IAAI,CAACG,GAAL,EAAhB;AACA,UAAIJ,KAAK,GAAG,KAAKA,KAAjB;;AACA,8BAAkBC,IAAlB,gBAAwB;AAAnB,YAAMC,GAAG,GAAID,IAAJ,KAAT;;AACJ,YAAI,QAAOD,KAAK,CAACE,GAAD,CAAZ,MAAsB,QAA1B,EAAoC;AACnCF,UAAAA,KAAK,CAACE,GAAD,CAAL,GAAa,EAAb;AACA;;AACDF,QAAAA,KAAK,GAAGA,KAAK,CAACE,GAAD,CAAb;AACA;;AACD,aAAOF,KAAK,CAACK,OAAD,CAAL,GAAiBF,KAAxB;AACA;;;;;;SAzBmBJ,K","sourcesContent":["/**\r\n * A basic in-memory cache.\r\n *\r\n * import Cache from 'javascript-time-ago/Cache'\r\n * const cache = new Cache()\r\n * const object = cache.get('key1', 'key2', ...) || cache.put('key1', 'key2', ..., createObject())\r\n */\r\nexport default class Cache {\r\n\tcache = {}\r\n\r\n\tget(...keys) {\r\n\t\tlet cache = this.cache\r\n\t\tfor (const key of keys) {\r\n\t\t\tif (typeof cache !== 'object') {\r\n\t\t\t\treturn\r\n\t\t\t}\r\n\t\t\tcache = cache[key]\r\n\t\t}\r\n\t\treturn cache\r\n\t}\r\n\r\n\tput(...keys) {\r\n\t\tconst value = keys.pop()\r\n\t\tconst lastKey = keys.pop()\r\n\t\tlet cache = this.cache\r\n\t\tfor (const key of keys) {\r\n\t\t\tif (typeof cache[key] !== 'object') {\r\n\t\t\t\tcache[key] = {}\r\n\t\t\t}\r\n\t\t\tcache = cache[key]\r\n\t\t}\r\n\t\treturn cache[lastKey] = value\r\n\t}\r\n}"],"file":"cache.js"}

12
node_modules/javascript-time-ago/modules/cache.test.js generated vendored Normal file
View File

@@ -0,0 +1,12 @@
import Cache from './cache';
describe('cache', function () {
it('should cache', function () {
var cache = new Cache();
var value = {};
expect(cache.get('123', '456')).to.be.undefined;
expect(cache.put('123', '456', value)).to.equal(value);
expect(cache.get('123', '456')).to.equal(value);
expect(cache.put('123', '789', 123)).to.equal(123);
});
});
//# sourceMappingURL=cache.test.js.map

View File

@@ -0,0 +1 @@
{"version":3,"sources":["../source/cache.test.js"],"names":["Cache","describe","it","cache","value","expect","get","to","be","undefined","put","equal"],"mappings":"AAAA,OAAOA,KAAP,MAAkB,SAAlB;AAEAC,QAAQ,CAAC,OAAD,EAAU,YAClB;AACCC,EAAAA,EAAE,CAAC,cAAD,EAAiB,YACnB;AACC,QAAMC,KAAK,GAAG,IAAIH,KAAJ,EAAd;AAEA,QAAMI,KAAK,GAAG,EAAd;AACAC,IAAAA,MAAM,CAACF,KAAK,CAACG,GAAN,CAAU,KAAV,EAAiB,KAAjB,CAAD,CAAN,CAAgCC,EAAhC,CAAmCC,EAAnC,CAAsCC,SAAtC;AACAJ,IAAAA,MAAM,CAACF,KAAK,CAACO,GAAN,CAAU,KAAV,EAAiB,KAAjB,EAAwBN,KAAxB,CAAD,CAAN,CAAuCG,EAAvC,CAA0CI,KAA1C,CAAgDP,KAAhD;AACAC,IAAAA,MAAM,CAACF,KAAK,CAACG,GAAN,CAAU,KAAV,EAAiB,KAAjB,CAAD,CAAN,CAAgCC,EAAhC,CAAmCI,KAAnC,CAAyCP,KAAzC;AAEAC,IAAAA,MAAM,CAACF,KAAK,CAACO,GAAN,CAAU,KAAV,EAAiB,KAAjB,EAAwB,GAAxB,CAAD,CAAN,CAAqCH,EAArC,CAAwCI,KAAxC,CAA8C,GAA9C;AACA,GAVC,CAAF;AAWA,CAbO,CAAR","sourcesContent":["import Cache from './cache'\r\n\r\ndescribe('cache', () =>\r\n{\r\n\tit('should cache', () =>\r\n\t{\r\n\t\tconst cache = new Cache()\r\n\r\n\t\tconst value = {}\r\n\t\texpect(cache.get('123', '456')).to.be.undefined\r\n\t\texpect(cache.put('123', '456', value)).to.equal(value)\r\n\t\texpect(cache.get('123', '456')).to.equal(value)\r\n\r\n\t\texpect(cache.put('123', '789', 123)).to.equal(123)\r\n\t})\r\n})\r\n"],"file":"cache.test.js"}

View File

@@ -0,0 +1,62 @@
import { day, month, year } from './helpers'; // just now
// 1 second ago
// 2 seconds ago
// …
// 59 seconds ago
// 1 minute ago
// 2 minutes ago
// …
// 59 minutes ago
// 1 hour ago
// 2 hours ago
// …
// 24 hours ago
// 1 day ago
// 2 days ago
// …
// 7 days ago
// 1 week ago
// 2 weeks ago
// …
// 3 weeks ago
// 1 month ago
// 2 months ago
// …
// 11 months ago
// 1 year ago
// 2 years ago
// …
export default [{
factor: 1,
unit: 'now'
}, {
threshold: 0.5,
factor: 1,
unit: 'second'
}, {
threshold: 59.5,
factor: 60,
unit: 'minute'
}, {
threshold: 59.5 * 60,
factor: 60 * 60,
unit: 'hour'
}, {
threshold: 23.5 * 60 * 60,
factor: day,
unit: 'day'
}, {
threshold: 6.5 * day,
factor: 7 * day,
unit: 'week'
}, {
threshold: 3.5 * 7 * day,
factor: month,
unit: 'month'
}, {
threshold: 11.5 * month,
factor: year,
unit: 'year'
}];
//# sourceMappingURL=canonical.js.map

View File

@@ -0,0 +1 @@
{"version":3,"sources":["../../source/gradation/canonical.js"],"names":["day","month","year","factor","unit","threshold"],"mappings":"AAAA,SAASA,GAAT,EAAcC,KAAd,EAAqBC,IAArB,QAAiC,WAAjC,C,CAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AACA,eACA,CACC;AACCC,EAAAA,MAAM,EAAE,CADT;AAECC,EAAAA,IAAI,EAAE;AAFP,CADD,EAKC;AACCC,EAAAA,SAAS,EAAE,GADZ;AAECF,EAAAA,MAAM,EAAE,CAFT;AAGCC,EAAAA,IAAI,EAAE;AAHP,CALD,EAUC;AACCC,EAAAA,SAAS,EAAE,IADZ;AAECF,EAAAA,MAAM,EAAE,EAFT;AAGCC,EAAAA,IAAI,EAAE;AAHP,CAVD,EAeC;AACCC,EAAAA,SAAS,EAAE,OAAO,EADnB;AAECF,EAAAA,MAAM,EAAE,KAAK,EAFd;AAGCC,EAAAA,IAAI,EAAE;AAHP,CAfD,EAoBC;AACCC,EAAAA,SAAS,EAAE,OAAO,EAAP,GAAY,EADxB;AAECF,EAAAA,MAAM,EAAEH,GAFT;AAGCI,EAAAA,IAAI,EAAE;AAHP,CApBD,EAyBC;AACCC,EAAAA,SAAS,EAAE,MAAML,GADlB;AAECG,EAAAA,MAAM,EAAE,IAAIH,GAFb;AAGCI,EAAAA,IAAI,EAAE;AAHP,CAzBD,EA8BC;AACCC,EAAAA,SAAS,EAAE,MAAM,CAAN,GAAUL,GADtB;AAECG,EAAAA,MAAM,EAAEF,KAFT;AAGCG,EAAAA,IAAI,EAAE;AAHP,CA9BD,EAmCC;AACCC,EAAAA,SAAS,EAAE,OAAOJ,KADnB;AAECE,EAAAA,MAAM,EAAED,IAFT;AAGCE,EAAAA,IAAI,EAAE;AAHP,CAnCD,CADA","sourcesContent":["import { day, month, year } from './helpers'\r\n\r\n// just now\r\n// 1 second ago\r\n// 2 seconds ago\r\n// …\r\n// 59 seconds ago\r\n// 1 minute ago\r\n// 2 minutes ago\r\n// …\r\n// 59 minutes ago\r\n// 1 hour ago\r\n// 2 hours ago\r\n// …\r\n// 24 hours ago\r\n// 1 day ago\r\n// 2 days ago\r\n// …\r\n// 7 days ago\r\n// 1 week ago\r\n// 2 weeks ago\r\n// …\r\n// 3 weeks ago\r\n// 1 month ago\r\n// 2 months ago\r\n// …\r\n// 11 months ago\r\n// 1 year ago\r\n// 2 years ago\r\n// …\r\nexport default\r\n[\r\n\t{\r\n\t\tfactor: 1,\r\n\t\tunit: 'now'\r\n\t},\r\n\t{\r\n\t\tthreshold: 0.5,\r\n\t\tfactor: 1,\r\n\t\tunit: 'second'\r\n\t},\r\n\t{\r\n\t\tthreshold: 59.5,\r\n\t\tfactor: 60,\r\n\t\tunit: 'minute'\r\n\t},\r\n\t{\r\n\t\tthreshold: 59.5 * 60,\r\n\t\tfactor: 60 * 60,\r\n\t\tunit: 'hour'\r\n\t},\r\n\t{\r\n\t\tthreshold: 23.5 * 60 * 60,\r\n\t\tfactor: day,\r\n\t\tunit: 'day'\r\n\t},\r\n\t{\r\n\t\tthreshold: 6.5 * day,\r\n\t\tfactor: 7 * day,\r\n\t\tunit: 'week'\r\n\t},\r\n\t{\r\n\t\tthreshold: 3.5 * 7 * day,\r\n\t\tfactor: month,\r\n\t\tunit: 'month'\r\n\t},\r\n\t{\r\n\t\tthreshold: 11.5 * month,\r\n\t\tfactor: year,\r\n\t\tunit: 'year'\r\n\t}\r\n]"],"file":"canonical.js"}

View File

@@ -0,0 +1,23 @@
import grade from '../grade';
import gradation from './canonical'; // Perhaps this should be part of `grade.test.js` instead.
describe('canonical gradation', function () {
it('should grade correctly', function () {
var test = function test(elapsed) {
return grade(elapsed, null, ['second', 'minute', 'hour', 'day', 'month', 'year'], gradation);
};
expect(test(0)).to.be.undefined;
expect(test(0.5).unit).to.equal('second');
expect(test(0.5).factor).to.equal(1);
expect(test(59.4).unit).to.equal('second');
expect(test(59.4).factor).to.equal(1);
expect(test(59.5).unit).to.equal('minute');
expect(test(59.5).factor).to.equal(60);
expect(test(59.5 * 60 - 1).unit).to.equal('minute');
expect(test(59.5 * 60 - 1).factor).to.equal(60);
expect(test(59.5 * 60).unit).to.equal('hour');
expect(test(59.5 * 60).factor).to.equal(60 * 60);
});
});
//# sourceMappingURL=canonical.test.js.map

View File

@@ -0,0 +1 @@
{"version":3,"sources":["../../source/gradation/canonical.test.js"],"names":["grade","gradation","describe","it","test","elapsed","expect","to","be","undefined","unit","equal","factor"],"mappings":"AAAA,OAAOA,KAAP,MAAkB,UAAlB;AACA,OAAOC,SAAP,MAAsB,aAAtB,C,CAEA;;AAEAC,QAAQ,CAAC,qBAAD,EAAwB,YAChC;AACCC,EAAAA,EAAE,CAAC,wBAAD,EAA2B,YAC7B;AACC,QAAMC,IAAI,GAAG,SAAPA,IAAO,CAACC,OAAD;AAAA,aAAaL,KAAK,CAACK,OAAD,EAAU,IAAV,EAAgB,CAC9C,QAD8C,EAE9C,QAF8C,EAG9C,MAH8C,EAI9C,KAJ8C,EAK9C,OAL8C,EAM9C,MAN8C,CAAhB,EAO5BJ,SAP4B,CAAlB;AAAA,KAAb;;AASAK,IAAAA,MAAM,CAACF,IAAI,CAAC,CAAD,CAAL,CAAN,CAAgBG,EAAhB,CAAmBC,EAAnB,CAAsBC,SAAtB;AAEAH,IAAAA,MAAM,CAACF,IAAI,CAAC,GAAD,CAAJ,CAAUM,IAAX,CAAN,CAAuBH,EAAvB,CAA0BI,KAA1B,CAAgC,QAAhC;AACAL,IAAAA,MAAM,CAACF,IAAI,CAAC,GAAD,CAAJ,CAAUQ,MAAX,CAAN,CAAyBL,EAAzB,CAA4BI,KAA5B,CAAkC,CAAlC;AAEAL,IAAAA,MAAM,CAACF,IAAI,CAAC,IAAD,CAAJ,CAAWM,IAAZ,CAAN,CAAwBH,EAAxB,CAA2BI,KAA3B,CAAiC,QAAjC;AACAL,IAAAA,MAAM,CAACF,IAAI,CAAC,IAAD,CAAJ,CAAWQ,MAAZ,CAAN,CAA0BL,EAA1B,CAA6BI,KAA7B,CAAmC,CAAnC;AAEAL,IAAAA,MAAM,CAACF,IAAI,CAAC,IAAD,CAAJ,CAAWM,IAAZ,CAAN,CAAwBH,EAAxB,CAA2BI,KAA3B,CAAiC,QAAjC;AACAL,IAAAA,MAAM,CAACF,IAAI,CAAC,IAAD,CAAJ,CAAWQ,MAAZ,CAAN,CAA0BL,EAA1B,CAA6BI,KAA7B,CAAmC,EAAnC;AAEAL,IAAAA,MAAM,CAACF,IAAI,CAAC,OAAO,EAAP,GAAY,CAAb,CAAJ,CAAoBM,IAArB,CAAN,CAAiCH,EAAjC,CAAoCI,KAApC,CAA0C,QAA1C;AACAL,IAAAA,MAAM,CAACF,IAAI,CAAC,OAAO,EAAP,GAAY,CAAb,CAAJ,CAAoBQ,MAArB,CAAN,CAAmCL,EAAnC,CAAsCI,KAAtC,CAA4C,EAA5C;AAEAL,IAAAA,MAAM,CAACF,IAAI,CAAC,OAAO,EAAR,CAAJ,CAAgBM,IAAjB,CAAN,CAA6BH,EAA7B,CAAgCI,KAAhC,CAAsC,MAAtC;AACAL,IAAAA,MAAM,CAACF,IAAI,CAAC,OAAO,EAAR,CAAJ,CAAgBQ,MAAjB,CAAN,CAA+BL,EAA/B,CAAkCI,KAAlC,CAAwC,KAAK,EAA7C;AACA,GA3BC,CAAF;AA4BA,CA9BO,CAAR","sourcesContent":["import grade from '../grade'\r\nimport gradation from './canonical'\r\n\r\n// Perhaps this should be part of `grade.test.js` instead.\r\n\r\ndescribe('canonical gradation', () =>\r\n{\r\n\tit('should grade correctly', () =>\r\n\t{\r\n\t\tconst test = (elapsed) => grade(elapsed, null, [\r\n\t\t\t'second',\r\n\t\t\t'minute',\r\n\t\t\t'hour',\r\n\t\t\t'day',\r\n\t\t\t'month',\r\n\t\t\t'year'\r\n\t\t], gradation)\r\n\r\n\t\texpect(test(0)).to.be.undefined\r\n\r\n\t\texpect(test(0.5).unit).to.equal('second')\r\n\t\texpect(test(0.5).factor).to.equal(1)\r\n\r\n\t\texpect(test(59.4).unit).to.equal('second')\r\n\t\texpect(test(59.4).factor).to.equal(1)\r\n\r\n\t\texpect(test(59.5).unit).to.equal('minute')\r\n\t\texpect(test(59.5).factor).to.equal(60)\r\n\r\n\t\texpect(test(59.5 * 60 - 1).unit).to.equal('minute')\r\n\t\texpect(test(59.5 * 60 - 1).factor).to.equal(60)\r\n\r\n\t\texpect(test(59.5 * 60).unit).to.equal('hour')\r\n\t\texpect(test(59.5 * 60).factor).to.equal(60 * 60)\r\n\t})\r\n})"],"file":"canonical.test.js"}

View File

@@ -0,0 +1,68 @@
import { day, month, year } from './helpers'; // just now
// 1 minute ago
// 2 minutes ago
// 5 minutes ago
// 10 minutes ago
// 15 minutes ago
// 20 minutes ago
// an hour ago
// 2 hours ago
// …
// 20 hours ago
// a day ago
// 2 days ago
// 5 days ago
// a week ago
// 2 weeks ago
// 3 weeks ago
// a month ago
// 2 months ago
// 4 months ago
// a year ago
// 2 years ago
// …
export default [{
factor: 1,
unit: 'now'
}, {
threshold: 1,
threshold_for_now: 45,
factor: 1,
unit: 'second'
}, {
threshold: 45,
factor: 60,
unit: 'minute'
}, {
threshold: 2.5 * 60,
factor: 60,
granularity: 5,
unit: 'minute'
}, {
threshold: 22.5 * 60,
factor: 30 * 60,
unit: 'half-hour'
}, {
threshold: 42.5 * 60,
threshold_for_minute: 52.5 * 60,
factor: 60 * 60,
unit: 'hour'
}, {
threshold: 20.5 / 24 * day,
factor: day,
unit: 'day'
}, {
threshold: 5.5 * day,
factor: 7 * day,
unit: 'week'
}, {
threshold: 3.5 * 7 * day,
factor: month,
unit: 'month'
}, {
threshold: 10.5 * month,
factor: year,
unit: 'year'
}];
//# sourceMappingURL=convenient.js.map

View File

@@ -0,0 +1 @@
{"version":3,"sources":["../../source/gradation/convenient.js"],"names":["day","month","year","factor","unit","threshold","threshold_for_now","granularity","threshold_for_minute"],"mappings":"AAAA,SAASA,GAAT,EAAcC,KAAd,EAAqBC,IAArB,QAAiC,WAAjC,C,CAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AACA,eACA,CACC;AACCC,EAAAA,MAAM,EAAE,CADT;AAECC,EAAAA,IAAI,EAAE;AAFP,CADD,EAKC;AACCC,EAAAA,SAAS,EAAE,CADZ;AAECC,EAAAA,iBAAiB,EAAE,EAFpB;AAGCH,EAAAA,MAAM,EAAE,CAHT;AAICC,EAAAA,IAAI,EAAE;AAJP,CALD,EAWC;AACCC,EAAAA,SAAS,EAAE,EADZ;AAECF,EAAAA,MAAM,EAAE,EAFT;AAGCC,EAAAA,IAAI,EAAE;AAHP,CAXD,EAgBC;AACCC,EAAAA,SAAS,EAAE,MAAM,EADlB;AAECF,EAAAA,MAAM,EAAE,EAFT;AAGCI,EAAAA,WAAW,EAAE,CAHd;AAICH,EAAAA,IAAI,EAAE;AAJP,CAhBD,EAsBC;AACCC,EAAAA,SAAS,EAAE,OAAO,EADnB;AAECF,EAAAA,MAAM,EAAE,KAAK,EAFd;AAGCC,EAAAA,IAAI,EAAE;AAHP,CAtBD,EA2BC;AACCC,EAAAA,SAAS,EAAE,OAAO,EADnB;AAECG,EAAAA,oBAAoB,EAAE,OAAO,EAF9B;AAGCL,EAAAA,MAAM,EAAE,KAAK,EAHd;AAICC,EAAAA,IAAI,EAAE;AAJP,CA3BD,EAiCC;AACCC,EAAAA,SAAS,EAAG,OAAO,EAAR,GAAcL,GAD1B;AAECG,EAAAA,MAAM,EAAEH,GAFT;AAGCI,EAAAA,IAAI,EAAE;AAHP,CAjCD,EAsCC;AACCC,EAAAA,SAAS,EAAE,MAAML,GADlB;AAECG,EAAAA,MAAM,EAAE,IAAIH,GAFb;AAGCI,EAAAA,IAAI,EAAE;AAHP,CAtCD,EA2CC;AACCC,EAAAA,SAAS,EAAE,MAAM,CAAN,GAAUL,GADtB;AAECG,EAAAA,MAAM,EAAEF,KAFT;AAGCG,EAAAA,IAAI,EAAE;AAHP,CA3CD,EAgDC;AACCC,EAAAA,SAAS,EAAE,OAAOJ,KADnB;AAECE,EAAAA,MAAM,EAAED,IAFT;AAGCE,EAAAA,IAAI,EAAE;AAHP,CAhDD,CADA","sourcesContent":["import { day, month, year } from './helpers'\r\n\r\n// just now\r\n// 1 minute ago\r\n// 2 minutes ago\r\n// 5 minutes ago\r\n// 10 minutes ago\r\n// 15 minutes ago\r\n// 20 minutes ago\r\n// an hour ago\r\n// 2 hours ago\r\n// …\r\n// 20 hours ago\r\n// a day ago\r\n// 2 days ago\r\n// 5 days ago\r\n// a week ago\r\n// 2 weeks ago\r\n// 3 weeks ago\r\n// a month ago\r\n// 2 months ago\r\n// 4 months ago\r\n// a year ago\r\n// 2 years ago\r\n// …\r\nexport default\r\n[\r\n\t{\r\n\t\tfactor: 1,\r\n\t\tunit: 'now'\r\n\t},\r\n\t{\r\n\t\tthreshold: 1,\r\n\t\tthreshold_for_now: 45,\r\n\t\tfactor: 1,\r\n\t\tunit: 'second'\r\n\t},\r\n\t{\r\n\t\tthreshold: 45,\r\n\t\tfactor: 60,\r\n\t\tunit: 'minute'\r\n\t},\r\n\t{\r\n\t\tthreshold: 2.5 * 60,\r\n\t\tfactor: 60,\r\n\t\tgranularity: 5,\r\n\t\tunit: 'minute'\r\n\t},\r\n\t{\r\n\t\tthreshold: 22.5 * 60,\r\n\t\tfactor: 30 * 60,\r\n\t\tunit: 'half-hour'\r\n\t},\r\n\t{\r\n\t\tthreshold: 42.5 * 60,\r\n\t\tthreshold_for_minute: 52.5 * 60,\r\n\t\tfactor: 60 * 60,\r\n\t\tunit: 'hour'\r\n\t},\r\n\t{\r\n\t\tthreshold: (20.5 / 24) * day,\r\n\t\tfactor: day,\r\n\t\tunit: 'day'\r\n\t},\r\n\t{\r\n\t\tthreshold: 5.5 * day,\r\n\t\tfactor: 7 * day,\r\n\t\tunit: 'week'\r\n\t},\r\n\t{\r\n\t\tthreshold: 3.5 * 7 * day,\r\n\t\tfactor: month,\r\n\t\tunit: 'month'\r\n\t},\r\n\t{\r\n\t\tthreshold: 10.5 * month,\r\n\t\tfactor: year,\r\n\t\tunit: 'year'\r\n\t}\r\n]"],"file":"convenient.js"}

View File

@@ -0,0 +1,31 @@
import grade from '../grade';
import gradation from './convenient'; // Perhaps this should be part of `grade.test.js` instead.
describe('convenient gradation', function () {
it('should grade correctly', function () {
var test = function test(elapsed) {
return grade(elapsed, null, ['second', 'minute', 'hour', 'day', 'month', 'year'], gradation);
};
expect(test(0)).to.be.undefined;
expect(test(1).unit).to.equal('second');
expect(test(1).factor).to.equal(1);
expect(test(44).unit).to.equal('second');
expect(test(44).factor).to.equal(1);
expect(test(45).unit).to.equal('minute');
expect(test(45).factor).to.equal(60);
expect(test(45).granularity).to.be.undefined;
expect(test(2.5 * 60 - 1).unit).to.equal('minute');
expect(test(2.5 * 60 - 1).factor).to.equal(60);
expect(test(2.5 * 60 - 1).granularity).to.be.undefined;
expect(test(2.5 * 60).unit).to.equal('minute');
expect(test(2.5 * 60).factor).to.equal(60);
expect(test(2.5 * 60).granularity).to.equal(5);
expect(test(52.5 * 60 - 1).unit).to.equal('minute');
expect(test(52.5 * 60 - 1).factor).to.equal(60);
expect(test(52.5 * 60 - 1).granularity).to.equal(5);
expect(test(52.5 * 60).unit).to.equal('hour');
expect(test(52.5 * 60).factor).to.equal(60 * 60);
});
});
//# sourceMappingURL=convenient.test.js.map

View File

@@ -0,0 +1 @@
{"version":3,"sources":["../../source/gradation/convenient.test.js"],"names":["grade","gradation","describe","it","test","elapsed","expect","to","be","undefined","unit","equal","factor","granularity"],"mappings":"AAAA,OAAOA,KAAP,MAAkB,UAAlB;AACA,OAAOC,SAAP,MAAsB,cAAtB,C,CAEA;;AAEAC,QAAQ,CAAC,sBAAD,EAAyB,YACjC;AACCC,EAAAA,EAAE,CAAC,wBAAD,EAA2B,YAC7B;AACC,QAAMC,IAAI,GAAG,SAAPA,IAAO,CAACC,OAAD;AAAA,aAAaL,KAAK,CAACK,OAAD,EAAU,IAAV,EAAgB,CAC9C,QAD8C,EAE9C,QAF8C,EAG9C,MAH8C,EAI9C,KAJ8C,EAK9C,OAL8C,EAM9C,MAN8C,CAAhB,EAO5BJ,SAP4B,CAAlB;AAAA,KAAb;;AASAK,IAAAA,MAAM,CAACF,IAAI,CAAC,CAAD,CAAL,CAAN,CAAgBG,EAAhB,CAAmBC,EAAnB,CAAsBC,SAAtB;AAEAH,IAAAA,MAAM,CAACF,IAAI,CAAC,CAAD,CAAJ,CAAQM,IAAT,CAAN,CAAqBH,EAArB,CAAwBI,KAAxB,CAA8B,QAA9B;AACAL,IAAAA,MAAM,CAACF,IAAI,CAAC,CAAD,CAAJ,CAAQQ,MAAT,CAAN,CAAuBL,EAAvB,CAA0BI,KAA1B,CAAgC,CAAhC;AAEAL,IAAAA,MAAM,CAACF,IAAI,CAAC,EAAD,CAAJ,CAASM,IAAV,CAAN,CAAsBH,EAAtB,CAAyBI,KAAzB,CAA+B,QAA/B;AACAL,IAAAA,MAAM,CAACF,IAAI,CAAC,EAAD,CAAJ,CAASQ,MAAV,CAAN,CAAwBL,EAAxB,CAA2BI,KAA3B,CAAiC,CAAjC;AAEAL,IAAAA,MAAM,CAACF,IAAI,CAAC,EAAD,CAAJ,CAASM,IAAV,CAAN,CAAsBH,EAAtB,CAAyBI,KAAzB,CAA+B,QAA/B;AACAL,IAAAA,MAAM,CAACF,IAAI,CAAC,EAAD,CAAJ,CAASQ,MAAV,CAAN,CAAwBL,EAAxB,CAA2BI,KAA3B,CAAiC,EAAjC;AACAL,IAAAA,MAAM,CAACF,IAAI,CAAC,EAAD,CAAJ,CAASS,WAAV,CAAN,CAA6BN,EAA7B,CAAgCC,EAAhC,CAAmCC,SAAnC;AAEAH,IAAAA,MAAM,CAACF,IAAI,CAAC,MAAM,EAAN,GAAW,CAAZ,CAAJ,CAAmBM,IAApB,CAAN,CAAgCH,EAAhC,CAAmCI,KAAnC,CAAyC,QAAzC;AACAL,IAAAA,MAAM,CAACF,IAAI,CAAC,MAAM,EAAN,GAAW,CAAZ,CAAJ,CAAmBQ,MAApB,CAAN,CAAkCL,EAAlC,CAAqCI,KAArC,CAA2C,EAA3C;AACAL,IAAAA,MAAM,CAACF,IAAI,CAAC,MAAM,EAAN,GAAW,CAAZ,CAAJ,CAAmBS,WAApB,CAAN,CAAuCN,EAAvC,CAA0CC,EAA1C,CAA6CC,SAA7C;AAEAH,IAAAA,MAAM,CAACF,IAAI,CAAC,MAAM,EAAP,CAAJ,CAAeM,IAAhB,CAAN,CAA4BH,EAA5B,CAA+BI,KAA/B,CAAqC,QAArC;AACAL,IAAAA,MAAM,CAACF,IAAI,CAAC,MAAM,EAAP,CAAJ,CAAeQ,MAAhB,CAAN,CAA8BL,EAA9B,CAAiCI,KAAjC,CAAuC,EAAvC;AACAL,IAAAA,MAAM,CAACF,IAAI,CAAC,MAAM,EAAP,CAAJ,CAAeS,WAAhB,CAAN,CAAmCN,EAAnC,CAAsCI,KAAtC,CAA4C,CAA5C;AAEAL,IAAAA,MAAM,CAACF,IAAI,CAAC,OAAO,EAAP,GAAY,CAAb,CAAJ,CAAoBM,IAArB,CAAN,CAAiCH,EAAjC,CAAoCI,KAApC,CAA0C,QAA1C;AACAL,IAAAA,MAAM,CAACF,IAAI,CAAC,OAAO,EAAP,GAAY,CAAb,CAAJ,CAAoBQ,MAArB,CAAN,CAAmCL,EAAnC,CAAsCI,KAAtC,CAA4C,EAA5C;AACAL,IAAAA,MAAM,CAACF,IAAI,CAAC,OAAO,EAAP,GAAY,CAAb,CAAJ,CAAoBS,WAArB,CAAN,CAAwCN,EAAxC,CAA2CI,KAA3C,CAAiD,CAAjD;AAEAL,IAAAA,MAAM,CAACF,IAAI,CAAC,OAAO,EAAR,CAAJ,CAAgBM,IAAjB,CAAN,CAA6BH,EAA7B,CAAgCI,KAAhC,CAAsC,MAAtC;AACAL,IAAAA,MAAM,CAACF,IAAI,CAAC,OAAO,EAAR,CAAJ,CAAgBQ,MAAjB,CAAN,CAA+BL,EAA/B,CAAkCI,KAAlC,CAAwC,KAAK,EAA7C;AACA,GArCC,CAAF;AAsCA,CAxCO,CAAR","sourcesContent":["import grade from '../grade'\r\nimport gradation from './convenient'\r\n\r\n// Perhaps this should be part of `grade.test.js` instead.\r\n\r\ndescribe('convenient gradation', () =>\r\n{\r\n\tit('should grade correctly', () =>\r\n\t{\r\n\t\tconst test = (elapsed) => grade(elapsed, null, [\r\n\t\t\t'second',\r\n\t\t\t'minute',\r\n\t\t\t'hour',\r\n\t\t\t'day',\r\n\t\t\t'month',\r\n\t\t\t'year'\r\n\t\t], gradation)\r\n\r\n\t\texpect(test(0)).to.be.undefined\r\n\r\n\t\texpect(test(1).unit).to.equal('second')\r\n\t\texpect(test(1).factor).to.equal(1)\r\n\r\n\t\texpect(test(44).unit).to.equal('second')\r\n\t\texpect(test(44).factor).to.equal(1)\r\n\r\n\t\texpect(test(45).unit).to.equal('minute')\r\n\t\texpect(test(45).factor).to.equal(60)\r\n\t\texpect(test(45).granularity).to.be.undefined\r\n\r\n\t\texpect(test(2.5 * 60 - 1).unit).to.equal('minute')\r\n\t\texpect(test(2.5 * 60 - 1).factor).to.equal(60)\r\n\t\texpect(test(2.5 * 60 - 1).granularity).to.be.undefined\r\n\r\n\t\texpect(test(2.5 * 60).unit).to.equal('minute')\r\n\t\texpect(test(2.5 * 60).factor).to.equal(60)\r\n\t\texpect(test(2.5 * 60).granularity).to.equal(5)\r\n\r\n\t\texpect(test(52.5 * 60 - 1).unit).to.equal('minute')\r\n\t\texpect(test(52.5 * 60 - 1).factor).to.equal(60)\r\n\t\texpect(test(52.5 * 60 - 1).granularity).to.equal(5)\r\n\r\n\t\texpect(test(52.5 * 60).unit).to.equal('hour')\r\n\t\texpect(test(52.5 * 60).factor).to.equal(60 * 60)\r\n\t})\r\n})"],"file":"convenient.test.js"}

View File

@@ -0,0 +1,49 @@
export var minute = 60; // in seconds
export var hour = 60 * minute; // in seconds
export var day = 24 * hour; // in seconds
// https://www.quora.com/What-is-the-average-number-of-days-in-a-month
export var month = 30.44 * day; // in seconds
// "400 years have 146097 days (taking into account leap year rules)"
export var year = 146097 / 400 * day; // in seconds
/**
* Returns a step of gradation corresponding to the unit.
* @param {Object[]} gradation
* @param {string} unit
* @return {?Object}
*/
export function getStep(gradation, unit) {
for (var _iterator = gradation, _isArray = Array.isArray(_iterator), _i = 0, _iterator = _isArray ? _iterator : _iterator[Symbol.iterator]();;) {
var _ref;
if (_isArray) {
if (_i >= _iterator.length) break;
_ref = _iterator[_i++];
} else {
_i = _iterator.next();
if (_i.done) break;
_ref = _i.value;
}
var step = _ref;
if (step.unit === unit) {
return step;
}
}
}
/**
* Converts value to a `Date`
* @param {(number|Date)} value
* @return {Date}
*/
export function getDate(value) {
return value instanceof Date ? value : new Date(value);
}
//# sourceMappingURL=helpers.js.map

View File

@@ -0,0 +1 @@
{"version":3,"sources":["../../source/gradation/helpers.js"],"names":["minute","hour","day","month","year","getStep","gradation","unit","step","getDate","value","Date"],"mappings":"AAAA,OAAO,IAAMA,MAAM,GAAG,EAAf,C,CAAkB;;AAEzB,OAAO,IAAMC,IAAI,GAAG,KAAKD,MAAlB,C,CAAyB;;AAEhC,OAAO,IAAME,GAAG,GAAG,KAAKD,IAAjB,C,CAAsB;AAE7B;;AACA,OAAO,IAAME,KAAK,GAAG,QAAQD,GAAtB,C,CAA0B;AAEjC;;AACA,OAAO,IAAME,IAAI,GAAI,SAAS,GAAV,GAAiBF,GAA9B,C,CAAkC;;AAEzC;;;;;;;AAMA,OAAO,SAASG,OAAT,CAAiBC,SAAjB,EAA4BC,IAA5B,EAAkC;AACxC,uBAAmBD,SAAnB,kHAA8B;AAAA;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;AAAA,QAAnBE,IAAmB;;AAC7B,QAAIA,IAAI,CAACD,IAAL,KAAcA,IAAlB,EAAwB;AACvB,aAAOC,IAAP;AACA;AACD;AACD;AAED;;;;;;AAKA,OAAO,SAASC,OAAT,CAAiBC,KAAjB,EAAwB;AAC9B,SAAOA,KAAK,YAAYC,IAAjB,GAAwBD,KAAxB,GAAgC,IAAIC,IAAJ,CAASD,KAAT,CAAvC;AACA","sourcesContent":["export const minute = 60 // in seconds\r\n\r\nexport const hour = 60 * minute // in seconds\r\n\r\nexport const day = 24 * hour // in seconds\r\n\r\n// https://www.quora.com/What-is-the-average-number-of-days-in-a-month\r\nexport const month = 30.44 * day // in seconds\r\n\r\n// \"400 years have 146097 days (taking into account leap year rules)\"\r\nexport const year = (146097 / 400) * day // in seconds\r\n\r\n/**\r\n * Returns a step of gradation corresponding to the unit.\r\n * @param {Object[]} gradation\r\n * @param {string} unit\r\n * @return {?Object}\r\n */\r\nexport function getStep(gradation, unit) {\r\n\tfor (const step of gradation) {\r\n\t\tif (step.unit === unit) {\r\n\t\t\treturn step\r\n\t\t}\r\n\t}\r\n}\r\n\r\n/**\r\n * Converts value to a `Date`\r\n * @param {(number|Date)} value\r\n * @return {Date}\r\n */\r\nexport function getDate(value) {\r\n\treturn value instanceof Date ? value : new Date(value)\r\n}"],"file":"helpers.js"}

View File

@@ -0,0 +1,9 @@
import { getDate } from './helpers';
describe('gradation helpers', function () {
it('should convert value to Date', function () {
var today = new Date();
getDate(today.getTime()).getTime().should.equal(today.getTime());
getDate(today).getTime().should.equal(today.getTime());
});
});
//# sourceMappingURL=helpers.test.js.map

View File

@@ -0,0 +1 @@
{"version":3,"sources":["../../source/gradation/helpers.test.js"],"names":["getDate","describe","it","today","Date","getTime","should","equal"],"mappings":"AAAA,SAASA,OAAT,QAAwB,WAAxB;AAEAC,QAAQ,CAAC,mBAAD,EAAsB,YAC9B;AACCC,EAAAA,EAAE,CAAC,8BAAD,EAAiC,YACnC;AACC,QAAMC,KAAK,GAAG,IAAIC,IAAJ,EAAd;AACAJ,IAAAA,OAAO,CAACG,KAAK,CAACE,OAAN,EAAD,CAAP,CAAyBA,OAAzB,GAAmCC,MAAnC,CAA0CC,KAA1C,CAAgDJ,KAAK,CAACE,OAAN,EAAhD;AACAL,IAAAA,OAAO,CAACG,KAAD,CAAP,CAAeE,OAAf,GAAyBC,MAAzB,CAAgCC,KAAhC,CAAsCJ,KAAK,CAACE,OAAN,EAAtC;AACA,GALC,CAAF;AAMA,CARO,CAAR","sourcesContent":["import { getDate } from './helpers'\r\n\r\ndescribe('gradation helpers', () =>\r\n{\r\n\tit('should convert value to Date', () =>\r\n\t{\r\n\t\tconst today = new Date()\r\n\t\tgetDate(today.getTime()).getTime().should.equal(today.getTime())\r\n\t\tgetDate(today).getTime().should.equal(today.getTime())\r\n\t})\r\n})"],"file":"helpers.test.js"}

View File

@@ -0,0 +1,38 @@
// A gradation is a mapping from a time interval (in seconds)
// to the most appropriate time interval measurement unit
// for describing it, along with the amount of such units.
//
// E.g. for "canonical" gradation:
//
// 0 -> 1 'now'
// 0.5 -> 1 'second'
// 60 -> 1 'minute'
// 91 -> 2 'minute's
// ...
//
// Each gradation unit can have:
//
// * unit - (required) The name of the time interval measurement unit.
//
// * factor - (required) The amount of seconds will be divided by this number for this unit.
//
// * granularity - A step for the unit's resulting "amount" value.
//
// * threshold - Min value (in seconds) for this unit. Is required for non-first unit.
//
// * threshold_for_[unit] - A specific threshold required for moving from `[unit]` to this unit.
// E.g. if "now" unit is present in time units gradation
// then `threshold_for_now` can be set to `45` seconds.
// Otherwise, if "now" unit is omitted from time units gradation,
// then `elapsed(0)` will output "0 seconds" because there's no `threshold`.
//
// A user can supply his own gradation.
//
// Don't name a gradation "default"
// because that would conflict with the
// CommonJS "interoperability" export layer.
//
export { default as canonical } from './canonical';
export { default as convenient } from './convenient';
export { minute, hour, day, month, year, getStep, getDate } from './helpers';
//# sourceMappingURL=index.js.map

View File

@@ -0,0 +1 @@
{"version":3,"sources":["../../source/gradation/index.js"],"names":["default","canonical","convenient","minute","hour","day","month","year","getStep","getDate"],"mappings":"AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,SAASA,OAAO,IAAIC,SAApB,QAAqC,aAArC;AACA,SAASD,OAAO,IAAIE,UAApB,QAAsC,cAAtC;AACA,SAASC,MAAT,EAAiBC,IAAjB,EAAuBC,GAAvB,EAA4BC,KAA5B,EAAmCC,IAAnC,EAAyCC,OAAzC,EAAkDC,OAAlD,QAAiE,WAAjE","sourcesContent":["// A gradation is a mapping from a time interval (in seconds)\r\n// to the most appropriate time interval measurement unit\r\n// for describing it, along with the amount of such units.\r\n//\r\n// E.g. for \"canonical\" gradation:\r\n//\r\n// 0 -> 1 'now'\r\n// 0.5 -> 1 'second'\r\n// 60 -> 1 'minute'\r\n// 91 -> 2 'minute's\r\n// ...\r\n//\r\n// Each gradation unit can have:\r\n//\r\n// * unit - (required) The name of the time interval measurement unit.\r\n//\r\n// * factor - (required) The amount of seconds will be divided by this number for this unit.\r\n//\r\n// * granularity - A step for the unit's resulting \"amount\" value.\r\n//\r\n// * threshold - Min value (in seconds) for this unit. Is required for non-first unit.\r\n//\r\n// * threshold_for_[unit] - A specific threshold required for moving from `[unit]` to this unit.\r\n// E.g. if \"now\" unit is present in time units gradation\r\n// then `threshold_for_now` can be set to `45` seconds.\r\n// Otherwise, if \"now\" unit is omitted from time units gradation,\r\n// then `elapsed(0)` will output \"0 seconds\" because there's no `threshold`.\r\n//\r\n// A user can supply his own gradation.\r\n//\r\n// Don't name a gradation \"default\"\r\n// because that would conflict with the\r\n// CommonJS \"interoperability\" export layer.\r\n//\r\nexport { default as canonical } from './canonical'\r\nexport { default as convenient } from './convenient'\r\nexport { minute, hour, day, month, year, getStep, getDate } from './helpers'"],"file":"index.js"}

156
node_modules/javascript-time-ago/modules/grade.js generated vendored Normal file
View File

@@ -0,0 +1,156 @@
function _typeof(obj) { if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); }
import { convenient } from './gradation';
/**
* Takes seconds `elapsed` and measures them against
* `gradation` to return the suitable `gradation` step.
*
* @param {number} elapsed - Time interval (in seconds). Is < 0 for past dates and > 0 for future dates.
*
* @param {string[]} units - A list of allowed time units
* (e.g. ['second', 'minute', 'hour', …])
*
* @param {Object} [gradation] - Time scale gradation steps.
*
* E.g.:
* [
* { unit: 'second', factor: 1 },
* { unit: 'minute', factor: 60, threshold: 60 },
* { format(), threshold: 24 * 60 * 60 },
* …
* ]
*
* @return {?Object} `gradation` step.
*/
export default function grade(elapsed, now, units) {
var gradation = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : convenient;
// Leave only allowed time measurement units.
// E.g. omit "quarter" unit.
gradation = getAllowedSteps(gradation, units); // If no steps of gradation fit the conditions
// then return nothing.
if (gradation.length === 0) {
return;
} // Find the most appropriate gradation step
var i = findGradationStep(elapsed, now, gradation);
var step = gradation[i]; // If time elapsed is too small and even
// the first gradation step doesn't suit it
// then return nothing.
if (i === -1) {
return;
} // Apply granularity to the time amount
// (and fall back to the previous step
// if the first level of granularity
// isn't met by this amount)
if (step.granularity) {
// Recalculate the elapsed time amount based on granularity
var amount = Math.round(Math.abs(elapsed) / step.factor / step.granularity) * step.granularity; // If the granularity for this step
// is too high, then fallback
// to the previous step of gradation.
// (if there is any previous step of gradation)
if (amount === 0 && i > 0) {
return gradation[i - 1];
}
}
return step;
}
/**
* Gets threshold for moving from `fromStep` to `next_step`.
* @param {Object} fromStep - From step.
* @param {Object} next_step - To step.
* @param {number} now - The current timestamp.
* @param {boolean} future - Is `true` for future dates ("in 5 minutes").
* @return {number}
* @throws Will throw if no threshold is found.
*/
function getThreshold(fromStep, toStep, now, future) {
var threshold; // Allows custom thresholds when moving
// from a specific step to a specific step.
if (fromStep && (fromStep.id || fromStep.unit)) {
threshold = toStep["threshold_for_".concat(fromStep.id || fromStep.unit)];
} // If no custom threshold is set for this transition
// then use the usual threshold for the next step.
if (threshold === undefined) {
threshold = toStep.threshold;
} // Convert threshold to a number.
if (typeof threshold === 'function') {
threshold = threshold(now, future);
} // Throw if no threshold is found.
if (fromStep && typeof threshold !== 'number') {
// Babel transforms `typeof` into some "branches"
// so istanbul will show this as "branch not covered".
/* istanbul ignore next */
var type = _typeof(threshold);
throw new Error("Each step of a gradation must have a threshold defined except for the first one. Got \"".concat(threshold, "\", ").concat(type, ". Step: ").concat(JSON.stringify(toStep)));
}
return threshold;
}
/**
* @param {number} elapsed - Time elapsed (in seconds).
* @param {number} now - Current timestamp.
* @param {Object} gradation - Gradation.
* @param {number} i - Gradation step currently being tested.
* @return {number} Gradation step index.
*/
function findGradationStep(elapsed, now, gradation) {
var i = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : 0;
// If the threshold for moving from previous step
// to this step is too high then return the previous step.
if (Math.abs(elapsed) < getThreshold(gradation[i - 1], gradation[i], now, elapsed < 0)) {
return i - 1;
} // If it's the last step of gradation then return it.
if (i === gradation.length - 1) {
return i;
} // Move to the next step.
return findGradationStep(elapsed, now, gradation, i + 1);
}
/**
* Leaves only allowed gradation steps.
* @param {Object[]} gradation
* @param {string[]} units - Allowed time units.
* @return {Object[]}
*/
function getAllowedSteps(gradation, units) {
return gradation.filter(function (_ref) {
var unit = _ref.unit;
// If this step has a `unit` defined
// then this `unit` must be in the list of `units` allowed.
if (unit) {
return units.indexOf(unit) >= 0;
} // A gradation step is not required to specify a `unit`.
// E.g. for Twitter gradation it specifies `format()` instead.
return true;
});
}
//# sourceMappingURL=grade.js.map

File diff suppressed because one or more lines are too long

31
node_modules/javascript-time-ago/modules/grade.test.js generated vendored Normal file
View File

@@ -0,0 +1,31 @@
import grade from '../source/grade';
import { canonical } from '../source/gradation';
describe('grade', function () {
it('should return nothing if no time units are applicable', function () {
expect(grade(0, null, ['femtosecond'], canonical)).to.be.undefined;
});
it('should throw if a non-first step does not have a threshold', function () {
expect(grade(2, null, ['second'], [{
unit: 'second'
}])).to.deep.equal({
unit: 'second'
});
expect(function () {
grade(2, null, ['second', 'minute'], [{
unit: 'second'
}, {
unit: 'minute'
}]);
}).to.throw('Each step of a gradation must have a threshold defined except for the first one. Got "undefined", undefined. Step: {"unit":"minute"}');
});
it('should fall back to previous grading scale step if granularity is too high', function () {
var gradation = canonical.slice();
gradation[1].unit.should.equal('second');
gradation[1].granularity = 3;
grade(1.49, null, ['now', 'second'], gradation).unit.should.equal('now'); // And if there's no previous step, then use the current one.
gradation.splice(0, 1);
grade(1.49, null, ['now', 'second'], gradation).unit.should.equal('second');
});
});
//# sourceMappingURL=grade.test.js.map

View File

@@ -0,0 +1 @@
{"version":3,"sources":["../source/grade.test.js"],"names":["grade","canonical","describe","it","expect","to","be","undefined","unit","deep","equal","throw","gradation","slice","should","granularity","splice"],"mappings":"AAAA,OAAOA,KAAP,MAAkB,iBAAlB;AACA,SAASC,SAAT,QAA0B,qBAA1B;AAEAC,QAAQ,CAAC,OAAD,EAAU,YAClB;AACCC,EAAAA,EAAE,CAAC,uDAAD,EAA0D,YAC5D;AACCC,IAAAA,MAAM,CAACJ,KAAK,CAAC,CAAD,EAAI,IAAJ,EAAU,CAAC,aAAD,CAAV,EAA2BC,SAA3B,CAAN,CAAN,CAAmDI,EAAnD,CAAsDC,EAAtD,CAAyDC,SAAzD;AACA,GAHC,CAAF;AAKAJ,EAAAA,EAAE,CAAC,4DAAD,EAA+D,YACjE;AACCC,IAAAA,MAAM,CAACJ,KAAK,CAAC,CAAD,EAAI,IAAJ,EAAU,CAAC,QAAD,CAAV,EAAsB,CAAC;AAAEQ,MAAAA,IAAI,EAAE;AAAR,KAAD,CAAtB,CAAN,CAAN,CAAyDH,EAAzD,CAA4DI,IAA5D,CAAiEC,KAAjE,CAAuE;AAAEF,MAAAA,IAAI,EAAE;AAAR,KAAvE;AAEAJ,IAAAA,MAAM,CAAC,YAAM;AACZJ,MAAAA,KAAK,CAAC,CAAD,EAAI,IAAJ,EAAU,CAAC,QAAD,EAAW,QAAX,CAAV,EAAgC,CAAC;AAAEQ,QAAAA,IAAI,EAAE;AAAR,OAAD,EAAqB;AAAEA,QAAAA,IAAI,EAAE;AAAR,OAArB,CAAhC,CAAL;AACA,KAFK,CAAN,CAEGH,EAFH,CAEMM,KAFN,CAGC,sIAHD;AAKA,GATC,CAAF;AAWAR,EAAAA,EAAE,CAAC,4EAAD,EAA+E,YACjF;AACC,QAAMS,SAAS,GAAGX,SAAS,CAACY,KAAV,EAAlB;AAEAD,IAAAA,SAAS,CAAC,CAAD,CAAT,CAAaJ,IAAb,CAAkBM,MAAlB,CAAyBJ,KAAzB,CAA+B,QAA/B;AACAE,IAAAA,SAAS,CAAC,CAAD,CAAT,CAAaG,WAAb,GAA2B,CAA3B;AAEAf,IAAAA,KAAK,CAAC,IAAD,EAAO,IAAP,EAAa,CAAC,KAAD,EAAQ,QAAR,CAAb,EAAgCY,SAAhC,CAAL,CAAgDJ,IAAhD,CAAqDM,MAArD,CAA4DJ,KAA5D,CAAkE,KAAlE,EAND,CAQC;;AAEAE,IAAAA,SAAS,CAACI,MAAV,CAAiB,CAAjB,EAAoB,CAApB;AAEAhB,IAAAA,KAAK,CAAC,IAAD,EAAO,IAAP,EAAa,CAAC,KAAD,EAAQ,QAAR,CAAb,EAAgCY,SAAhC,CAAL,CAAgDJ,IAAhD,CAAqDM,MAArD,CAA4DJ,KAA5D,CAAkE,QAAlE;AACA,GAdC,CAAF;AAeA,CAjCO,CAAR","sourcesContent":["import grade from '../source/grade'\r\nimport { canonical } from '../source/gradation'\r\n\r\ndescribe('grade', () =>\r\n{\r\n\tit('should return nothing if no time units are applicable', () =>\r\n\t{\r\n\t\texpect(grade(0, null, ['femtosecond'], canonical)).to.be.undefined\r\n\t})\r\n\r\n\tit('should throw if a non-first step does not have a threshold', () =>\r\n\t{\r\n\t\texpect(grade(2, null, ['second'], [{ unit: 'second' }])).to.deep.equal({ unit: 'second' })\r\n\r\n\t\texpect(() => {\r\n\t\t\tgrade(2, null, ['second', 'minute'], [{ unit: 'second' }, { unit: 'minute' }])\r\n\t\t}).to.throw(\r\n\t\t\t'Each step of a gradation must have a threshold defined except for the first one. Got \"undefined\", undefined. Step: {\"unit\":\"minute\"}'\r\n\t\t)\r\n\t})\r\n\r\n\tit('should fall back to previous grading scale step if granularity is too high', () =>\r\n\t{\r\n\t\tconst gradation = canonical.slice()\r\n\r\n\t\tgradation[1].unit.should.equal('second')\r\n\t\tgradation[1].granularity = 3\r\n\r\n\t\tgrade(1.49, null, ['now', 'second'], gradation).unit.should.equal('now')\r\n\r\n\t\t// And if there's no previous step, then use the current one.\r\n\r\n\t\tgradation.splice(0, 1)\r\n\r\n\t\tgrade(1.49, null, ['now', 'second'], gradation).unit.should.equal('second')\r\n\t})\r\n})"],"file":"grade.test.js"}

78
node_modules/javascript-time-ago/modules/locale.js generated vendored Normal file
View File

@@ -0,0 +1,78 @@
function _typeof(obj) { if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); }
// Chooses the most appropriate locale
// (one of the registered ones)
// based on the list of preferred `locales` supplied by the user.
//
// @param {string[]} locales - the list of preferable locales (in [IETF format](https://en.wikipedia.org/wiki/IETF_language_tag)).
// @param {Function} isLocaleDataAvailable - tests if a locale is available.
//
// @returns {string} The most suitable locale
//
// @example
// // Returns 'en'
// chooseLocale(['en-US'], undefined, (locale) => locale === 'ru' || locale === 'en')
//
export default function chooseLocale(locales, isLocaleDataAvailable) {
// This is not an intelligent algorithm,
// but it will do for this library's case.
// `sr-Cyrl-BA` -> `sr-Cyrl` -> `sr`.
for (var _iterator = locales, _isArray = Array.isArray(_iterator), _i = 0, _iterator = _isArray ? _iterator : _iterator[Symbol.iterator]();;) {
var _ref;
if (_isArray) {
if (_i >= _iterator.length) break;
_ref = _iterator[_i++];
} else {
_i = _iterator.next();
if (_i.done) break;
_ref = _i.value;
}
var locale = _ref;
if (isLocaleDataAvailable(locale)) {
return locale;
}
var parts = locale.split('-');
while (parts.length > 1) {
parts.pop();
locale = parts.join('-');
if (isLocaleDataAvailable(locale)) {
return locale;
}
}
}
throw new Error("No locale data has been registered for any of the locales: ".concat(locales.join(', ')));
}
/**
* Whether can use `Intl.DateTimeFormat` for these `locales`.
* Returns the first suitable one.
* @param {(string|string[])} locales
* @return {?string} The first locale that can be used.
*/
export function intlDateTimeFormatSupportedLocale(locales) {
/* istanbul ignore else */
if (intlDateTimeFormatSupported()) {
return Intl.DateTimeFormat.supportedLocalesOf(locales)[0];
}
}
/**
* Whether can use `Intl.DateTimeFormat`.
* @return {boolean}
*/
export function intlDateTimeFormatSupported() {
// Babel transforms `typeof` into some "branches"
// so istanbul will show this as "branch not covered".
/* istanbul ignore next */
var isIntlAvailable = (typeof Intl === "undefined" ? "undefined" : _typeof(Intl)) === 'object';
return isIntlAvailable && typeof Intl.DateTimeFormat === 'function';
}
//# sourceMappingURL=locale.js.map

View File

@@ -0,0 +1 @@
{"version":3,"sources":["../source/locale.js"],"names":["chooseLocale","locales","isLocaleDataAvailable","locale","parts","split","length","pop","join","Error","intlDateTimeFormatSupportedLocale","intlDateTimeFormatSupported","Intl","DateTimeFormat","supportedLocalesOf","isIntlAvailable"],"mappings":";;AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,eAAe,SAASA,YAAT,CAAsBC,OAAtB,EAA+BC,qBAA/B,EACf;AACC;AACA;AACA;AACA,uBAAmBD,OAAnB,kHAA4B;AAAA;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;AAAA,QAAnBE,MAAmB;;AAC3B,QAAID,qBAAqB,CAACC,MAAD,CAAzB,EAAmC;AAClC,aAAOA,MAAP;AACA;;AACD,QAAMC,KAAK,GAAGD,MAAM,CAACE,KAAP,CAAa,GAAb,CAAd;;AACA,WAAOD,KAAK,CAACE,MAAN,GAAe,CAAtB,EAAyB;AACxBF,MAAAA,KAAK,CAACG,GAAN;AACAJ,MAAAA,MAAM,GAAGC,KAAK,CAACI,IAAN,CAAW,GAAX,CAAT;;AACA,UAAIN,qBAAqB,CAACC,MAAD,CAAzB,EAAmC;AAClC,eAAOA,MAAP;AACA;AACD;AACD;;AAED,QAAM,IAAIM,KAAJ,sEAAwER,OAAO,CAACO,IAAR,CAAa,IAAb,CAAxE,EAAN;AACA;AAED;;;;;;;AAMA,OAAO,SAASE,iCAAT,CAA2CT,OAA3C,EAAoD;AAC1D;AACA,MAAIU,2BAA2B,EAA/B,EAAmC;AAClC,WAAOC,IAAI,CAACC,cAAL,CAAoBC,kBAApB,CAAuCb,OAAvC,EAAgD,CAAhD,CAAP;AACA;AACD;AACD;;;;;AAIA,OAAO,SAASU,2BAAT,GAAuC;AAC7C;AACA;;AACA;AACA,MAAMI,eAAe,GAAG,QAAOH,IAAP,yCAAOA,IAAP,OAAgB,QAAxC;AACA,SAAOG,eAAe,IAAI,OAAOH,IAAI,CAACC,cAAZ,KAA+B,UAAzD;AACA","sourcesContent":["// Chooses the most appropriate locale\r\n// (one of the registered ones)\r\n// based on the list of preferred `locales` supplied by the user.\r\n//\r\n// @param {string[]} locales - the list of preferable locales (in [IETF format](https://en.wikipedia.org/wiki/IETF_language_tag)).\r\n// @param {Function} isLocaleDataAvailable - tests if a locale is available.\r\n//\r\n// @returns {string} The most suitable locale\r\n//\r\n// @example\r\n// // Returns 'en'\r\n// chooseLocale(['en-US'], undefined, (locale) => locale === 'ru' || locale === 'en')\r\n//\r\nexport default function chooseLocale(locales, isLocaleDataAvailable)\r\n{\r\n\t// This is not an intelligent algorithm,\r\n\t// but it will do for this library's case.\r\n\t// `sr-Cyrl-BA` -> `sr-Cyrl` -> `sr`.\r\n\tfor (let locale of locales) {\r\n\t\tif (isLocaleDataAvailable(locale)) {\r\n\t\t\treturn locale\r\n\t\t}\r\n\t\tconst parts = locale.split('-')\r\n\t\twhile (parts.length > 1) {\r\n\t\t\tparts.pop()\r\n\t\t\tlocale = parts.join('-')\r\n\t\t\tif (isLocaleDataAvailable(locale)) {\r\n\t\t\t\treturn locale\r\n\t\t\t}\r\n\t\t}\r\n\t}\r\n\r\n\tthrow new Error(`No locale data has been registered for any of the locales: ${locales.join(', ')}`)\r\n}\r\n\r\n/**\r\n * Whether can use `Intl.DateTimeFormat` for these `locales`.\r\n * Returns the first suitable one.\r\n * @param {(string|string[])} locales\r\n * @return {?string} The first locale that can be used.\r\n */\r\nexport function intlDateTimeFormatSupportedLocale(locales) {\r\n\t/* istanbul ignore else */\r\n\tif (intlDateTimeFormatSupported()) {\r\n\t\treturn Intl.DateTimeFormat.supportedLocalesOf(locales)[0]\r\n\t}\r\n}\r\n/**\r\n * Whether can use `Intl.DateTimeFormat`.\r\n * @return {boolean}\r\n */\r\nexport function intlDateTimeFormatSupported() {\r\n\t// Babel transforms `typeof` into some \"branches\"\r\n\t// so istanbul will show this as \"branch not covered\".\r\n\t/* istanbul ignore next */\r\n\tconst isIntlAvailable = typeof Intl === 'object'\r\n\treturn isIntlAvailable && typeof Intl.DateTimeFormat === 'function'\r\n}\r\n"],"file":"locale.js"}

View File

@@ -0,0 +1,41 @@
import chooseLocale, { intlDateTimeFormatSupportedLocale } from '../source/locale';
describe('locale', function () {
it("should tell if can use Intl for date formatting", function () {
intlDateTimeFormatSupportedLocale('en').should.equal('en');
intlDateTimeFormatSupportedLocale('en-XX').should.equal('en-XX');
intlDateTimeFormatSupportedLocale(['en', 'ru']).should.equal('en');
});
it("should choose the most appropriate locale", function () {
function arrayToObject(array) {
return array.reduce(function (object, locale) {
object[locale] = true;
return object;
}, {});
}
function choose(locale, locales) {
var defaultLocale = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 'en';
if (typeof locale === 'string') {
locale = [locale];
}
locale = locale.concat(defaultLocale);
return chooseLocale(locale, function (_) {
return locales.includes(_);
});
}
choose('ru-RU', ['en', 'ru']).should.equal('ru');
choose('en-GB', ['en', 'ru']).should.equal('en');
choose('fr-FR', ['en', 'ru']).should.equal('en');
choose(['fr-FR', 'de-DE'], ['en', 'ru']).should.equal('en');
choose(['fr-FR', 'de-DE'], ['en', 'de']).should.equal('de');
choose(['fr-FR', 'de-DE'], ['en', 'de', 'fr']).should.equal('fr');
choose('fr-FR', ['en', 'fr-FR']).should.equal('fr-FR');
expect(function () {
return choose('fr-FR', ['de', 'ru']);
}).to.throw('No locale data has been registered for any of the locales: fr-FR');
});
});
//# sourceMappingURL=locale.test.js.map

View File

@@ -0,0 +1 @@
{"version":3,"sources":["../source/locale.test.js"],"names":["chooseLocale","intlDateTimeFormatSupportedLocale","describe","it","should","equal","arrayToObject","array","reduce","object","locale","choose","locales","defaultLocale","concat","_","includes","expect","to","throw"],"mappings":"AAAA,OAAOA,YAAP,IAAuBC,iCAAvB,QAAgE,kBAAhE;AAEAC,QAAQ,CAAC,QAAD,EAAW,YACnB;AACCC,EAAAA,EAAE,oDAAoD,YACtD;AACCF,IAAAA,iCAAiC,CAAC,IAAD,CAAjC,CAAwCG,MAAxC,CAA+CC,KAA/C,CAAqD,IAArD;AACAJ,IAAAA,iCAAiC,CAAC,OAAD,CAAjC,CAA2CG,MAA3C,CAAkDC,KAAlD,CAAwD,OAAxD;AACAJ,IAAAA,iCAAiC,CAAC,CAAC,IAAD,EAAO,IAAP,CAAD,CAAjC,CAAgDG,MAAhD,CAAuDC,KAAvD,CAA6D,IAA7D;AACA,GALC,CAAF;AAOAF,EAAAA,EAAE,8CAA8C,YAChD;AACC,aAASG,aAAT,CAAuBC,KAAvB,EACA;AACC,aAAOA,KAAK,CAACC,MAAN,CAAa,UAACC,MAAD,EAASC,MAAT,EAAoB;AACvCD,QAAAA,MAAM,CAACC,MAAD,CAAN,GAAiB,IAAjB;AACA,eAAOD,MAAP;AACA,OAHM,EAGJ,EAHI,CAAP;AAIA;;AAED,aAASE,MAAT,CAAgBD,MAAhB,EAAwBE,OAAxB,EACA;AAAA,UADiCC,aACjC,uEADiD,IACjD;;AACC,UAAI,OAAOH,MAAP,KAAkB,QAAtB,EAAgC;AAC/BA,QAAAA,MAAM,GAAG,CAACA,MAAD,CAAT;AACA;;AACDA,MAAAA,MAAM,GAAGA,MAAM,CAACI,MAAP,CAAcD,aAAd,CAAT;AACA,aAAOb,YAAY,CAACU,MAAD,EAAS,UAAAK,CAAC;AAAA,eAAIH,OAAO,CAACI,QAAR,CAAiBD,CAAjB,CAAJ;AAAA,OAAV,CAAnB;AACA;;AAEDJ,IAAAA,MAAM,CAAC,OAAD,EAAU,CAAC,IAAD,EAAO,IAAP,CAAV,CAAN,CAA8BP,MAA9B,CAAqCC,KAArC,CAA2C,IAA3C;AACAM,IAAAA,MAAM,CAAC,OAAD,EAAU,CAAC,IAAD,EAAO,IAAP,CAAV,CAAN,CAA8BP,MAA9B,CAAqCC,KAArC,CAA2C,IAA3C;AACAM,IAAAA,MAAM,CAAC,OAAD,EAAU,CAAC,IAAD,EAAO,IAAP,CAAV,CAAN,CAA8BP,MAA9B,CAAqCC,KAArC,CAA2C,IAA3C;AACAM,IAAAA,MAAM,CAAC,CAAC,OAAD,EAAU,OAAV,CAAD,EAAqB,CAAC,IAAD,EAAO,IAAP,CAArB,CAAN,CAAyCP,MAAzC,CAAgDC,KAAhD,CAAsD,IAAtD;AACAM,IAAAA,MAAM,CAAC,CAAC,OAAD,EAAU,OAAV,CAAD,EAAqB,CAAC,IAAD,EAAO,IAAP,CAArB,CAAN,CAAyCP,MAAzC,CAAgDC,KAAhD,CAAsD,IAAtD;AACAM,IAAAA,MAAM,CAAC,CAAC,OAAD,EAAU,OAAV,CAAD,EAAqB,CAAC,IAAD,EAAO,IAAP,EAAa,IAAb,CAArB,CAAN,CAA+CP,MAA/C,CAAsDC,KAAtD,CAA4D,IAA5D;AACAM,IAAAA,MAAM,CAAC,OAAD,EAAU,CAAC,IAAD,EAAO,OAAP,CAAV,CAAN,CAAiCP,MAAjC,CAAwCC,KAAxC,CAA8C,OAA9C;AAEAY,IAAAA,MAAM,CAAC;AAAA,aAAMN,MAAM,CAAC,OAAD,EAAU,CAAC,IAAD,EAAO,IAAP,CAAV,CAAZ;AAAA,KAAD,CAAN,CAA4CO,EAA5C,CAA+CC,KAA/C,CACC,kEADD;AAGA,GA9BC,CAAF;AA+BA,CAxCO,CAAR","sourcesContent":["import chooseLocale, { intlDateTimeFormatSupportedLocale } from '../source/locale'\r\n\r\ndescribe('locale', function()\r\n{\r\n\tit(`should tell if can use Intl for date formatting`, function()\r\n\t{\r\n\t\tintlDateTimeFormatSupportedLocale('en').should.equal('en')\r\n\t\tintlDateTimeFormatSupportedLocale('en-XX').should.equal('en-XX')\r\n\t\tintlDateTimeFormatSupportedLocale(['en', 'ru']).should.equal('en')\r\n\t})\r\n\r\n\tit(`should choose the most appropriate locale`, function()\r\n\t{\r\n\t\tfunction arrayToObject(array)\r\n\t\t{\r\n\t\t\treturn array.reduce((object, locale) => {\r\n\t\t\t\tobject[locale] = true\r\n\t\t\t\treturn object\r\n\t\t\t}, {})\r\n\t\t}\r\n\r\n\t\tfunction choose(locale, locales, defaultLocale = 'en')\r\n\t\t{\r\n\t\t\tif (typeof locale === 'string') {\r\n\t\t\t\tlocale = [locale]\r\n\t\t\t}\r\n\t\t\tlocale = locale.concat(defaultLocale)\r\n\t\t\treturn chooseLocale(locale, _ => locales.includes(_))\r\n\t\t}\r\n\r\n\t\tchoose('ru-RU', ['en', 'ru']).should.equal('ru')\r\n\t\tchoose('en-GB', ['en', 'ru']).should.equal('en')\r\n\t\tchoose('fr-FR', ['en', 'ru']).should.equal('en')\r\n\t\tchoose(['fr-FR', 'de-DE'], ['en', 'ru']).should.equal('en')\r\n\t\tchoose(['fr-FR', 'de-DE'], ['en', 'de']).should.equal('de')\r\n\t\tchoose(['fr-FR', 'de-DE'], ['en', 'de', 'fr']).should.equal('fr')\r\n\t\tchoose('fr-FR', ['en', 'fr-FR']).should.equal('fr-FR')\r\n\r\n\t\texpect(() => choose('fr-FR', ['de', 'ru'])).to.throw(\r\n\t\t\t'No locale data has been registered for any of the locales: fr-FR'\r\n\t\t)\r\n\t})\r\n})"],"file":"locale.test.js"}

View File

@@ -0,0 +1,7 @@
import { convenient } from '../gradation';
export default {
gradation: convenient,
flavour: ['long-convenient', 'long'],
units: ['now', 'minute', 'hour', 'day', 'week', 'month', 'year']
};
//# sourceMappingURL=default.js.map

View File

@@ -0,0 +1 @@
{"version":3,"sources":["../../source/style/default.js"],"names":["convenient","gradation","flavour","units"],"mappings":"AAAA,SAASA,UAAT,QAA2B,cAA3B;AAEA,eACA;AACCC,EAAAA,SAAS,EAAED,UADZ;AAECE,EAAAA,OAAO,EAAE,CAAC,iBAAD,EAAoB,MAApB,CAFV;AAGCC,EAAAA,KAAK,EACL,CACC,KADD,EAEC,QAFD,EAGC,MAHD,EAIC,KAJD,EAKC,MALD,EAMC,OAND,EAOC,MAPD;AAJD,CADA","sourcesContent":["import { convenient } from '../gradation'\r\n\r\nexport default\r\n{\r\n\tgradation: convenient,\r\n\tflavour: ['long-convenient', 'long'],\r\n\tunits:\r\n\t[\r\n\t\t'now',\r\n\t\t'minute',\r\n\t\t'hour',\r\n\t\t'day',\r\n\t\t'week',\r\n\t\t'month',\r\n\t\t'year'\r\n\t]\r\n}"],"file":"default.js"}

View File

@@ -0,0 +1,9 @@
// A preset (style) is an object having shape
// `{ units, gradation, flavour, custom({ elapsed, time, date, now, locale }) }`.
//
// `date` parameter of `custom()` is not guaranteed to be set (can be inferred from `time`).
//
export { default as timeStyle } from './time';
export { default as twitterStyle } from './twitter';
export { default as defaultStyle } from './default';
//# sourceMappingURL=index.js.map

View File

@@ -0,0 +1 @@
{"version":3,"sources":["../../source/style/index.js"],"names":["default","timeStyle","twitterStyle","defaultStyle"],"mappings":"AAAA;AACA;AACA;AACA;AACA;AACA,SAASA,OAAO,IAAIC,SAApB,QAAqC,QAArC;AACA,SAASD,OAAO,IAAIE,YAApB,QAAwC,WAAxC;AACA,SAASF,OAAO,IAAIG,YAApB,QAAwC,WAAxC","sourcesContent":["// A preset (style) is an object having shape\r\n// `{ units, gradation, flavour, custom({ elapsed, time, date, now, locale }) }`.\r\n//\r\n// `date` parameter of `custom()` is not guaranteed to be set (can be inferred from `time`).\r\n//\r\nexport { default as timeStyle } from './time'\r\nexport { default as twitterStyle } from './twitter'\r\nexport { default as defaultStyle } from './default'"],"file":"index.js"}

30
node_modules/javascript-time-ago/modules/style/time.js generated vendored Normal file
View File

@@ -0,0 +1,30 @@
import { convenient } from '../gradation'; // Similar to the default style but with "ago" omitted.
//
// just now
// 5 minutes
// 10 minutes
// 15 minutes
// 20 minutes
// an hour
// 2 hours
// …
// 20 hours
// 1 day
// 2 days
// a week
// 2 weeks
// 3 weeks
// a month
// 2 months
// 3 months
// 4 months
// a year
// 2 years
//
export default {
gradation: convenient,
flavour: 'long-time',
units: ['now', 'minute', 'hour', 'day', 'week', 'month', 'year']
};
//# sourceMappingURL=time.js.map

View File

@@ -0,0 +1 @@
{"version":3,"sources":["../../source/style/time.js"],"names":["convenient","gradation","flavour","units"],"mappings":"AAAA,SAASA,UAAT,QAA2B,cAA3B,C,CAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AACA,eACA;AACCC,EAAAA,SAAS,EAAED,UADZ;AAECE,EAAAA,OAAO,EAAE,WAFV;AAGCC,EAAAA,KAAK,EACL,CACC,KADD,EAEC,QAFD,EAGC,MAHD,EAIC,KAJD,EAKC,MALD,EAMC,OAND,EAOC,MAPD;AAJD,CADA","sourcesContent":["import { convenient } from '../gradation'\r\n\r\n// Similar to the default style but with \"ago\" omitted.\r\n//\r\n// just now\r\n// 5 minutes\r\n// 10 minutes\r\n// 15 minutes\r\n// 20 minutes\r\n// an hour\r\n// 2 hours\r\n// …\r\n// 20 hours\r\n// 1 day\r\n// 2 days\r\n// a week\r\n// 2 weeks\r\n// 3 weeks\r\n// a month\r\n// 2 months\r\n// 3 months\r\n// 4 months\r\n// a year\r\n// 2 years\r\n//\r\nexport default\r\n{\r\n\tgradation: convenient,\r\n\tflavour: 'long-time',\r\n\tunits:\r\n\t[\r\n\t\t'now',\r\n\t\t'minute',\r\n\t\t'hour',\r\n\t\t'day',\r\n\t\t'week',\r\n\t\t'month',\r\n\t\t'year'\r\n\t]\r\n}"],"file":"time.js"}

View File

@@ -0,0 +1,11 @@
import timeStyle from './time';
import { convenientGradationTest } from '../JavascriptTimeAgo.test';
describe('"time" style', function () {
it('should format "time" style relative time (English)', function () {
convenientGradationTest(['just now', '1 minute', '2 minutes', '5 minutes', '10 minutes', '15 minutes', '20 minutes', '25 minutes', '30 minutes', '35 minutes', '40 minutes', '45 minutes', '50 minutes', '1 hour', '2 hours', '3 hours', '4 hours', '5 hours', '6 hours', '7 hours', '8 hours', '9 hours', '10 hours', '11 hours', '12 hours', '13 hours', '14 hours', '15 hours', '16 hours', '17 hours', '18 hours', '19 hours', '20 hours', '1 day', '2 days', '3 days', '4 days', '5 days', '1 week', '2 weeks', '3 weeks', '1 month', '2 months', '3 months', '4 months', '5 months', '6 months', '7 months', '8 months', '9 months', '9 months', '10 months', '1 year', '2 years', '3 years', '100 years'], 'en-US', timeStyle);
});
it('should format "time" style relative time (Russian)', function () {
convenientGradationTest(['только что', '1 минута', '2 минуты', '5 минут', '10 минут', '15 минут', '20 минут', '25 минут', '30 минут', '35 минут', '40 минут', '45 минут', '50 минут', '1 час', '2 часа', '3 часа', '4 часа', '5 часов', '6 часов', '7 часов', '8 часов', '9 часов', '10 часов', '11 часов', '12 часов', '13 часов', '14 часов', '15 часов', '16 часов', '17 часов', '18 часов', '19 часов', '20 часов', '1 день', '2 дня', '3 дня', '4 дня', '5 дней', '1 неделю', '2 недели', '3 недели', '1 месяц', '2 месяца', '3 месяца', '4 месяца', '5 месяцев', '6 месяцев', '7 месяцев', '8 месяцев', '9 месяцев', '9 месяцев', '10 месяцев', '1 год', '2 года', '3 года', '100 лет'], 'ru-RU', timeStyle);
});
});
//# sourceMappingURL=time.test.js.map

File diff suppressed because one or more lines are too long

View File

@@ -0,0 +1,103 @@
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; var ownKeys = Object.keys(source); if (typeof Object.getOwnPropertySymbols === 'function') { ownKeys = ownKeys.concat(Object.getOwnPropertySymbols(source).filter(function (sym) { return Object.getOwnPropertyDescriptor(source, sym).enumerable; })); } ownKeys.forEach(function (key) { _defineProperty(target, key, source[key]); }); } return target; }
function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
import { canonical, day, hour, getStep, getDate } from '../gradation';
import { intlDateTimeFormatSupported } from '../locale'; // A cache for `Intl.DateTimeFormat` twitter formatters
// for various locales (is a global variable).
var formatters = {}; // Twitter style relative time formatting.
// ("1m", "2h", "Mar 3", "Apr 4, 2012").
// Seconds, minutes and hours are shown relatively,
// and other intervals can be shown using full date format.
export default {
// Twitter gradation is derived from "canonical" gradation
// adjusting its "minute" `threshold` to be 45.
gradation: [// Minutes
_objectSpread({}, getStep(canonical, 'minute'), {
threshold: 45
}), // Hours
getStep(canonical, 'hour'), // If `date` and `now` happened the same year,
// then only output month and day.
{
threshold: day - 0.5 * hour,
format: function format(value, locale) {
// Whether can use `Intl.DateTimeFormat`.
// If `Intl` is not available,
// or the locale is not supported,
// then don't override the default labels.
/* istanbul ignore if */
if (!intlDateTimeFormatSupported()) {
return;
}
/* istanbul ignore else */
if (!formatters[locale]) {
formatters[locale] = {};
}
/* istanbul ignore else */
if (!formatters[locale].this_year) {
// "Apr 11" (MMMd)
formatters[locale].this_year = new Intl.DateTimeFormat(locale, {
month: 'short',
day: 'numeric'
});
} // Output month and day.
return formatters[locale].this_year.format(getDate(value));
}
}, // If `date` and `now` happened in defferent years,
// then output day, month and year.
{
threshold: function threshold(now, future) {
if (future) {
// Jan 1st 00:00 of the next year.
var nextYear = new Date(new Date(now).getFullYear() + 1, 0);
return (nextYear.getTime() - now) / 1000;
} else {
// Jan 1st of the current year.
var thisYear = new Date(new Date(now).getFullYear(), 0);
return (now - thisYear.getTime()) / 1000;
}
},
format: function format(value, locale) {
// Whether can use `Intl.DateTimeFormat`.
// If `Intl` is not available,
// or the locale is not supported,
// then don't override the default labels.
/* istanbul ignore if */
if (!intlDateTimeFormatSupported()) {
return;
}
/* istanbul ignore if */
if (!formatters[locale]) {
formatters[locale] = {};
}
/* istanbul ignore else */
if (!formatters[locale].other) {
// "Apr 11, 2017" (yMMMd)
formatters[locale].other = new Intl.DateTimeFormat(locale, {
year: 'numeric',
month: 'short',
day: 'numeric'
});
} // Output day, month and year.
return formatters[locale].other.format(getDate(value));
}
}],
flavour: ['tiny', 'short-time', 'narrow', 'short']
};
//# sourceMappingURL=twitter.js.map

File diff suppressed because one or more lines are too long

View File

@@ -0,0 +1,80 @@
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; var ownKeys = Object.keys(source); if (typeof Object.getOwnPropertySymbols === 'function') { ownKeys = ownKeys.concat(Object.getOwnPropertySymbols(source).filter(function (sym) { return Object.getOwnPropertyDescriptor(source, sym).enumerable; })); } ownKeys.forEach(function (key) { _defineProperty(target, key, source[key]); }); } return target; }
function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
import twitterStyle from './twitter';
import JavascriptTimeAgo from '../JavascriptTimeAgo';
import { day, month, year } from '../gradation';
describe('"twitter" style', function () {
it('should fallback from "tiny" to "narrow" for Twitter style for autogenerated locales', function () {
var timeAgo = new JavascriptTimeAgo('de');
timeAgo.format(Date.now() - 3 * 60 * 60 * 1000, 'twitter').should.equal('vor 3 Std.');
});
it('should format Twitter style relative time (English)', function () {
var timeAgo = new JavascriptTimeAgo('en');
var now = new Date(2016, 3, 10, 22, 59).getTime();
var elapsed = function elapsed(time) {
return timeAgo.format(now - time * 1000, _objectSpread({
now: now
}, twitterStyle));
};
elapsed(0).should.equal('');
elapsed(44.9).should.equal('');
elapsed(45.1).should.equal('1m');
elapsed(1.49 * 60).should.equal('1m');
elapsed(1.51 * 60).should.equal('2m');
elapsed(2.49 * 60).should.equal('2m');
elapsed(2.51 * 60).should.equal('3m'); // …
elapsed(59.49 * 60).should.equal('59m');
elapsed(59.51 * 60).should.equal('1h');
elapsed(1.49 * 60 * 60).should.equal('1h');
elapsed(1.51 * 60 * 60).should.equal('2h');
elapsed(2.49 * 60 * 60).should.equal('2h');
elapsed(2.51 * 60 * 60).should.equal('3h'); // …
elapsed(23.49 * 60 * 60).should.equal('23h');
elapsed(day + 2 * 60 + 60 * 60).should.equal('Apr 9'); // …
// "month" is an approximation.
elapsed(month * 3).should.equal('Jan 10');
elapsed(month * 4).should.equal('Dec 11, 2015');
elapsed(year).should.equal('Apr 11, 2015'); // Test future dates.
// "month" is an approximation.
elapsed(-1 * month * 8).should.equal('Dec 10');
elapsed(-1 * month * 9).should.equal('Jan 9, 2017');
});
it('should format Twitter style relative time (Russian)', function () {
var timeAgo = new JavascriptTimeAgo('ru');
var now = new Date(2016, 3, 10, 22, 59).getTime();
var elapsed = function elapsed(time) {
return timeAgo.format(now - time * 1000, _objectSpread({
now: now
}, twitterStyle));
};
elapsed(45.1).should.equal('1м');
elapsed(59.51 * 60).should.equal('1ч');
elapsed(day + 62 * 60).should.equal('9 апр.');
elapsed(year).should.equal('11 апр. 2015 г.');
});
it('should format Twitter style relative time (Korean)', function () {
var timeAgo = new JavascriptTimeAgo('ko');
var now = new Date(2016, 3, 10, 22, 59).getTime();
var elapsed = function elapsed(time) {
return timeAgo.format(now - time * 1000, _objectSpread({
now: now
}, twitterStyle));
};
elapsed(45.1).should.equal('1분');
elapsed(59.51 * 60).should.equal('1시간'); // elapsed(day + 62 * 60).should.equal('9 апр.')
// elapsed(year).should.equal('11 апр. 2015 г.')
});
});
//# sourceMappingURL=twitter.test.js.map

File diff suppressed because one or more lines are too long