extract-time

Extracts time from an arbitrary text input.

Usage no npm install needed!

<script type="module">
  import extractTime from 'https://cdn.skypack.dev/extract-time';
</script>

README

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');
// [{time: '14:00'}]

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

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

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

extractTime('resolves ambiguous times using the provided time notation bias 1:30', 12);
// [{time: '13:30'}]

Signature

/**
 * Indicates if time format is 12-hour or 24-hour clock notation.
 */
export type TimeNotationType = 12 | 24;

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

/**
 * @param subject Arbitrary text input.
 */
type extractTime = (
  subject: string,
  timeNotation: TimeNotationType,
) => $ReadOnlyArray<TimeMatchType>;

Related projects

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