diff --git a/README.md b/README.md index d8770aa..135b676 100644 --- a/README.md +++ b/README.md @@ -63,6 +63,13 @@ or import with `script` tag in html file and access global variable `timeago`. format('2016-06-12', 'en_US'); ``` +## CDN + +Alternatively to NPM, you can also use a CDN which will reflect the latest version as soon as it is published to npm. + +```html + +``` ## API diff --git a/__tests__/lang/tk.spec.ts b/__tests__/lang/tk.spec.ts new file mode 100644 index 0000000..9c84cd4 --- /dev/null +++ b/__tests__/lang/tk.spec.ts @@ -0,0 +1,103 @@ +import { advanceTo, clear } from 'jest-date-mock'; +import { format, register } from '../../src'; +import tk from '../../src/lang/tk'; + +register('tk', tk); + +let date = new Date(); + +beforeEach(() => { + advanceTo(0); + date = new Date(); +}); +afterEach(() => { + clear(); +}); +describe('tk', () => { + test('time ago', () => { + advanceTo(9 * 1000); + expect(format(date, 'tk')).toEqual('biraz öň'); + + advanceTo(30 * 1000); + expect(format(date, 'tk')).toEqual('30 sekunt öň'); + + advanceTo(1000 * 60); + expect(format(date, 'tk')).toEqual('1 minut öň'); + + advanceTo(1000 * 60 * 30); + expect(format(date, 'tk')).toEqual('30 minut öň'); + + advanceTo(1000 * 60 * 60); + expect(format(date, 'tk')).toEqual('1 sagat öň'); + + advanceTo(1000 * 60 * 60 * 8); + expect(format(date, 'tk')).toEqual('8 sagat öň'); + + advanceTo(1000 * 60 * 60 * 24); + expect(format(date, 'tk')).toEqual('1 gün öň'); + + advanceTo(1000 * 60 * 60 * 24 * 3); + expect(format(date, 'tk')).toEqual('3 gün öň'); + + advanceTo(1000 * 60 * 60 * 24 * 7); + expect(format(date, 'tk')).toEqual('1 hepde öň'); + + advanceTo(1000 * 60 * 60 * 24 * 7 * 3); + expect(format(date, 'tk')).toEqual('3 hepde öň'); + + advanceTo(1000 * 60 * 60 * 24 * 31); + expect(format(date, 'tk')).toEqual('1 aý öň'); + + advanceTo(1000 * 60 * 60 * 24 * 31 * 4); + expect(format(date, 'tk')).toEqual('4 aý öň'); + + advanceTo(1000 * 60 * 60 * 24 * 366); + expect(format(date, 'tk')).toEqual('1 ýyl öň'); + + advanceTo(1000 * 60 * 60 * 24 * 366 * 10); + expect(format(date, 'tk')).toEqual('10 ýyl öň'); + }); + test('time in', () => { + advanceTo(-9 * 1000); + expect(format(date, 'tk')).toEqual('şuwagt'); + + advanceTo(-30 * 1000); + expect(format(date, 'tk')).toEqual('30 sekuntdan'); + + advanceTo(-1000 * 60); + expect(format(date, 'tk')).toEqual('1 minutdan'); + + advanceTo(-1000 * 60 * 30); + expect(format(date, 'tk')).toEqual('30 minutdan'); + + advanceTo(-1000 * 60 * 60); + expect(format(date, 'tk')).toEqual('1 sagatdan'); + + advanceTo(-1000 * 60 * 60 * 8); + expect(format(date, 'tk')).toEqual('8 sagatdan'); + + advanceTo(-1000 * 60 * 60 * 24); + expect(format(date, 'tk')).toEqual('1 günden'); + + advanceTo(-1000 * 60 * 60 * 24 * 3); + expect(format(date, 'tk')).toEqual('3 günden'); + + advanceTo(-1000 * 60 * 60 * 24 * 7); + expect(format(date, 'tk')).toEqual('1 hepdeden'); + + advanceTo(-1000 * 60 * 60 * 24 * 7 * 3); + expect(format(date, 'tk')).toEqual('3 hepdeden'); + + advanceTo(-1000 * 60 * 60 * 24 * 31); + expect(format(date, 'tk')).toEqual('1 aýdan'); + + advanceTo(-1000 * 60 * 60 * 24 * 31 * 4); + expect(format(date, 'tk')).toEqual('4 aýdan'); + + advanceTo(-1000 * 60 * 60 * 24 * 366); + expect(format(date, 'tk')).toEqual('1 ýyldan'); + + advanceTo(-1000 * 60 * 60 * 24 * 366 * 10); + expect(format(date, 'tk')).toEqual('10 ýyldan'); + }); +}); diff --git a/package.json b/package.json index 0ae86c3..0427e13 100644 --- a/package.json +++ b/package.json @@ -6,6 +6,8 @@ "description": "timeago.js is a simple library (only 1kb) to used to format datetime with `*** time ago` statement. eg: '3 hours ago'. localization supported.", "main": "lib/index.js", "module": "esm/index.js", + "unpkg": "dist/timeago.min.js", + "browser": "dist/timeago.min.js", "files": [ "lib", "esm", diff --git a/src/lang/tk.ts b/src/lang/tk.ts new file mode 100644 index 0000000..de66f74 --- /dev/null +++ b/src/lang/tk.ts @@ -0,0 +1,9 @@ +const TK = ['sekunt', 'minut', 'sagat', 'gün', 'hepde', 'aý', 'ýyl']; +function getSuffix(unit: string): string { + return unit.match(/[aouy]/) ? 'dan' : 'den'; +} +export default function(diff: number, idx: number): [string, string] { + if (idx === 0) return ['biraz öň', 'şuwagt']; + const unit = TK[Math.floor(idx / 2)]; + return [`${diff} ${unit} öň`, `${diff} ${unit}${getSuffix(unit)}`]; +}