javascript-time-ago
Advanced tools
Comparing version 0.2.12 to 0.3.0
@@ -95,3 +95,3 @@ 'use strict'; | ||
// 20 hours ago | ||
// yesterday | ||
// a day ago | ||
// 2 days ago | ||
@@ -98,0 +98,0 @@ // 5 days ago |
@@ -114,3 +114,3 @@ 'use strict'; | ||
// 20 hours | ||
// yesterday | ||
// a day ago | ||
// 2 days | ||
@@ -117,0 +117,0 @@ // a week |
@@ -384,3 +384,3 @@ 'use strict'; | ||
var locale_parts = locale.toLowerCase().split('-'); | ||
var locale_parts = locale.split('-'); | ||
@@ -419,11 +419,18 @@ while (locale_parts.length) { | ||
// Adds locale data | ||
Javascript_time_ago.locale = function (locale, locale_data) { | ||
var locale_data_map = {}; | ||
Javascript_time_ago.locale = function (locale_data) { | ||
var locale = void 0; | ||
var locale_data_map = void 0; | ||
// Supports multiple locale variations | ||
// (e.g. "default", "short", "normal", "long", etc) | ||
if (!locale_data.default) { | ||
// Convert from CLDR format (if needed) | ||
locale_data_map.default = from_CLDR(locale_data); | ||
if (locale_data.main) { | ||
locale = (0, _keys2.default)(locale_data.main)[0]; | ||
// Convert from CLDR format | ||
locale_data_map = from_CLDR(locale_data); | ||
} else { | ||
locale = locale_data.locale; | ||
locale_data_map = {}; | ||
// Supports multiple locale variations | ||
// (e.g. "default", "short", "normal", "long", etc) | ||
var _iteratorNormalCompletion4 = true; | ||
@@ -437,4 +444,5 @@ var _didIteratorError4 = false; | ||
// Convert from CLDR format (if needed) | ||
locale_data_map[key] = from_CLDR(locale_data[key]); | ||
if (key !== 'locale') { | ||
locale_data_map[key] = locale_data[key]; | ||
} | ||
} | ||
@@ -457,4 +465,14 @@ } catch (err) { | ||
// Guard against malformed input | ||
if (!locale) { | ||
throw new Error('Couldn\'t determine locale for this locale data. Make sure the "locale" property is present.'); | ||
} | ||
// Ensure default formatting flavour is set | ||
if (!locale_data_map.default) { | ||
locale_data_map.default = locale_data_map.long || locale_data_map[(0, _keys2.default)(locale_data_map)[0]]; | ||
} | ||
// Store locale specific messages in the static variable | ||
Javascript_time_ago.locale_data[locale.toLowerCase()] = locale_data_map; | ||
Javascript_time_ago.locale_data[locale] = locale_data_map; | ||
@@ -469,4 +487,14 @@ // (will be added manually by this library user) | ||
function from_CLDR(data) { | ||
var converted = {}; | ||
// the usual time measurement units | ||
var units = ['second', 'minute', 'hour', 'day', 'week', 'month', 'year']; | ||
// result | ||
var converted = { long: {} }; | ||
// detects the short flavour of labels (yr., mo., etc) | ||
var short = /-short$/; | ||
var locale = (0, _keys2.default)(data.main)[0]; | ||
data = data.main[locale].dates.fields; | ||
var _iteratorNormalCompletion5 = true; | ||
@@ -480,40 +508,39 @@ var _didIteratorError5 = false; | ||
// take only the usual time measurement units | ||
if (units.indexOf(key) < 0 && units.indexOf(key.replace(short, '')) < 0) { | ||
continue; | ||
} | ||
var entry = data[key]; | ||
var converted_entry = {}; | ||
if (entry.previous) { | ||
converted_entry.previous = entry.previous; | ||
} | ||
// if a key ends with `-short`, then it's a "short" flavour | ||
if (short.test(key)) { | ||
if (!converted.short) { | ||
converted.short = {}; | ||
} | ||
if (entry.current) { | ||
converted_entry.current = entry.current; | ||
converted.short[key.replace(short, '')] = converted_entry; | ||
} else { | ||
converted.long[key] = converted_entry; | ||
} | ||
if (entry.next) { | ||
converted_entry.next = entry.next; | ||
} | ||
// the "relative" values aren't suitable for "ago" or "in a" cases, | ||
// because "1 year ago" != "last year" | ||
if (entry.past) { | ||
converted_entry.past = entry.past; | ||
} | ||
// if (entry['relative-type--1']) | ||
// { | ||
// converted_entry.previous = entry['relative-type--1'] | ||
// } | ||
if (entry.future) { | ||
converted_entry.future = entry.future; | ||
} | ||
// if (entry['relative-type-0']) | ||
// { | ||
// converted_entry.current = entry['relative-type-0'] | ||
// } | ||
converted[key] = converted_entry; | ||
// if (entry['relative-type-1']) | ||
// { | ||
// converted_entry.next = entry['relative-type-1'] | ||
// } | ||
if (entry['relative-type--1']) { | ||
converted_entry.previous = entry['relative-type--1']; | ||
} | ||
if (entry['relative-type-0']) { | ||
converted_entry.current = entry['relative-type-0']; | ||
} | ||
if (entry['relative-type-1']) { | ||
converted_entry.next = entry['relative-type-1']; | ||
} | ||
if (entry['relativeTime-type-past']) { | ||
@@ -520,0 +547,0 @@ var past = entry['relativeTime-type-past']; |
export { default } from './source/time ago' | ||
export { a_day, days_in_a_month, days_in_a_year, gradation } from './source/classify elapsed' | ||
// Doesn't work with Rollup, so commented that out | ||
// https://github.com/halt-hammerzeit/javascript-time-ago/issues/1 | ||
// Languages will have to be loaded manually. | ||
// | ||
// // Add all locale data to `javascript-time-ago`. | ||
// // This module will be ignored when bundling | ||
// // for the browser with Browserify/Webpack. | ||
// global.javascript_time_ago = javascript_time_ago | ||
// require('./locales') | ||
// delete global.javascript_time_ago | ||
export { a_day, days_in_a_month, days_in_a_year, gradation } from './source/classify elapsed' |
'use strict' | ||
var javascript_time_ago = require('./build/time ago')['default'] | ||
// Doesn't work with Rollup, so commented that out | ||
// https://github.com/halt-hammerzeit/javascript-time-ago/issues/1 | ||
// Languages will have to be loaded manually. | ||
// | ||
// // Add all locale data to `javascript-time-ago`. | ||
// // This module will be ignored when bundling | ||
// // for the browser with Browserify/Webpack. | ||
// global.javascript_time_ago = javascript_time_ago | ||
// require('./locales') | ||
// delete global.javascript_time_ago | ||
exports = module.exports = javascript_time_ago | ||
exports = module.exports = require('./build/time ago')['default'] | ||
exports['default'] = exports | ||
@@ -18,0 +5,0 @@ |
@@ -1,8 +0,2 @@ | ||
var path = require('path') | ||
var fs = require('fs') | ||
fs.readdirSync(path.resolve(__dirname, 'locales')).forEach(function(file) | ||
{ | ||
var locale = file.replace(/\.js$/, '') | ||
javascript_time_ago.locale(locale, require('./locales/' + locale)) | ||
}) | ||
export { en } from './locales/en' | ||
export { ru } from './locales/ru' |
var long = { | ||
"year": { | ||
"previous": "a year ago", | ||
"current": "this year", | ||
"next": "in a year", | ||
@@ -25,3 +24,2 @@ "future": { | ||
"previous": "a month ago", | ||
"current": "this month", | ||
"next": "in a month", | ||
@@ -39,3 +37,2 @@ "future": { | ||
"previous": "a week ago", | ||
"current": "this week", | ||
"next": "in a week", | ||
@@ -52,5 +49,4 @@ "future": { | ||
"day": { | ||
"previous": "yesterday", | ||
"current": "today", | ||
"next": "tomorrow", | ||
"previous": "a day ago", | ||
"next": "in a day", | ||
"future": { | ||
@@ -67,3 +63,2 @@ "one": "in {0} day", | ||
"previous": "an hour ago", | ||
"current": "this hour", | ||
"next": "in an hour", | ||
@@ -89,3 +84,2 @@ "future": { | ||
"previous": "a minute ago", | ||
"current": "this minute", | ||
"next": "in a minute", | ||
@@ -125,3 +119,2 @@ "future": { | ||
"previous": "a year", | ||
"current": "this year", | ||
"next": "a year", | ||
@@ -147,3 +140,2 @@ "future": { | ||
"previous": "a month", | ||
"current": "this month", | ||
"next": "a month", | ||
@@ -161,3 +153,2 @@ "future": { | ||
"previous": "a week", | ||
"current": "this week", | ||
"next": "a week", | ||
@@ -174,5 +165,4 @@ "future": { | ||
"day": { | ||
"previous": "yesterday", | ||
"current": "today", | ||
"next": "tomorrow", | ||
"previous": "a day ago", | ||
"next": "in a day", | ||
"future": { | ||
@@ -189,3 +179,2 @@ "one": "{0} day", | ||
"previous": "an hour", | ||
"current": "this hour", | ||
"next": "an hour", | ||
@@ -210,3 +199,2 @@ "future": { | ||
"minute": { | ||
"current": "this minute", | ||
"future": { | ||
@@ -274,5 +262,4 @@ "one": "{0} minute", | ||
"day": { | ||
"previous": "yesterday", | ||
"current": "today", | ||
"next": "tomorrow", | ||
"previous": "a day ago", | ||
"next": "in a day", | ||
"future": { | ||
@@ -360,5 +347,4 @@ "one": "in {0} day", | ||
"day": { | ||
"previous": "yesterday", | ||
"current": "today", | ||
"next": "tomorrow", | ||
"previous": "a day ago", | ||
"next": "in a day", | ||
"future": { | ||
@@ -440,5 +426,4 @@ "one": "{0} day", | ||
"day": { | ||
"previous": "yesterday", | ||
"current": "today", | ||
"next": "tomorrow", | ||
"previous": "a day ago", | ||
"next": "in a day", | ||
"future": { | ||
@@ -488,2 +473,3 @@ "other": "{0}d" | ||
{ | ||
locale : 'en', | ||
default : long, | ||
@@ -490,0 +476,0 @@ |
@@ -527,5 +527,2 @@ var long = { | ||
"day": { | ||
"previous": "yesterday", | ||
"current": "today", | ||
"next": "tomorrow", | ||
"future": { | ||
@@ -575,2 +572,3 @@ "other": "{0}д" | ||
{ | ||
locale : 'ru', | ||
default : long, | ||
@@ -577,0 +575,0 @@ |
{ | ||
"name": "javascript-time-ago", | ||
"version": "0.2.12", | ||
"version": "0.3.0", | ||
"description": "International highly customizable relative time formatting", | ||
@@ -5,0 +5,0 @@ "main": "index.umd.js", |
@@ -52,4 +52,4 @@ # javascript-time-ago | ||
// | ||
javascript_time_ago.locale('en', require('javascript-time-ago/locales/en')) | ||
javascript_time_ago.locale('ru', require('javascript-time-ago/locales/ru')) | ||
javascript_time_ago.locale(require('javascript-time-ago/locales/en')) | ||
javascript_time_ago.locale(require('javascript-time-ago/locales/ru')) | ||
@@ -82,3 +82,3 @@ // Load number pluralization functions for the locales. | ||
time_ago_english.format(new Date(Date.now() - 24 * 60 * 60 * 1000)) | ||
// "yesterday" | ||
// "a day ago" | ||
@@ -142,3 +142,3 @@ const time_ago_russian = new javascript_time_ago('ru-RU') | ||
* 20 hours | ||
* yesterday | ||
* a day ago | ||
* 2 days | ||
@@ -188,5 +188,5 @@ * 3 days | ||
{ | ||
"previous": "yesterday", | ||
"previous": "a day ago", | ||
"now": "today", | ||
"next": "tomorrow", | ||
"next": "in a day", | ||
"past": | ||
@@ -221,13 +221,13 @@ { | ||
"day": { | ||
"displayName": "day", // `displayName` field is not used | ||
"relative-type--1": "yesterday", // is optional | ||
"relative-type-0": "today", // is optional | ||
"relative-type-1": "tomorrow", // is optional | ||
"displayName": "day", // ignored | ||
"relative-type--1": "yesterday", // ignored | ||
"relative-type-0": "today", // ignored | ||
"relative-type-1": "tomorrow", // ignored | ||
"relativeTime-type-future": { | ||
"relativeTimePattern-count-one": "in {0} day", | ||
"relativeTimePattern-count-other": "in {0} days" | ||
"relativeTimePattern-count-one" : "in {0} day", | ||
"relativeTimePattern-count-other" : "in {0} days" | ||
}, | ||
"relativeTime-type-past": { | ||
"relativeTimePattern-count-one": "{0} day ago", | ||
"relativeTimePattern-count-other": "{0} days ago" | ||
"relativeTimePattern-count-one" : "{0} day ago", | ||
"relativeTimePattern-count-other" : "{0} days ago" | ||
} | ||
@@ -234,0 +234,0 @@ }, |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
101410
17
1899