Last active
November 12, 2015 05:18
-
-
Save jorinvo/b4eaa64bca5348aa2709 to your computer and use it in GitHub Desktop.
Compare timeago
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module.exports = { | |
emptyDoc: 'Write …', | |
search: 'Search …', | |
footer: 'write lite, open source', | |
share: 'share', | |
open: 'open', | |
modified: 'modified', | |
welcome: require('./welcome.txt'), | |
secondsAgo: function (x) { | |
if (x === 1) return 'a second ago'; | |
return x + ' seconds ago'; | |
}, | |
minutesAgo: function (x) { | |
if (x === 1) return 'a minute ago'; | |
return x + ' minutes ago'; | |
}, | |
hoursAgo: function (x) { | |
if (x === 1) return 'an hour ago'; | |
return x + ' hours ago'; | |
}, | |
daysAgo: function (x) { | |
if (x === 1) return 'a day ago'; | |
return x + ' days ago'; | |
}, | |
monthsAgo: function (x) { | |
if (x === 1) return 'a month ago'; | |
return x + ' months ago'; | |
}, | |
yearsAgo: function (x) { | |
if (x === 1) return 'a year ago'; | |
return x + ' years ago'; | |
} | |
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function plural(word, num) { | |
var forms = word.split('_'); | |
return num === 1 ? forms[0] : forms[1]; | |
} | |
module.exports = { | |
emptyDoc: 'Write …', | |
search: 'Search …', | |
footer: 'write lite, open source', | |
share: 'share', | |
open: 'open', | |
modified: 'modified', | |
welcome: require('./welcome.txt'), | |
timeAgo: function relativeTimeWithPlural(number, key) { | |
var format = { | |
'ss': 'second_seconds', | |
'mm': 'minute_minutes', | |
'hh': 'hour_hours', | |
'dd': 'day_days', | |
'MM': 'month_months', | |
'yy': 'year_years' | |
}; | |
if (number === 1) { | |
return 'a ' + plural(format[key], +number) + ' ago'; | |
} | |
else { | |
return number + ' ' + plural(format[key], +number) + ' ago'; | |
} | |
} | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment