0.0.6 • Published 8 years ago
@datagica/parse-age v0.0.6
Age parser
Can detect an age in a document. well, most of the time.
Installation
$ npm install --save @datagica/parse-age
Usage
import parseAge from "@datagica/parse-age";
parseAge(INPUT).then(result => {
if (result == null) {
console.log("not found")
} else {
console.log("found: ", result)
}
}).catch(err => {
console.log("invalid input data: "+err)
})
Examples
{
import parseAge from "@datagica/parse-age";
// get the birth date and estimate the age
parseAge("date de naissance: 1 avril 1985").then(..).catch(..)
{
"str":"Wed Apr 01 1985 00:00:00 GMT+0200 (CEST)",
"timestamp": 483746400000,
"month": 4,
"date": 1,
"year": 1985,
"age": 30
}
// get the age and estimate the birth date
parseAge("j'ai 29 ans").then(..).catch(..)
{
"str":"Thu Jan 01 1987 00:00:00 GMT+0100 (CET)",
"timestamp":536454000000,
"month":1,
"date":1,
"year":1987,
"age":29
}
TODO
- Fix "1 avril 1985" (see tests)
- birth date parser should support more text formats
- should support more languages, too