2.0.0 • Published 5 years ago

edtf-parser v2.0.0

Weekly downloads
-
License
MIT
Repository
github
Last release
5 years ago

edtf-parser

Parses natural language to EDTF compliant date strings.

Contents

  1. Installation
  2. Usage
  3. API Reference
  4. Compatibility
  5. License

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

PropertyTypeDefaultDescription
localestring'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/20002000-12-31
August 4th 20002000-08-04
December 20002000-12
20002000

Date and Time

Not supported

Time Interval

Input (example)Output
1984 to 20011984/2001
February 2010 - June 20112010-02/2011-06
12/31/2000 to 01/08/20012000-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 19841984?
around June 20042004-06~
possibly about 31/12/20042004-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 19701950/1970-06~

Negative Calendar Year

Not supported

License

MIT © Simon Mathewson

2.0.0

5 years ago

1.0.0

5 years ago