2.0.0 • Published 5 years ago
edtf-parser v2.0.0
edtf-parser
Parses natural language to EDTF compliant date strings.
Contents
Installation
$ npm install edtf-parser
Usage
Node.js (CommonJS)
const edtfParser = require('edtf-parser');
edtfParser.parse('1940 until about June 1942');
// -> '1940/1942-06~'
Browser
ES6
import edtfParser from 'edtf-parser';
edtfParser.parse('1940 until about June 1942');
// -> '1940/1942-06~'
\
Download edtf-parser.min.js separately without the rest of the package.
<script src="edtf-parser.min.js"></script>
<script>
edtfParser.parse('1940 until about June 1942');
// -> '1940/1942-06~'
</script>
API Reference
edtfParser.parse(input, options)
options
Property | Type | Default | Description |
---|---|---|---|
locale | string | 'en' | The locale determines which words can be used for parsing and how to parse date formats. Currently, only 'en' is supported. |
customKeywords | { [keyword: string]: (original) => string } | Allows adding custom keywords with corresponding modifier functions. If a keyword is detected, it's modifier is called with the original EDTF string expecting it to return a modified EDTF string. |
Compatibility
edtf-parser implements select features of EDTF levels 0 and 1 as specified by ISO 8601-2 with some modifications, making it compatible to EDTF.js.
Level 0
Date
Input (example) | Output |
---|---|
12/31/2000 | 2000-12-31 |
August 4th 2000 | 2000-08-04 |
December 2000 | 2000-12 |
2000 | 2000 |
Date and Time
Not supported
Time Interval
Input (example) | Output |
---|---|
1984 to 2001 | 1984/2001 |
February 2010 - June 2011 | 2010-02/2011-06 |
12/31/2000 to 01/08/2001 | 2000-12-31/2001-01-08 |
Level 1
Letter-prefixed Calendar Year
Not supported
Seasons
Will be supported in the future
Qualification of a Date (Uncertain/Approximate)
Input (example) | Output |
---|---|
possibly 1984 | 1984? |
around June 2004 | 2004-06~ |
possibly about 31/12/2004 | 2004-31-12% |
Unspecified Digits
Will be supported in the future
Extended Interval (L1)
Only supporting open end and open start time intervals as well as approximate/uncertain modifiers
Input (example) | Output |
---|---|
since 1970 | [1970..] |
until 1970 | [..1970] |
1950 until around June 1970 | 1950/1970-06~ |
Negative Calendar Year
Not supported
License
MIT © Simon Mathewson