diff options
Diffstat (limited to 'node_modules')
-rw-r--r-- | node_modules/tiny-relative-date/LICENSE.md | 21 | ||||
-rw-r--r-- | node_modules/tiny-relative-date/README.md | 120 | ||||
-rw-r--r-- | node_modules/tiny-relative-date/lib/factory.js | 100 | ||||
-rw-r--r-- | node_modules/tiny-relative-date/lib/index.js | 18 | ||||
-rw-r--r-- | node_modules/tiny-relative-date/package.json | 73 | ||||
-rw-r--r-- | node_modules/tiny-relative-date/src/factory.js | 89 | ||||
-rw-r--r-- | node_modules/tiny-relative-date/src/index.js | 4 | ||||
-rw-r--r-- | node_modules/tiny-relative-date/translations/da.js | 31 | ||||
-rw-r--r-- | node_modules/tiny-relative-date/translations/de.js | 31 | ||||
-rw-r--r-- | node_modules/tiny-relative-date/translations/en-short.js | 31 | ||||
-rw-r--r-- | node_modules/tiny-relative-date/translations/en.js | 31 | ||||
-rw-r--r-- | node_modules/tiny-relative-date/translations/es.js | 31 |
12 files changed, 580 insertions, 0 deletions
diff --git a/node_modules/tiny-relative-date/LICENSE.md b/node_modules/tiny-relative-date/LICENSE.md new file mode 100644 index 000000000..e42aca312 --- /dev/null +++ b/node_modules/tiny-relative-date/LICENSE.md @@ -0,0 +1,21 @@ +MIT License + +Copyright (c) 2017 Joseph Wynn + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. diff --git a/node_modules/tiny-relative-date/README.md b/node_modules/tiny-relative-date/README.md new file mode 100644 index 000000000..4087a7926 --- /dev/null +++ b/node_modules/tiny-relative-date/README.md @@ -0,0 +1,120 @@ +# Relative Date + +[![Build Status](https://travis-ci.org/wildlyinaccurate/tiny-relative-date.png?branch=master)](https://travis-ci.org/wildlyinaccurate/tiny-relative-date) + +Tiny function that provides relative, human-readable dates. + +## Installation + +``` +npm install tiny-relative-date +``` + +## Usage + +The module returns a `relativeDate` function with English translations by default. + +```js +const relativeDate = require('tiny-relative-date') +``` + +The `relativeDate` function accepts date strings or `Date` objects. + +```js +relativeDate('2017-06-25 09:00') // '12 hours ago' +relativeDate(new Date()) // 'just now' +``` + +The value of "now" can also be passed as a second parameter. + +```js +const now = new Date('2017-06-25 08:00:00') +const date = new Date('2017-06-25 07:00:00') + +relativeDate(date, now) // 'an hour ago' +``` + +### Using a non-English locale + +The tiny-relative-date module can be initialised with a locale. See the [translations directory]('./translations') for a list of available locales. + +```js +const relativeDateFactory = require('tiny-relative-date/lib/factory') +const deTranslations = require('tiny-relative-date/translations/de') +const relativeDate = relativeDateFactory(deTranslations) + +relativeDate(new Date()) // 'gerade eben' +``` + +### Using a custom locale + +You can also use a completely custom locale by passing a translations object instead of a locale string. Translations can be plain strings with a `{{time}}` placeholder, or they can be functions. See the **Adding new locales** section below for a list of translation keys. + +```js +const relativeDateFactory = require('tiny-relative-date/lib/factory') +const relativeDate = relativeDateFactory({ + hoursAgo: '{{time}}h ago', + daysAgo: (days) => `${days * 24}h ago` +}) + +relativeDate('2017-06-25 07:00:00') // '2h ago' +relativeDate('2017-06-24 06:00:00') // '27h ago' +``` + +## Contributing + +Contributions are welcome! Running this project locally requires Git and Node.js. + +``` +git clone git@github.com:wildlyinaccurate/tiny-relative-date.git +cd tiny-relative-date/ +npm install +``` + +Once you are set up, you can make changes to files in the `src/`, `spec/` and `translations/` directories. Build any changes you make by running + +``` +npm run build +``` + +And run the tests with + +``` +npm run test +``` + +### Adding new locales + +If you would like to add a new locale, please create a JSON file in the `translations` directory and ensure it has the following keys: + +| Key | Default value ("en" locale) | +|------------------------|-----------------------------| +| `justNow` | just now | +| `secondsAgo` | {{time}} seconds ago | +| `aMinuteAgo` | a minute ago | +| `minutesAgo` | {{time}} minutes ago | +| `anHourAgo` | an hour ago | +| `hoursAgo` | {{time}} hours ago | +| `aDayAgo` | yesterday | +| `daysAgo` | {{time}} days ago | +| `aWeekAgo` | a week ago | +| `weeksAgo` | {{time}} weeks ago | +| `aMonthAgo` | a month ago | +| `monthsAgo` | {{time}} months ago | +| `aYearAgo` | a year ago | +| `yearsAgo` | {{time}} years ago | +| `overAYearAgo` | over a year ago | +| `secondsFromNow` | {{time}} seconds from now | +| `aMinuteFromNow` | a minute from now | +| `minutesFromNow` | {{time}} minutes from now | +| `anHourFromNow` | an hour from now | +| `hoursFromNow` | {{time}} hours from now | +| `aDayFromNow` | tomorrow | +| `daysFromNow` | {{time}} days from now | +| `aWeekFromNow` | a week from now | +| `weeksFromNow` | {{time}} weeks from now | +| `aMonthFromNow` | a month from now | +| `monthsFromNow` | {{time}} months from now | +| `aYearFromNow` | a year from now | +| `yearsFromNow` | {{time}} years from now | +| `overAYearFromNow` | over a year from now | diff --git a/node_modules/tiny-relative-date/lib/factory.js b/node_modules/tiny-relative-date/lib/factory.js new file mode 100644 index 000000000..ac9016144 --- /dev/null +++ b/node_modules/tiny-relative-date/lib/factory.js @@ -0,0 +1,100 @@ +'use strict'; + +Object.defineProperty(exports, "__esModule", { + value: true +}); +exports.default = relativeDateFactory; +var calculateDelta = function calculateDelta(now, date) { + return Math.round(Math.abs(now - date) / 1000); +}; + +function relativeDateFactory(translations) { + return function relativeDate(date) { + var now = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : new Date(); + + if (!(date instanceof Date)) { + date = new Date(date); + } + + var delta = null; + + var minute = 60; + var hour = minute * 60; + var day = hour * 24; + var week = day * 7; + var month = day * 30; + var year = day * 365; + + delta = calculateDelta(now, date); + + if (delta > day && delta < week) { + date = new Date(date.getFullYear(), date.getMonth(), date.getDate(), 0, 0, 0); + delta = calculateDelta(now, date); + } + + var translate = function translate(translatePhrase, timeValue) { + var key = void 0; + + if (translatePhrase === 'justNow') { + key = translatePhrase; + } else if (now >= date) { + key = translatePhrase + 'Ago'; + } else { + key = translatePhrase + 'FromNow'; + } + + var translation = translations[key]; + + if (typeof translation === 'function') { + return translation(timeValue); + } + + return translation.replace('{{time}}', timeValue); + }; + + switch (false) { + case !(delta < 30): + return translate('justNow'); + + case !(delta < minute): + return translate('seconds', delta); + + case !(delta < 2 * minute): + return translate('aMinute'); + + case !(delta < hour): + return translate('minutes', Math.floor(delta / minute)); + + case Math.floor(delta / hour) !== 1: + return translate('anHour'); + + case !(delta < day): + return translate('hours', Math.floor(delta / hour)); + + case !(delta < day * 2): + return translate('aDay'); + + case !(delta < week): + return translate('days', Math.floor(delta / day)); + + case Math.floor(delta / week) !== 1: + return translate('aWeek'); + + case !(delta < month): + return translate('weeks', Math.floor(delta / week)); + + case Math.floor(delta / month) !== 1: + return translate('aMonth'); + + case !(delta < year): + return translate('months', Math.floor(delta / month)); + + case Math.floor(delta / year) !== 1: + return translate('aYear'); + + default: + return translate('overAYear'); + } + }; +} +module.exports = exports['default'];
\ No newline at end of file diff --git a/node_modules/tiny-relative-date/lib/index.js b/node_modules/tiny-relative-date/lib/index.js new file mode 100644 index 000000000..ed8a82ad6 --- /dev/null +++ b/node_modules/tiny-relative-date/lib/index.js @@ -0,0 +1,18 @@ +'use strict'; + +Object.defineProperty(exports, "__esModule", { + value: true +}); + +var _factory = require('./factory'); + +var _factory2 = _interopRequireDefault(_factory); + +var _en = require('../translations/en'); + +var _en2 = _interopRequireDefault(_en); + +function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } + +exports.default = (0, _factory2.default)(_en2.default); +module.exports = exports['default'];
\ No newline at end of file diff --git a/node_modules/tiny-relative-date/package.json b/node_modules/tiny-relative-date/package.json new file mode 100644 index 000000000..8744d444e --- /dev/null +++ b/node_modules/tiny-relative-date/package.json @@ -0,0 +1,73 @@ +{ + "_from": "tiny-relative-date", + "_id": "tiny-relative-date@1.3.0", + "_inBundle": false, + "_integrity": "sha512-MOQHpzllWxDCHHaDno30hhLfbouoYlOI8YlMNtvKe1zXbjEVhbcEovQxvZrPvtiYW630GQDoMMarCnjfyfHA+A==", + "_location": "/tiny-relative-date", + "_phantomChildren": {}, + "_requested": { + "type": "tag", + "registry": true, + "raw": "tiny-relative-date", + "name": "tiny-relative-date", + "escapedName": "tiny-relative-date", + "rawSpec": "", + "saveSpec": null, + "fetchSpec": "latest" + }, + "_requiredBy": [ + "#USER", + "/" + ], + "_resolved": "https://registry.npmjs.org/tiny-relative-date/-/tiny-relative-date-1.3.0.tgz", + "_shasum": "fa08aad501ed730f31cc043181d995c39a935e07", + "_spec": "tiny-relative-date", + "_where": "/Users/zkat/Documents/code/npm", + "author": { + "name": "Joseph Wynn", + "email": "joseph@wildlyinaccurate.com", + "url": "https://wildlyinaccurate.com/" + }, + "bugs": { + "url": "https://github.com/wildlyinaccurate/relative-date/issues" + }, + "bundleDependencies": false, + "deprecated": false, + "description": "Tiny function that provides relative, human-readable dates.", + "devDependencies": { + "babel-cli": "^6.24.1", + "babel-plugin-add-module-exports": "^0.2.1", + "babel-preset-es2015": "^6.24.1", + "babel-register": "^6.24.1", + "eslint": "^4.1.0", + "eslint-config-standard": "^10.2.1", + "eslint-plugin-import": "^2.6.0", + "eslint-plugin-node": "^5.0.0", + "eslint-plugin-promise": "^3.5.0", + "eslint-plugin-standard": "^3.0.1", + "jasmine": "^2.6.0", + "jasmine-spec-reporter": "^4.1.1" + }, + "files": [ + "lib/", + "src/", + "translations/" + ], + "homepage": "https://github.com/wildlyinaccurate/relative-date#readme", + "license": "MIT", + "main": "lib/index.js", + "module": "src/index.js", + "name": "tiny-relative-date", + "repository": { + "type": "git", + "url": "git+https://github.com/wildlyinaccurate/relative-date.git" + }, + "scripts": { + "build": "babel src -d lib", + "eslint": "eslint --fix src/**/*.js", + "jasmine": "jasmine", + "prepublish": "npm run build", + "test": "npm run eslint && npm run jasmine" + }, + "version": "1.3.0" +} diff --git a/node_modules/tiny-relative-date/src/factory.js b/node_modules/tiny-relative-date/src/factory.js new file mode 100644 index 000000000..689359bcf --- /dev/null +++ b/node_modules/tiny-relative-date/src/factory.js @@ -0,0 +1,89 @@ +const calculateDelta = (now, date) => Math.round(Math.abs(now - date) / 1000) + +export default function relativeDateFactory (translations) { + return function relativeDate (date, now = new Date()) { + if (!(date instanceof Date)) { + date = new Date(date) + } + + let delta = null + + const minute = 60 + const hour = minute * 60 + const day = hour * 24 + const week = day * 7 + const month = day * 30 + const year = day * 365 + + delta = calculateDelta(now, date) + + if (delta > day && delta < week) { + date = new Date(date.getFullYear(), date.getMonth(), date.getDate(), 0, 0, 0) + delta = calculateDelta(now, date) + } + + const translate = (translatePhrase, timeValue) => { + let key + + if (translatePhrase === 'justNow') { + key = translatePhrase + } else if (now >= date) { + key = `${translatePhrase}Ago` + } else { + key = `${translatePhrase}FromNow` + } + + const translation = translations[key] + + if (typeof translation === 'function') { + return translation(timeValue) + } + + return translation.replace('{{time}}', timeValue) + } + + switch (false) { + case !(delta < 30): + return translate('justNow') + + case !(delta < minute): + return translate('seconds', delta) + + case !(delta < 2 * minute): + return translate('aMinute') + + case !(delta < hour): + return translate('minutes', Math.floor(delta / minute)) + + case Math.floor(delta / hour) !== 1: + return translate('anHour') + + case !(delta < day): + return translate('hours', Math.floor(delta / hour)) + + case !(delta < day * 2): + return translate('aDay') + + case !(delta < week): + return translate('days', Math.floor(delta / day)) + + case Math.floor(delta / week) !== 1: + return translate('aWeek') + + case !(delta < month): + return translate('weeks', Math.floor(delta / week)) + + case Math.floor(delta / month) !== 1: + return translate('aMonth') + + case !(delta < year): + return translate('months', Math.floor(delta / month)) + + case Math.floor(delta / year) !== 1: + return translate('aYear') + + default: + return translate('overAYear') + } + } +} diff --git a/node_modules/tiny-relative-date/src/index.js b/node_modules/tiny-relative-date/src/index.js new file mode 100644 index 000000000..c2cef6889 --- /dev/null +++ b/node_modules/tiny-relative-date/src/index.js @@ -0,0 +1,4 @@ +import relativeDateFactory from './factory' +import enTranslations from '../translations/en' + +export default relativeDateFactory(enTranslations) diff --git a/node_modules/tiny-relative-date/translations/da.js b/node_modules/tiny-relative-date/translations/da.js new file mode 100644 index 000000000..dedc17d97 --- /dev/null +++ b/node_modules/tiny-relative-date/translations/da.js @@ -0,0 +1,31 @@ +module.exports = { + justNow: "ligenu", + secondsAgo: "{{time}} sekunder siden", + aMinuteAgo: "et minut siden", + minutesAgo: "{{time}} minutter siden", + anHourAgo: "en time siden", + hoursAgo: "{{time}} timer siden", + aDayAgo: "i går", + daysAgo: "{{time}} dage siden", + aWeekAgo: "en uge siden", + weeksAgo: "{{time}} uger siden", + aMonthAgo: "en måned siden", + monthsAgo: "{{time}} måneder siden", + aYearAgo: "et år siden", + yearsAgo: "{{time}} år siden", + overAYearAgo: "over et år siden", + secondsFromNow: "om {{time}} sekunder", + aMinuteFromNow: "om et minut", + minutesFromNow: "om {{time}} minutter", + anHourFromNow: "om en time", + hoursFromNow: "om {{time}} timer", + aDayFromNow: "i morgen", + daysFromNow: "om {{time}} dage", + aWeekFromNow: "om en uge", + weeksFromNow: "om {{time}} uger", + aMonthFromNow: "om en måned", + monthsFromNow: "om {{time}} måneder", + aYearFromNow: "om et år", + yearsFromNow: "om {{time}} år", + overAYearFromNow: "om over et år" +} diff --git a/node_modules/tiny-relative-date/translations/de.js b/node_modules/tiny-relative-date/translations/de.js new file mode 100644 index 000000000..c0342e190 --- /dev/null +++ b/node_modules/tiny-relative-date/translations/de.js @@ -0,0 +1,31 @@ +module.exports = { + justNow: "gerade eben", + secondsAgo: "vor {{time}} Sekunden", + aMinuteAgo: "vor einer Minute", + minutesAgo: "vor {{time}} Minuten", + anHourAgo: "vor einer Stunde", + hoursAgo: "vor {{time}} Stunden", + aDayAgo: "gestern", + daysAgo: "vor {{time}} Tagen", + aWeekAgo: "letzte Woche", + weeksAgo: "vor {{time}} Wochen", + aMonthAgo: "letzten Monat", + monthsAgo: "vor {{time}} Monaten", + aYearAgo: "letztes Jahr", + yearsAgo: "vor {{time}} Jahren", + overAYearAgo: "vor über einem Jahr", + secondsFromNow: "in {{time}} Sekunden", + aMinuteFromNow: "in einer Minute", + minutesFromNow: "in {{time}} Minuten", + anHourFromNow: "in einer Stunde", + hoursFromNow: "in {{time}} Stunden", + aDayFromNow: "morgen", + daysFromNow: "in {{time}} Tagen", + aWeekFromNow: "nächste Woche", + weeksFromNow: "in {{time}} Wochen", + aMonthFromNow: "nächsten Monat", + monthsFromNow: "in {{time}} Monaten", + aYearFromNow: "nächstes Jahr", + yearsFromNow: "in {{time}} Jahren", + overAYearFromNow: "in über einem Jahr" +} diff --git a/node_modules/tiny-relative-date/translations/en-short.js b/node_modules/tiny-relative-date/translations/en-short.js new file mode 100644 index 000000000..b368d1921 --- /dev/null +++ b/node_modules/tiny-relative-date/translations/en-short.js @@ -0,0 +1,31 @@ +module.exports = { + justNow: "now", + secondsAgo: "{{time}}s", + aMinuteAgo: "1m", + minutesAgo: "{{time}}m", + anHourAgo: "1h", + hoursAgo: "{{time}}h", + aDayAgo: "1d", + daysAgo: "{{time}}d", + aWeekAgo: "1w", + weeksAgo: "{{time}}w", + aMonthAgo: '4w', + monthsAgo: (months) => `${Math.round(months / 12 * 52)}w`, + aYearAgo: "1y", + yearsAgo: "{{time}}y", + overAYearAgo: "1y+", + secondsFromNow: "+{{time}}s", + aMinuteFromNow: "+1m", + minutesFromNow: "+{{time}}m", + anHourFromNow: "+1h", + hoursFromNow: "+{{time}}h", + aDayFromNow: "+1d", + daysFromNow: "+{{time}}d", + aWeekFromNow: "+1w", + weeksFromNow: "+{{time}}w", + aMonthFromNow: '+4w', + monthsFromNow: (months) => `+${Math.round(months / 12 * 52)}w`, + aYearFromNow: "+1y", + yearsFromNow: "+{{time}}y", + overAYearFromNow: "+1y+" +} diff --git a/node_modules/tiny-relative-date/translations/en.js b/node_modules/tiny-relative-date/translations/en.js new file mode 100644 index 000000000..8411bf034 --- /dev/null +++ b/node_modules/tiny-relative-date/translations/en.js @@ -0,0 +1,31 @@ +module.exports = { + justNow: "just now", + secondsAgo: "{{time}} seconds ago", + aMinuteAgo: "a minute ago", + minutesAgo: "{{time}} minutes ago", + anHourAgo: "an hour ago", + hoursAgo: "{{time}} hours ago", + aDayAgo: "yesterday", + daysAgo: "{{time}} days ago", + aWeekAgo: "a week ago", + weeksAgo: "{{time}} weeks ago", + aMonthAgo: "a month ago", + monthsAgo: "{{time}} months ago", + aYearAgo: "a year ago", + yearsAgo: "{{time}} years ago", + overAYearAgo: "over a year ago", + secondsFromNow: "{{time}} seconds from now", + aMinuteFromNow: "a minute from now", + minutesFromNow: "{{time}} minutes from now", + anHourFromNow: "an hour from now", + hoursFromNow: "{{time}} hours from now", + aDayFromNow: "tomorrow", + daysFromNow: "{{time}} days from now", + aWeekFromNow: "a week from now", + weeksFromNow: "{{time}} weeks from now", + aMonthFromNow: "a month from now", + monthsFromNow: "{{time}} months from now", + aYearFromNow: "a year from now", + yearsFromNow: "{{time}} years from now", + overAYearFromNow: "over a year from now" +} diff --git a/node_modules/tiny-relative-date/translations/es.js b/node_modules/tiny-relative-date/translations/es.js new file mode 100644 index 000000000..fac622ff8 --- /dev/null +++ b/node_modules/tiny-relative-date/translations/es.js @@ -0,0 +1,31 @@ +module.exports = { + justNow: "recién", + secondsAgo: "hace {{time}} segundos", + aMinuteAgo: "hace un minuto", + minutesAgo: "hace {{time}} minutos", + anHourAgo: "hace una hora", + hoursAgo: "hace {{time}} horas", + aDayAgo: "ayer", + daysAgo: "hace {{time}} días", + aWeekAgo: "hace una semana", + weeksAgo: "hace {{time}} semanas", + aMonthAgo: "hace un mes", + monthsAgo: "hace {{time}} meses", + aYearAgo: "hace un año", + yearsAgo: "hace {{time}} años", + overAYearAgo: "hace mas de un año", + secondsFromNow: "dentro de {{time}} segundos", + aMinuteFromNow: "dentro de un minuto", + minutesFromNow: "dentro de {{time}} minutos", + anHourFromNow: "dentro de una hora", + hoursFromNow: "dentro de {{time}} horas", + aDayFromNow: "mañana", + daysFromNow: "dentro de {{time}} días", + aWeekFromNow: "dentro de una semana", + weeksFromNow: "dentro de {{time}} semanas", + aMonthFromNow: "dentro de un mes", + monthsFromNow: "dentro de {{time}} meses", + aYearFromNow: "dentro de un año", + yearsFromNow: "dentro de {{time}} años", + overAYearFromNow: "dentro de mas de un año" +} |