Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/mugendi/parse-dates
Easy dates parser that leverages on the power of n-gramify & http://www.datejs.com to parse dates that other parsers would fail. The concept is simple, instead on Regex, tokenize string into 'reducing ngrams' & extract!
https://github.com/mugendi/parse-dates
Last synced: 15 days ago
JSON representation
Easy dates parser that leverages on the power of n-gramify & http://www.datejs.com to parse dates that other parsers would fail. The concept is simple, instead on Regex, tokenize string into 'reducing ngrams' & extract!
- Host: GitHub
- URL: https://github.com/mugendi/parse-dates
- Owner: mugendi
- Created: 2015-07-21T14:33:32.000Z (over 9 years ago)
- Default Branch: master
- Last Pushed: 2018-01-10T08:43:52.000Z (almost 7 years ago)
- Last Synced: 2024-10-25T12:24:08.446Z (18 days ago)
- Language: JavaScript
- Homepage:
- Size: 15.6 KB
- Stars: 3
- Watchers: 1
- Forks: 1
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# Extract dates from text
Easy dates parser that leverages on the power of [n-gramify](https://www.npmjs.com/package/n-gramify), [datejs](http://www.datejs.com) & [dehumanize-date](https://www.npmjs.com/package/dehumanize-date) to parse dates that other parsers would fail.
The concept is simple, instead on Regex, we tokenize the string into 'reducing ngrams' & then extract dates!
**datejs** does the initial parsing & then we use **dehumanize-date** to confirm parsed tokens & format them.
```javascript
var parse_date = require ( 'parse-dates' )
var s=" Peter was born in 5th january 1994 will be 44 years old next week. "
var parsed=parse_date(s)console.log(JSON.stringify(parsed,0,4));
```
Output:
```json
{
"dates": [
"1994-01-05T00:00:00.000Z"
],
"string": {
"in": " Peter was born in 5th january 1994 and will be 44 years old next week. ",
"out": " Peter was born in 1994-01-05T00:00:00.000Z and will be 44 years old next week. ",
"annotated": " Peter was born in {DATE: 1994-01-05T00:00:00.000Z} and will be 44 years old next week. "
}
}```