/extract-time

Extracts time from an arbitrary text input.

Primary LanguageJavaScriptOtherNOASSERTION

extract-time ⏰

Travis build status Coveralls NPM version Canonical Code Style Twitter Follow

Extracts time from an arbitrary text input.

Features

  • Deterministic and unambiguous time parsing.

Usage

import extractTime from 'extract-time';

extractTime('extracts time from anywhere within the input 14:00', 24);
// [{time: '14:00'}]

extractTime('extracts multiple times located anywhere within the input: 16:00, 18:00', 24);
// [{time: '16:00'}, {time: '18:00'}]

extractTime('distinguish between the civilian 1:30 PM ...', 12);
// [{time: '13:30'}]

extractTime('... and military time formats 13:30', 24);
// [{time: '13:30'}]

Signature

type TimeFormatType = 12 | 24;

/**
 * @property time 24-hour military time.
 */
type TimeMatchType = {|
  +time: string
|};

/**
 * @param subject Arbitrary text input.
 * @param timeFormat Expected time format (12-hour am-pm clock or 24-hour military time).
 */
type extractTime = (subject: string, timeFormat: TimeFormatType) => $ReadOnlyArray<TimeMatchType>;

Related projects

  • extract-date – Extracts date from an arbitrary text input.
  • extract-price – Extracts price from an arbitrary text input.