timeago.js 3.0.1 → 3.0.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (83) hide show
  1. package/.npmignore +8 -8
  2. package/.travis.yml +2 -2
  3. package/LICENSE +20 -20
  4. package/README.md +189 -189
  5. package/README_zh.md +172 -172
  6. package/bower.json +21 -21
  7. package/demo/index.html +121 -0
  8. package/demo/index.js +25 -17
  9. package/dist/timeago.js +261 -258
  10. package/dist/timeago.locales.min.js +1 -1
  11. package/dist/timeago.min.js +1 -1
  12. package/gulpfile.js +13 -13
  13. package/index.html +185 -182
  14. package/locales/ar.js +26 -26
  15. package/locales/be.js +51 -51
  16. package/locales/bg.js +18 -18
  17. package/locales/ca.js +18 -18
  18. package/locales/da.js +18 -18
  19. package/locales/de.js +18 -18
  20. package/locales/el.js +18 -18
  21. package/locales/en.js +18 -18
  22. package/locales/en_short.js +17 -17
  23. package/locales/es.js +17 -17
  24. package/locales/eu.js +18 -18
  25. package/locales/fa.js +18 -0
  26. package/locales/fi.js +18 -18
  27. package/locales/fr.js +17 -17
  28. package/locales/he.js +18 -18
  29. package/locales/hu.js +18 -18
  30. package/locales/in_ID.js +18 -18
  31. package/locales/it.js +18 -18
  32. package/locales/ja.js +18 -18
  33. package/locales/ko.js +17 -17
  34. package/locales/locales.js +6 -6
  35. package/locales/ml.js +18 -18
  36. package/locales/my.js +18 -0
  37. package/locales/nl.js +18 -18
  38. package/locales/pl.js +34 -34
  39. package/locales/pt_BR.js +18 -18
  40. package/locales/ro.js +29 -29
  41. package/locales/ru.js +51 -51
  42. package/locales/sv.js +18 -18
  43. package/locales/ta.js +17 -17
  44. package/locales/th.js +18 -18
  45. package/locales/tr.js +18 -18
  46. package/locales/uk.js +40 -40
  47. package/locales/vi.js +18 -18
  48. package/locales/zh_CN.js +17 -17
  49. package/locales/zh_TW.js +17 -17
  50. package/package.json +49 -49
  51. package/src/timeago.js +261 -258
  52. package/src/timeago.locales.js +12 -12
  53. package/tests/locales/ar.js +66 -66
  54. package/tests/locales/be.js +63 -63
  55. package/tests/locales/bg.js +63 -63
  56. package/tests/locales/ca.js +64 -64
  57. package/tests/locales/en.js +62 -62
  58. package/tests/locales/en_short.js +62 -62
  59. package/tests/locales/eu.js +63 -63
  60. package/tests/locales/fa.js +63 -0
  61. package/tests/locales/fi.js +43 -43
  62. package/tests/locales/he.js +62 -62
  63. package/tests/locales/in_BG.js +63 -63
  64. package/tests/locales/in_HI.js +63 -63
  65. package/tests/locales/in_ID.js +62 -62
  66. package/tests/locales/ja.js +62 -62
  67. package/tests/locales/ko.js +62 -62
  68. package/tests/locales/my.js +63 -0
  69. package/tests/locales/pl.js +91 -91
  70. package/tests/locales/ro.js +61 -61
  71. package/tests/locales/ru.js +63 -63
  72. package/tests/locales/ta.js +62 -62
  73. package/tests/locales/tr.js +63 -63
  74. package/tests/locales/uk.js +63 -63
  75. package/tests/locales/vi.js +63 -63
  76. package/tests/locales/zh_CN.js +62 -62
  77. package/tests/locales_test.js +51 -51
  78. package/tests/test-builder.js +247 -247
  79. package/tests/test.js +83 -83
  80. package/tests/test_dev.js +44 -44
  81. package/tests/test_ts.ts +6 -6
  82. package/timeago.d.ts +14 -14
  83. package/webpack.config.js +10 -10
package/.npmignore CHANGED
@@ -1,8 +1,8 @@
1
- .project
2
- .settings
3
- .idea/*
4
- .DS_Store
5
-
6
- node_modules/*
7
- tests/test_ts.js
8
-
1
+ .project
2
+ .settings
3
+ .idea/*
4
+ .DS_Store
5
+
6
+ node_modules/*
7
+ tests/test_ts.js
8
+
package/.travis.yml CHANGED
@@ -1,3 +1,3 @@
1
- language: node_js
2
- node_js:
1
+ language: node_js
2
+ node_js:
3
3
  - "4.4.4"
package/LICENSE CHANGED
@@ -1,21 +1,21 @@
1
- The MIT License (MIT)
2
-
3
- Copyright (c) 2016 Hust.cc
4
-
5
- Permission is hereby granted, free of charge, to any person obtaining a copy
6
- of this software and associated documentation files (the "Software"), to deal
7
- in the Software without restriction, including without limitation the rights
8
- to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
- copies of the Software, and to permit persons to whom the Software is
10
- furnished to do so, subject to the following conditions:
11
-
12
- The above copyright notice and this permission notice shall be included in all
13
- copies or substantial portions of the Software.
14
-
15
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2016 Hust.cc
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
21
  SOFTWARE.
package/README.md CHANGED
@@ -1,189 +1,189 @@
1
- # timeago.js
2
-
3
- > **timeago.js** is a simple library (less than `2 kb`) that is used to format datetime with `*** time ago` statement. eg: '3 hours ago'.
4
-
5
- - Localization supported.
6
- - Time `ago` and time `in` supported.
7
- - Real-time render supported.
8
- - Nodejs and browserjs supported.
9
- - Well tested.
10
-
11
- [Official website](http://timeago.org/). 中文版说明文档[点这里](README_zh.md)。 React version here: [timeago-react](https://github.com/hustcc/timeago-react). Python version here: [timeago](https://github.com/hustcc/timeago).
12
-
13
- [![Build Status](https://travis-ci.org/hustcc/timeago.js.svg?branch=master)](https://travis-ci.org/hustcc/timeago.js) [![npm](https://img.shields.io/npm/v/timeago.js.svg?style=flat-square)](https://www.npmjs.com/package/timeago.js) [![npm](https://img.shields.io/npm/dt/timeago.js.svg?style=flat-square)](https://www.npmjs.com/package/timeago.js) [![npm](https://img.shields.io/npm/l/timeago.js.svg?style=flat-square)](https://www.npmjs.com/package/timeago.js)
14
-
15
- Such as
16
-
17
- ```
18
- just now
19
- 12 seconds ago
20
- 3 minutes ago
21
- 2 hours ago
22
- 3 days ago
23
- 3 weeks ago
24
- 6 months ago
25
- 2 years ago
26
-
27
- in 12 seconds
28
- in 3 minutes
29
- in 2 hours
30
- in 24 days
31
- in 6 months
32
- in 2 years
33
- ```
34
-
35
-
36
- # 1. Usage
37
-
38
- **1. Install timeago.js**
39
-
40
- ```sh
41
- npm install timeago.js
42
- ```
43
-
44
- **2. Import timeago.js**
45
-
46
- ES6/commonjs import style is supported.
47
-
48
- ```js
49
- // ES6
50
- import timeago from 'timeago.js';
51
-
52
- // commonjs
53
- var timeago = require("timeago.js");
54
- ```
55
-
56
- or link as a `script` in an html file and access global variable `timeago`.
57
-
58
- ```js
59
- <script src="dist/timeago.min.js"></script>
60
- ```
61
-
62
- or import in a typescript file.
63
-
64
- ```ts
65
- import timeago from 'timeago.js';
66
-
67
- // or
68
-
69
- import timeago = require("timeago.js");
70
- ```
71
-
72
- **3. Use `timeago` factory to create a new instance**
73
-
74
- ```js
75
- var timeagoInstance = timeago();
76
- timeagoInstance.format('2016-06-12');
77
- ```
78
-
79
-
80
- # 2. Detailed Usage
81
-
82
- **1. Set relative date**
83
-
84
- `timeago` is relative to the current date by default. You can set it yourself.
85
-
86
- ```js
87
- var timeagoInstance = timeago('2016-06-10 12:12:12'); // set the relative date here.
88
- timeagoInstance.format('2016-06-12', 'zh_CN');
89
- ```
90
-
91
- **2. Use timestamp**
92
-
93
- ```js
94
- timeago().format(Date.now() - 11 * 1000 * 60 * 60); // returns '11 hours ago'
95
- ```
96
-
97
- **3. Automatic rendering**
98
-
99
- HTML code:
100
- ```html
101
- <div class="needs_to_be_rendered" datetime="2016-06-30 09:20:00"></div>
102
- ```
103
- js code
104
- ```js
105
- var timeagoInstance = timeago();
106
- var nodes = document.querySelectorAll('.needs_to_be_rendered');
107
- // use render method to render nodes in real time
108
- timeagoInstance.render(nodes, 'zh_CN');
109
- // cancel real-time render for every node
110
- timeago.cancel()
111
- // or for the specific one
112
- timeago.cancel(nodes[0])
113
- ```
114
-
115
- The input for `render` method should be DOM object/array, pure javascript DOM node or jQuery DOM object.
116
-
117
- The `cancel` method clears all the render timers and release all resources of the instance. Optionally it accepts a single node to cancel timer just for it.
118
-
119
- The DOM object should have the attribute `datetime` or `data-timeago` with date formatted string.
120
-
121
- **4. Localization**
122
-
123
- Default locale is **`en`**, and the library supports `en` and `zh_CN`.
124
-
125
- ```js
126
- var timeagoInstance = timeago();
127
- timeagoInstance.format('2016-06-12', 'zh_CN');
128
- ```
129
-
130
- You can change the locale in the constructor or use the `setLocale` method:
131
-
132
- ```js
133
- var timeagoInstance = timeago(currentDate, 'zh_CN');
134
- // or
135
- timeago(currentDate).setLocale('zh_CN');
136
- ```
137
-
138
- **5. Register local language**
139
-
140
- You can register your own language via a static method `register`. Usage example:
141
-
142
- ```js
143
- // the local dict example is below.
144
- var test_local_dict = function(number, index, total_sec) {
145
- // number: the timeago / timein number;
146
- // index: the index of array below;
147
- // total_sec: total seconds between date to be formatted and today's date;
148
- return [
149
- ['just now', 'right now'],
150
- ['%s seconds ago', 'in %s seconds'],
151
- ['1 minute ago', 'in 1 minute'],
152
- ['%s minutes ago', 'in %s minutes'],
153
- ['1 hour ago', 'in 1 hour'],
154
- ['%s hours ago', 'in %s hours'],
155
- ['1 day ago', 'in 1 day'],
156
- ['%s days ago', 'in %s days'],
157
- ['1 week ago', 'in 1 week'],
158
- ['%s weeks ago', 'in %s weeks'],
159
- ['1 month ago', 'in 1 month'],
160
- ['%s months ago', 'in %s months'],
161
- ['1 year ago', 'in 1 year'],
162
- ['%s years ago', 'in %s years']
163
- ][index];
164
- };
165
- // register your locale with timeago
166
- timeago.register('test_local', test_local_dict);
167
- // use the locale with timeago instance
168
- var timeagoInstance = timeago();
169
- timeagoInstance.format('2016-06-12', 'test_local');
170
- ```
171
-
172
- Check out more [locales](locales).
173
-
174
- [Locale contributions](#3-contributions) are welcomed, thank you for submitting a GitHub pull request for corrections or additional languages. ^_^~
175
-
176
-
177
- # 3. Contributions
178
-
179
- 1. The website is based on [rmm5t/jquery-timeago](https://github.com/rmm5t/jquery-timeago) which is a nice and featured project but it depends on jQuery.
180
-
181
- 2. **locale translations**: The library needs more locale translations. You can:
182
-
183
- - Open an issue to write the locale translations, or submit a pull request. How to ? see [en's translation](locales/en.js).
184
- - Please **test** the locale by exec `npm test` or `node tests/locales_test.js`. How to write testcase, see [en's test cases](tests/locales/en.js).
185
-
186
-
187
- # 4. LICENSE
188
-
189
- MIT@[https://github.com/hustcc](hustcc)
1
+ # timeago.js
2
+
3
+ > **timeago.js** is a simple library (less than `2 kb`) that is used to format datetime with `*** time ago` statement. eg: '3 hours ago'.
4
+
5
+ - Localization supported.
6
+ - Time `ago` and time `in` supported.
7
+ - Real-time render supported.
8
+ - Nodejs and browserjs supported.
9
+ - Well tested.
10
+
11
+ [Official website](http://timeago.org/). 中文版说明文档[点这里](README_zh.md)。 React version here: [timeago-react](https://github.com/hustcc/timeago-react). Python version here: [timeago](https://github.com/hustcc/timeago).
12
+
13
+ [![Build Status](https://img.shields.io/travis/hustcc/timeago.js.svg?style=flat-square)](https://travis-ci.org/hustcc/timeago.js) [![CDNJS](https://img.shields.io/cdnjs/v/timeago.js.svg?style=flat-square)](https://cdnjs.com/libraries/timeago.js) [![npm](https://img.shields.io/npm/v/timeago.js.svg?style=flat-square)](https://www.npmjs.com/package/timeago.js) [![npm](https://img.shields.io/npm/dt/timeago.js.svg?style=flat-square)](https://www.npmjs.com/package/timeago.js) [![npm](https://img.shields.io/npm/l/timeago.js.svg?style=flat-square)](https://www.npmjs.com/package/timeago.js)
14
+
15
+ Such as
16
+
17
+ ```
18
+ just now
19
+ 12 seconds ago
20
+ 3 minutes ago
21
+ 2 hours ago
22
+ 3 days ago
23
+ 3 weeks ago
24
+ 6 months ago
25
+ 2 years ago
26
+
27
+ in 12 seconds
28
+ in 3 minutes
29
+ in 2 hours
30
+ in 24 days
31
+ in 6 months
32
+ in 2 years
33
+ ```
34
+
35
+
36
+ # 1. Usage
37
+
38
+ **1. Install timeago.js**
39
+
40
+ ```sh
41
+ npm install timeago.js
42
+ ```
43
+
44
+ **2. Import timeago.js**
45
+
46
+ ES6/commonjs import style is supported.
47
+
48
+ ```js
49
+ // ES6
50
+ import timeago from 'timeago.js';
51
+
52
+ // commonjs
53
+ var timeago = require("timeago.js");
54
+ ```
55
+
56
+ or link as a `script` in an html file and access global variable `timeago`.
57
+
58
+ ```js
59
+ <script src="dist/timeago.min.js"></script>
60
+ ```
61
+
62
+ or import in a typescript file.
63
+
64
+ ```ts
65
+ import timeago from 'timeago.js';
66
+
67
+ // or
68
+
69
+ import timeago = require("timeago.js");
70
+ ```
71
+
72
+ **3. Use `timeago` factory to create a new instance**
73
+
74
+ ```js
75
+ var timeagoInstance = timeago();
76
+ timeagoInstance.format('2016-06-12');
77
+ ```
78
+
79
+
80
+ # 2. Detailed Usage
81
+
82
+ **1. Set relative date**
83
+
84
+ `timeago` is relative to the current date by default. You can set it yourself.
85
+
86
+ ```js
87
+ var timeagoInstance = timeago('2016-06-10 12:12:12'); // set the relative date here.
88
+ timeagoInstance.format('2016-06-12', 'zh_CN');
89
+ ```
90
+
91
+ **2. Use timestamp**
92
+
93
+ ```js
94
+ timeago().format(Date.now() - 11 * 1000 * 60 * 60); // returns '11 hours ago'
95
+ ```
96
+
97
+ **3. Automatic rendering**
98
+
99
+ HTML code:
100
+ ```html
101
+ <div class="needs_to_be_rendered" datetime="2016-06-30 09:20:00"></div>
102
+ ```
103
+ js code
104
+ ```js
105
+ var timeagoInstance = timeago();
106
+ var nodes = document.querySelectorAll('.needs_to_be_rendered');
107
+ // use render method to render nodes in real time
108
+ timeagoInstance.render(nodes, 'zh_CN');
109
+ // cancel real-time render for every node
110
+ timeago.cancel()
111
+ // or for the specific one
112
+ timeago.cancel(nodes[0])
113
+ ```
114
+
115
+ The input for `render` method should be DOM object/array, pure javascript DOM node or jQuery DOM object.
116
+
117
+ The `cancel` method clears all the render timers and release all resources of the instance. Optionally it accepts a single node to cancel timer just for it.
118
+
119
+ The DOM object should have the attribute `datetime` or `data-timeago` with date formatted string.
120
+
121
+ **4. Localization**
122
+
123
+ Default locale is **`en`**, and the library supports `en` and `zh_CN`.
124
+
125
+ ```js
126
+ var timeagoInstance = timeago();
127
+ timeagoInstance.format('2016-06-12', 'zh_CN');
128
+ ```
129
+
130
+ You can change the locale in the constructor or use the `setLocale` method:
131
+
132
+ ```js
133
+ var timeagoInstance = timeago(currentDate, 'zh_CN');
134
+ // or
135
+ timeago(currentDate).setLocale('zh_CN');
136
+ ```
137
+
138
+ **5. Register local language**
139
+
140
+ You can register your own language via a static method `register`. Usage example:
141
+
142
+ ```js
143
+ // the local dict example is below.
144
+ var test_local_dict = function(number, index, total_sec) {
145
+ // number: the timeago / timein number;
146
+ // index: the index of array below;
147
+ // total_sec: total seconds between date to be formatted and today's date;
148
+ return [
149
+ ['just now', 'right now'],
150
+ ['%s seconds ago', 'in %s seconds'],
151
+ ['1 minute ago', 'in 1 minute'],
152
+ ['%s minutes ago', 'in %s minutes'],
153
+ ['1 hour ago', 'in 1 hour'],
154
+ ['%s hours ago', 'in %s hours'],
155
+ ['1 day ago', 'in 1 day'],
156
+ ['%s days ago', 'in %s days'],
157
+ ['1 week ago', 'in 1 week'],
158
+ ['%s weeks ago', 'in %s weeks'],
159
+ ['1 month ago', 'in 1 month'],
160
+ ['%s months ago', 'in %s months'],
161
+ ['1 year ago', 'in 1 year'],
162
+ ['%s years ago', 'in %s years']
163
+ ][index];
164
+ };
165
+ // register your locale with timeago
166
+ timeago.register('test_local', test_local_dict);
167
+ // use the locale with timeago instance
168
+ var timeagoInstance = timeago();
169
+ timeagoInstance.format('2016-06-12', 'test_local');
170
+ ```
171
+
172
+ Check out more [locales](locales).
173
+
174
+ [Locale contributions](#3-contributions) are welcomed, thank you for submitting a GitHub pull request for corrections or additional languages. ^_^~
175
+
176
+
177
+ # 3. Contributions
178
+
179
+ 1. The website is based on [rmm5t/jquery-timeago](https://github.com/rmm5t/jquery-timeago) which is a nice and featured project but it depends on jQuery.
180
+
181
+ 2. **locale translations**: The library needs more locale translations. You can:
182
+
183
+ - Open an issue to write the locale translations, or submit a pull request. How to ? see [en's translation](locales/en.js).
184
+ - Please **test** the locale by exec `npm test` or `node tests/locales_test.js`. How to write testcase, see [en's test cases](tests/locales/en.js).
185
+
186
+
187
+ # 4. LICENSE
188
+
189
+ MIT@[https://github.com/hustcc](hustcc)