chrono-node 1.3.5 → 1.4.4

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 (195) hide show
  1. package/.travis.yml +2 -0
  2. package/README.md +100 -86
  3. package/dist/chrono.js +7865 -0
  4. package/dist/chrono.js.map +1 -0
  5. package/dist/chrono.min.js +3 -0
  6. package/dist/chrono.min.js.LICENSE.txt +19 -0
  7. package/dist/chrono.min.js.map +1 -0
  8. package/package.json +20 -22
  9. package/src/chrono.js +5 -3
  10. package/src/options.js +33 -3
  11. package/src/parsers/{DE → de}/DECasualDateParser.js +18 -21
  12. package/src/parsers/{DE → de}/DEDeadlineFormatParser.js +9 -9
  13. package/src/parsers/{DE → de}/DEMonthNameLittleEndianParser.js +15 -36
  14. package/src/parsers/{DE → de}/DEMonthNameParser.js +12 -27
  15. package/src/parsers/{DE → de}/DESlashDateFormatParser.js +2 -3
  16. package/src/parsers/{DE → de}/DETimeAgoFormatParser.js +9 -14
  17. package/src/parsers/{DE → de}/DETimeExpressionParser.js +2 -2
  18. package/src/parsers/{DE → de}/DEWeekdayParser.js +14 -14
  19. package/src/parsers/{EN → en}/ENCasualDateParser.js +6 -11
  20. package/src/parsers/en/ENCasualTimeParser.js +54 -0
  21. package/src/parsers/{EN → en}/ENDeadlineFormatParser.js +15 -20
  22. package/src/parsers/{EN → en}/ENISOFormatParser.js +3 -3
  23. package/src/parsers/{EN → en}/ENMonthNameLittleEndianParser.js +25 -49
  24. package/src/parsers/{EN → en}/ENMonthNameMiddleEndianParser.js +6 -23
  25. package/src/parsers/{EN → en}/ENMonthNameParser.js +5 -22
  26. package/src/parsers/{EN → en}/ENRelativeDateFormatParser.js +48 -15
  27. package/src/parsers/{EN → en}/ENSlashDateFormatParser.js +7 -3
  28. package/src/parsers/{EN → en}/ENSlashDateFormatStartWithYearParser.js +12 -5
  29. package/src/parsers/{EN → en}/ENSlashMonthFormatParser.js +2 -5
  30. package/src/parsers/en/ENTimeAgoFormatParser.js +69 -0
  31. package/src/parsers/{EN → en}/ENTimeExpressionParser.js +26 -17
  32. package/src/parsers/en/ENTimeLaterFormatParser.js +75 -0
  33. package/src/parsers/{EN → en}/ENWeekdayParser.js +8 -12
  34. package/src/parsers/{ES → es}/ESCasualDateParser.js +8 -13
  35. package/src/parsers/{ES → es}/ESDeadlineFormatParser.js +5 -11
  36. package/src/parsers/{ES → es}/ESMonthNameLittleEndianParser.js +6 -28
  37. package/src/parsers/{ES → es}/ESSlashDateFormatParser.js +2 -2
  38. package/src/parsers/{ES → es}/ESTimeAgoFormatParser.js +8 -13
  39. package/src/parsers/{ES → es}/ESTimeExpressionParser.js +2 -7
  40. package/src/parsers/{ES → es}/ESWeekdayParser.js +1 -6
  41. package/src/parsers/{FR → fr}/FRCasualDateParser.js +6 -11
  42. package/src/parsers/{FR → fr}/FRDeadlineFormatParser.js +9 -14
  43. package/src/parsers/{FR → fr}/FRMonthNameLittleEndianParser.js +4 -26
  44. package/src/parsers/{FR → fr}/FRRelativeDateFormatParser.js +29 -34
  45. package/src/parsers/{FR → fr}/FRSlashDateFormatParser.js +22 -15
  46. package/src/parsers/{FR → fr}/FRTimeAgoFormatParser.js +8 -14
  47. package/src/parsers/{FR → fr}/FRTimeExpressionParser.js +2 -7
  48. package/src/parsers/{FR → fr}/FRWeekdayParser.js +1 -6
  49. package/src/parsers/{JP → ja}/JPCasualDateParser.js +5 -10
  50. package/src/parsers/ja/JPStandardParser.js +71 -0
  51. package/src/parsers/parser.js +80 -53
  52. package/src/parsers/pt/PTCasualDateParser.js +123 -0
  53. package/src/parsers/pt/PTDeadlineFormatParser.js +61 -0
  54. package/src/parsers/pt/PTMonthNameLittleEndianParser.js +86 -0
  55. package/src/parsers/pt/PTSlashDateFormatParser.js +114 -0
  56. package/src/parsers/pt/PTTimeAgoFormatParser.js +87 -0
  57. package/src/parsers/pt/PTTimeExpressionParser.js +234 -0
  58. package/src/parsers/pt/PTWeekdayParser.js +60 -0
  59. package/src/parsers/{ZH-Hant → zh-Hant}/ZHHantCasualDateParser.js +30 -19
  60. package/src/parsers/{ZH-Hant → zh-Hant}/ZHHantDateParser.js +2 -7
  61. package/src/parsers/{ZH-Hant → zh-Hant}/ZHHantDeadlineFormatParser.js +14 -19
  62. package/src/parsers/{ZH-Hant → zh-Hant}/ZHHantTimeExpressionParser.js +38 -11
  63. package/src/parsers/{ZH-Hant → zh-Hant}/ZHHantWeekdayParser.js +1 -7
  64. package/src/refiners/ExtractTimezoneAbbrRefiner.js +19 -10
  65. package/src/refiners/ForwardDateRefiner.js +10 -15
  66. package/src/refiners/{DE → de}/DEMergeDateRangeRefiner.js +1 -1
  67. package/src/refiners/{DE → de}/DEMergeDateTimeRefiner.js +3 -3
  68. package/src/refiners/{EN → en}/ENMergeDateRangeRefiner.js +5 -9
  69. package/src/refiners/{EN → en}/ENMergeDateTimeRefiner.js +15 -2
  70. package/src/refiners/{EN → en}/ENMergeWeekdayRefiner.js +0 -0
  71. package/src/refiners/{EN → en}/ENPrioritizeSpecificDateRefiner.js +0 -0
  72. package/src/refiners/{FR → fr}/FRMergeDateRangeRefiner.js +0 -0
  73. package/src/refiners/{FR → fr}/FRMergeDateTimeRefiner.js +1 -1
  74. package/src/refiners/{JP → ja}/JPMergeDateRangeRefiner.js +1 -1
  75. package/src/refiners/refiner.js +12 -12
  76. package/src/result.js +47 -19
  77. package/src/timezone.js +2 -0
  78. package/src/utils/EN.js +68 -2
  79. package/src/utils/PT.js +62 -0
  80. package/test/de/de.test.js +51 -0
  81. package/test/de/de_casual.test.js +432 -0
  82. package/test/de/de_dash.test.js +6 -0
  83. package/test/de/de_deadline.test.js +244 -0
  84. package/test/de/de_little_endian.test.js +459 -0
  85. package/test/de/de_time_ago.test.js +313 -0
  86. package/test/de/de_time_exp.test.js +166 -0
  87. package/test/de/de_weekday.test.js +235 -0
  88. package/test/en/en.test.js +250 -0
  89. package/test/en/en_casual.test.js +461 -0
  90. package/test/en/en_dash.test.js +31 -0
  91. package/test/en/en_deadline.test.js +366 -0
  92. package/test/{test_example.js → en/en_example.test.js} +7 -18
  93. package/test/en/en_inter_std.test.js +269 -0
  94. package/test/en/en_little_endian.test.js +566 -0
  95. package/test/en/en_middle_endian.test.js +552 -0
  96. package/test/en/en_month.test.js +156 -0
  97. package/test/en/en_option_forward.test.js +156 -0
  98. package/test/en/en_relative.test.js +228 -0
  99. package/test/en/en_slash.test.js +450 -0
  100. package/test/en/en_time_ago.test.js +374 -0
  101. package/test/en/en_time_exp.test.js +722 -0
  102. package/test/en/en_time_from_now.test.js +371 -0
  103. package/test/en/en_time_later.test.js +95 -0
  104. package/test/en/en_weekday.test.js +301 -0
  105. package/test/es/es_casual.test.js +258 -0
  106. package/test/es/es_dash.test.js +13 -0
  107. package/test/es/es_deadline.test.js +85 -0
  108. package/test/es/es_little_endian.test.js +350 -0
  109. package/test/es/es_slash.test.js +24 -0
  110. package/test/es/es_time_ago.test.js +137 -0
  111. package/test/es/es_time_exp.test.js +240 -0
  112. package/test/fr/fr_casual.test.js +454 -0
  113. package/test/fr/fr_dash.test.js +26 -0
  114. package/test/fr/fr_deadline.test.js +244 -0
  115. package/test/fr/fr_little_endian.test.js +576 -0
  116. package/test/fr/fr_relative.test.js +198 -0
  117. package/test/fr/fr_slash.test.js +81 -0
  118. package/test/fr/fr_time_ago.test.js +194 -0
  119. package/test/fr/fr_time_exp.test.js +960 -0
  120. package/test/fr/fr_weekday.test.js +200 -0
  121. package/test/ja/ja_casual.test.js +51 -0
  122. package/test/ja/ja_standard.test.js +344 -0
  123. package/test/pt/pt_casual.test.js +258 -0
  124. package/test/pt/pt_dash.test.js +13 -0
  125. package/test/pt/pt_deadline.test.js +85 -0
  126. package/test/pt/pt_little_endian.test.js +350 -0
  127. package/test/pt/pt_slash.test.js +44 -0
  128. package/test/pt/pt_time_ago.test.js +137 -0
  129. package/test/pt/pt_time_exp.test.js +240 -0
  130. package/test/system.test.js +207 -0
  131. package/test/zh/zh_hant_casual.test.js +340 -0
  132. package/test/zh/zh_hant_date.test.js +118 -0
  133. package/test/zh/zh_hant_deadline.test.js +213 -0
  134. package/test/zh/zh_hant_time_exp.test.js +226 -0
  135. package/test/zh/zh_hant_weekday.test.js +160 -0
  136. package/webpack.config.js +39 -0
  137. package/.npmignore +0 -11
  138. package/bower.json +0 -24
  139. package/chrono.js +0 -11892
  140. package/chrono.map.json +0 -1
  141. package/chrono.min.js +0 -148
  142. package/chrono.min.json +0 -1
  143. package/karma.conf.js +0 -68
  144. package/src/parsers/EN/ENCasualTimeParser.js +0 -53
  145. package/src/parsers/EN/ENTimeAgoFormatParser.js +0 -130
  146. package/src/parsers/EN/ENTimeFromNowFormatParser.js +0 -119
  147. package/src/parsers/JP/JPStandardParser.js +0 -88
  148. package/test/test_de.js +0 -62
  149. package/test/test_de_casual.js +0 -443
  150. package/test/test_de_dash.js +0 -17
  151. package/test/test_de_deadline.js +0 -255
  152. package/test/test_de_little_endian.js +0 -470
  153. package/test/test_de_time_ago.js +0 -324
  154. package/test/test_de_time_exp.js +0 -177
  155. package/test/test_de_weekday.js +0 -246
  156. package/test/test_en.js +0 -249
  157. package/test/test_en_casual.js +0 -448
  158. package/test/test_en_dash.js +0 -42
  159. package/test/test_en_deadline.js +0 -311
  160. package/test/test_en_inter_std.js +0 -272
  161. package/test/test_en_little_endian.js +0 -529
  162. package/test/test_en_middle_endian.js +0 -563
  163. package/test/test_en_month.js +0 -124
  164. package/test/test_en_option_forward.js +0 -167
  165. package/test/test_en_relative.js +0 -206
  166. package/test/test_en_slash.js +0 -370
  167. package/test/test_en_time_ago.js +0 -385
  168. package/test/test_en_time_exp.js +0 -663
  169. package/test/test_en_time_from_now.js +0 -345
  170. package/test/test_en_weekday.js +0 -312
  171. package/test/test_es_casual.js +0 -269
  172. package/test/test_es_dash.js +0 -24
  173. package/test/test_es_deadline.js +0 -96
  174. package/test/test_es_little_endian.js +0 -361
  175. package/test/test_es_slash.js +0 -35
  176. package/test/test_es_time_ago.js +0 -148
  177. package/test/test_es_time_exp.js +0 -251
  178. package/test/test_fr_casual.js +0 -465
  179. package/test/test_fr_dash.js +0 -37
  180. package/test/test_fr_deadline.js +0 -255
  181. package/test/test_fr_little_endian.js +0 -568
  182. package/test/test_fr_relative.js +0 -209
  183. package/test/test_fr_slash.js +0 -54
  184. package/test/test_fr_time_ago.js +0 -205
  185. package/test/test_fr_time_exp.js +0 -971
  186. package/test/test_fr_weekday.js +0 -211
  187. package/test/test_jp_casual.js +0 -62
  188. package/test/test_jp_standard.js +0 -181
  189. package/test/test_system.js +0 -178
  190. package/test/test_zh_hant_casual.js +0 -329
  191. package/test/test_zh_hant_date.js +0 -129
  192. package/test/test_zh_hant_deadline.js +0 -224
  193. package/test/test_zh_hant_time_exp.js +0 -210
  194. package/test/test_zh_hant_weekday.js +0 -171
  195. package/timezone.js +0 -9
package/.travis.yml CHANGED
@@ -2,5 +2,7 @@ language: node_js
2
2
  node_js:
3
3
  - "6"
4
4
  - "7"
5
+ - "8"
6
+ - "11"
5
7
  after_success:
6
8
  - npm run coveralls
package/README.md CHANGED
@@ -1,5 +1,5 @@
1
- Chrono
2
- ======
1
+ # Chrono
2
+
3
3
  A natural language date parser in Javascript, designed for extracting date information from any given text. (Java version is also available [here](https://github.com/wanasit/chrono-java))
4
4
 
5
5
  [![Build Status](https://travis-ci.org/wanasit/chrono.svg?branch=master)](https://travis-ci.org/wanasit/chrono)
@@ -15,34 +15,18 @@ Chrono supports most date and time formats, such as :
15
15
  * Sat Aug 17 2013 18:40:39 GMT+0900 (JST)
16
16
  * 2014-11-30T08:15:30-05:30
17
17
 
18
- ## Install
19
-
20
- #### npm (recommended)
18
+ ## Installation
21
19
 
22
20
  Just run:
23
-
24
- $ npm i --save chrono-node
21
+ ```bash
22
+ $ npm i --save chrono-node
23
+ ```
25
24
 
26
25
  And start using chrono:
27
-
28
- var chrono = require('chrono-node')
29
- chrono.parseDate('An appointment on Sep 12-13')
30
-
31
- #### Bower
32
-
33
- Prefer bower? You can do that, too:
34
-
35
- Just run:
36
-
37
- $ bower install chrono
38
-
39
- And use:
40
-
41
- ```html
42
- <script src="bower_components/chrono/chrono.min.js"></script>
43
- <script>chrono.parseDate('An appointment on Sep 12-13')</script>
26
+ ```js
27
+ var chrono = require('chrono-node');
28
+ chrono.parseDate('An appointment on Sep 12-13');
44
29
  ```
45
-
46
30
 
47
31
  #### Other Options:
48
32
 
@@ -50,7 +34,7 @@ Doing something else? No worries. Try these:
50
34
 
51
35
  Platform | Installation
52
36
  ---------|----
53
- CDN | Via [jsDelivr]:<br> `<script src="https://cdn.jsdelivr.net/chrono/VERSION/chrono.min.js"></script>`
37
+ CDN | Via [jsDelivr]:<br> `<script src="https://cdn.jsdelivr.net/npm/chrono-node@VERSION/chrono.min.js"></script>`
54
38
  Rails | Install from [Rails Assets] by adding this to your Gemfile:<br> `gem 'rails-assets-chrono', source: 'https://rails-assets.org'`
55
39
  Swift | Try using the community-made [chrono-swift] wrapper.
56
40
 
@@ -58,26 +42,18 @@ Swift | Try using the community-made [chrono-swift] wrapper.
58
42
  [jsDelivr]: https://www.jsdelivr.com/projects/chrono
59
43
  [chrono-swift]: https://github.com/neilsardesai/chrono-swift
60
44
 
61
- #### Browserify
62
-
63
- Chrono's modules are linked and packaged using [Browserify](http://browserify.org) on `src/chrono.js`. By default, `chrono.js` file exports `chrono` object as a window global.
64
-
65
- ```
66
- browserify src/chrono.js --s chrono -o chrono.js
67
- ```
68
-
69
45
  ## Usage
70
46
 
71
47
  Simply pass a string to function `chrono.parseDate` or `chrono.parse`.
72
48
 
73
- ```javascript
74
- > var chrono = require('chrono-node')
49
+ ```js
50
+ var chrono = require('chrono-node');
75
51
 
76
- > chrono.parseDate('An appointment on Sep 12-13')
77
- Fri Sep 12 2014 12:00:00 GMT-0500 (CDT)
52
+ chrono.parseDate('An appointment on Sep 12-13');
53
+ // Fri Sep 12 2014 12:00:00 GMT-0500 (CDT)
78
54
 
79
- > chrono.parse('An appointment on Sep 12-13');
80
- [ { index: 18,
55
+ chrono.parse('An appointment on Sep 12-13');
56
+ /* [ { index: 18,
81
57
  text: 'Sep 12-13',
82
58
  tags: { ENMonthNameMiddleEndianParser: true },
83
59
  start:
@@ -85,7 +61,7 @@ Fri Sep 12 2014 12:00:00 GMT-0500 (CDT)
85
61
  impliedValues: [Object] },
86
62
  end:
87
63
  { knownValues: [Object],
88
- impliedValues: [Object] } } ]
64
+ impliedValues: [Object] } } ] */
89
65
  ```
90
66
 
91
67
  ### Reference Date
@@ -94,28 +70,52 @@ Today's "Friday" is different from last month's "Friday".
94
70
  The meaning of the referenced dates depends on when they are mentioned.
95
71
  Chrono lets you define a reference date using `chrono.parse(text, ref)` and `chrono.parseDate(text, ref)`.
96
72
 
97
- ```javascript
73
+ ```js
74
+ chrono.parseDate('Friday', new Date(2012, 7, 23));
75
+ // Fri Aug 24 2012 12:00:00 GMT+0700 (ICT)
76
+
77
+ chrono.parseDate('Friday', new Date(2012, 7, 1));
78
+ // Fri Aug 03 2012 12:00:00 GMT+0700 (ICT)
79
+ ```
80
+
81
+ ### Parsing Options
82
+
83
+ * `forwardDate` (boolean) to assume the results should happen after the reference date (forward into the future)
84
+
85
+ ```js
86
+ var referenceDate = new Date(2012, 7, 25);
87
+ // Sat Aug 25 2012 00:00:00 GMT+0900 -- The reference date was Saturday
98
88
 
99
- > chrono.parseDate('Friday', new Date(2012,7,23));
100
- Fri Aug 24 2012 12:00:00 GMT+0700 (ICT)
89
+ chrono.parseDate('Friday', referenceDate);
90
+ // Fri Aug 24 2012 12:00:00 GMT+0900 (JST) -- The day before was Friday
101
91
 
102
- > chrono.parseDate('Friday', new Date(2012,7,1));
103
- Fri Aug 03 2012 12:00:00 GMT+0700 (ICT)
92
+ chrono.parseDate('Friday', referenceDate, { forwardDate: true });
93
+ // Fri Aug 31 2012 12:00:00 GMT+0900 (JST) -- The following Friday
94
+ ```
95
+
96
+ * `timezones` (Map) to override Chrono's default timezone abbriviation mapping. The value should be the timezone offset in minutes (between -720 to 720).
97
+
98
+ ```js
99
+ chrono.parse('Friday at 2 pm IST', refDate, { timezones: { 'IST': 330 } })[0].start.get('timezoneOffset');
100
+ // 330 (IST – India Standard Time +0530)
101
+
102
+ chrono.parse('Friday at 2 pm IST', refDate, { timezones: {'IST': 60 } })[0].start.get('timezoneOffset');
103
+ // 60 (IST - Irish Standard Time +0100)
104
104
  ```
105
105
 
106
106
  ### Detailed Parsed Results
107
107
 
108
108
  The function `chrono.parse` returns detailed parsing results as objects of class `chrono.ParsedResult`.
109
109
 
110
- ```javascript
111
- var results = chrono.parse('I have an appointment tomorrow from 10 to 11 AM')
110
+ ```js
111
+ var results = chrono.parse('I have an appointment tomorrow from 10 to 11 AM');
112
112
 
113
- results[0].index // 15
114
- results[0].text // 'tomorrow from 10 to 11 AM'
115
- results[0].ref // Sat Dec 13 2014 21:50:14 GMT-0600 (CST)
113
+ results[0].index; // 15
114
+ results[0].text; // 'tomorrow from 10 to 11 AM'
115
+ results[0].ref; // Sat Dec 13 2014 21:50:14 GMT-0600 (CST)
116
116
 
117
- results[0].start.date() // Sun Dec 14 2014 10:00:00 GMT-0600 (CST)
118
- results[0].end.date() // Sun Dec 14 2014 11:00:00 GMT-0600 (CST)
117
+ results[0].start.date(); // Sun Dec 14 2014 10:00:00 GMT-0600 (CST)
118
+ results[0].end.date(); // Sun Dec 14 2014 11:00:00 GMT-0600 (CST)
119
119
  ```
120
120
 
121
121
  #### ParsedResult
@@ -136,20 +136,20 @@ A group of found date and time components (year, month, hour, etc). ParsedCompon
136
136
  * `isCertain(component)` return true if the value of the component is known.
137
137
  * `date()` Create a javascript Date
138
138
 
139
- ```javascript
139
+ ```js
140
140
  // Remove the timezone offset of a parsed date and then create the Date object
141
- > var results = new chrono.parse('2016-03-08T01:16:07+02:00'); // Create new ParsedResult Object
142
- > results[0].start.assign('timezoneOffset', 0); // Change value in ParsedComponents Object 'start'
143
- > var d = results[0].start.date(); // Create a Date object
144
- > d.toString(); // Display resulting Date object
145
- 'Tue Mar 08 2016 01:16:07 GMT+0000 (GMT)'
141
+ var results = new chrono.parse('2016-03-08T01:16:07+02:00'); // Create new ParsedResult Object
142
+ results[0].start.assign('timezoneOffset', 0); // Change value in ParsedComponents Object 'start'
143
+
144
+ var d = results[0].start.date(); // Create a Date object
145
+ d.toString(); // 'Tue Mar 08 2016 01:16:07 GMT+0000 (GMT)'
146
146
  ```
147
147
 
148
148
  ### Strict vs Casual
149
149
 
150
150
  Chrono comes with `strict` mode that parse only formal date patterns.
151
151
 
152
- ```javascript
152
+ ```js
153
153
  // 'strict' mode
154
154
  chrono.strict.parseDate('Today'); // null
155
155
  chrono.strict.parseDate('Friday'); // null
@@ -159,10 +159,27 @@ chrono.strict.parseDate('Jul 01 2016'); // Fri Jul 01 2016 12:00:00 ...
159
159
  // 'casual' mode (default)
160
160
  chrono.parseDate('Today'); // Thu Jun 30 2016 12:00:00 ...
161
161
  chrono.casual.parseDate('Friday'); // Fri Jul 01 2016 12:00:00 ...
162
+ chrono.casual.parseDate('2016-07-01'); // Fri Jul 01 2016 12:00:00 ...
162
163
  chrono.casual.parseDate('Jul 01 2016'); // Fri Jul 01 2016 12:00:00 ...
163
- chrono.casual.parseDate('Friday'); // Fri Jul 01 2016 12:00:00 ...
164
164
  ```
165
165
 
166
+ ### Choosing Locale
167
+
168
+ By default, Chrono is configurated to parse different date formats from muliple languages out-off-box. However, by using predefined locale options, you can increase parsing accuracy.
169
+
170
+ Handling different date format for UK / US is a good example.
171
+
172
+ ```js
173
+ // default English (US)
174
+ chrono.parseDate('6/10/2018'); // Sun Jun 10 2018 12:00:00 ...
175
+ chrono.en.parseDate('6/10/2018'); // Sun Jun 10 2018 12:00:00 ...
176
+
177
+ // UK English or German
178
+ chrono.en_GB.parseDate('6/10/2018'); // Sat Oct 06 2018 12:00:00 ...
179
+ chrono.de.parseDate('6/10/2018'); // Sat Oct 06 2018 12:00:00 ...
180
+ ```
181
+
182
+ Current supported locale options are: `en`, `en_GB`, `de`, `pt`, `es`, `fr`, `ja`
166
183
 
167
184
  ## Customize Chrono
168
185
 
@@ -172,11 +189,11 @@ Chrono’s extraction pipeline are mainly separated into 'parse' and ‘refine
172
189
 
173
190
  Parser is a module for low-level pattern-based parsing. Ideally, each parser should be designed to handle a single specific date format. User can add new type of parsers for supporting new date formats or languages.
174
191
 
175
- ```javascript
192
+ ```js
176
193
  var christmasParser = new chrono.Parser();
177
194
 
178
195
  // Provide search pattern
179
- christmasParser.pattern = function () { return /Christmas/i }
196
+ christmasParser.pattern = function () { return /Christmas/i; };
180
197
 
181
198
  // This function will be called when matched pattern is found
182
199
  christmasParser.extract = function(text, ref, match, opt) {
@@ -191,7 +208,7 @@ christmasParser.extract = function(text, ref, match, opt) {
191
208
  month: 12,
192
209
  }
193
210
  });
194
- }
211
+ };
195
212
 
196
213
  // Create a new custom Chrono. The initial pipeline 'option' can also be specified as
197
214
  // - new chrono.Chrono(exports.options.strictOption())
@@ -199,7 +216,7 @@ christmasParser.extract = function(text, ref, match, opt) {
199
216
  var custom = new chrono.Chrono();
200
217
  custom.parsers.push(christmasParser);
201
218
 
202
- custom.parseDate("I'll arrive at 2.30AM on Christmas night")
219
+ custom.parseDate("I'll arrive at 2.30AM on Christmas night");
203
220
  // Wed Dec 25 2013 02:30:00 GMT+0900 (JST)
204
221
 
205
222
  ```
@@ -213,21 +230,21 @@ To create a custom parser, override `pattern` and `extract` methods on an object
213
230
 
214
231
  Refiner is a higher level module for improving or manipulating the results. User can add a new type of refiner to customize Chrono's results or to add some custom logic to Chrono.
215
232
 
216
- ```javascript
233
+ ```js
217
234
  var guessPMRefiner = new chrono.Refiner();
218
235
  guessPMRefiner.refine = function(text, results, opt) {
219
236
  // If there is no AM/PM (meridiem) specified,
220
237
  // let all time between 1:00 - 4:00 be PM (13.00 - 16.00)
221
238
  results.forEach(function (result) {
222
- if (!result.start.isCertain('meridiem')
223
- && result.start.get('hour') >= 1 && result.start.get('hour') < 4) {
239
+ if (!result.start.isCertain('meridiem') &&
240
+ result.start.get('hour') >= 1 && result.start.get('hour') < 4) {
224
241
 
225
242
  result.start.assign('meridiem', 1);
226
243
  result.start.assign('hour', result.start.get('hour') + 12);
227
244
  }
228
245
  });
229
246
  return results;
230
- }
247
+ };
231
248
 
232
249
  // Create a new custom Chrono. The initial pipeline 'option' can also be specified as
233
250
  // - new chrono.Chrono(exports.options.strictOption())
@@ -253,30 +270,27 @@ This guide explains how to setup chrono project for prospective contributors.
253
270
 
254
271
  ```bash
255
272
  # Clone and install library
256
- git clone https://github.com/wanasit/chrono.git chrono
257
- cd chrono
258
- npm install
259
-
260
- # Try running the test
261
- npm run test
262
- ```
273
+ $ git clone https://github.com/wanasit/chrono.git chrono
274
+ $ cd chrono
275
+ $ npm install
263
276
 
264
- Chrono's source files is in `src` directory. The built bundle (`chrono.js` and `chrono.min.js`) can be built by [Browserify](http://browserify.org) on `src/chrono.js` using the following command
265
-
266
- ```
267
- npm run make
268
277
  ```
269
278
 
270
279
  Parsing date from text is complicated. Sometimes, a small change can have effects on unexpected places. So, Chrono is a heavily tested library. Commits that break a test shouldn't be allowed in any condition.
271
280
 
272
- Chrono's unit testing is based-on [Qunit](https://qunitjs.com/) and [Karma](https://github.com/karma-runner/karma). During the developement, I recommend running Karma test together with watchify.
281
+ Chrono's unit testing is based-on [Jest](https://facebook.github.io/jest/).
273
282
 
274
- ```
275
- # Start karma
276
- npm run karma
283
+ ```bash
284
+ # Run the test
285
+ $ npm run test
277
286
 
278
- # Start watch (run on a different terminal)
279
- npm run watch
287
+ # Run the test in watch mode
288
+ $ npm run watch
280
289
  ```
281
290
 
291
+ Chrono's source files is in `src` directory. The built bundle (`dist/*`) is created by running [Webpack](https://webpack.js.org/) via the following command
292
+
293
+ ```bash
294
+ $ npm run build
295
+ ```
282
296