hunk.code_window: |                                 |              | 1453-05-29T23:59:59.999Z | 23:59:59 GMT+00:00                               | Errored                  |
   | Combination of date and time    | Pp           | 1987-02-11T12:13:14.015Z | 11.02.1987 12:13                                 | 1987-02-11T12:13:00.000Z |
   |                                 |              | 1453-05-29T23:59:59.999Z | 29.05.1453 23:59                                 | 1453-05-29T23:59:00.000Z |
   |                                 | PPpp         | 1987-02-11T12:13:14.015Z | 11. Feb. 1987 12:13:14                           | 1987-02-11T12:13:14.000Z |
   |                                 |              | 1453-05-29T23:59:59.999Z | 29. Mai. 1453 23:59:59                           | 1453-05-29T23:59:59.000Z |
   |                                 | PPPppp       | 1987-02-11T12:13:14.015Z | 11. Februar 1987 um 12:13:14 GMT+0               | Errored                  |
   |                                 |              | 1453-05-29T23:59:59.999Z | 29. Mai 1453 um 23:59:59 GMT+0                   | Errored                  |
   |                                 | PPPPpppp     | 1987-02-11T12:13:14.015Z | Mittwoch, 11. Februar 1987 um 12:13:14 GMT+00:00 | Errored                  |
  
hunk.labels: keep keep keep replace replace keep keep keep
hunk.after_edit: |                                 | PPpp         | 1987-02-11T12:13:14.015Z | 11. Feb 1987 12:13:14                            | 1987-02-11T12:13:14.000Z |
   |                                 |              | 1453-05-29T23:59:59.999Z | 29. Mai 1453 23:59:59                            | 1453-05-29T23:59:59.000Z |
  
hunk.file_path: src/locale/de-AT/snapshot.md
hunk.type: replace
file: import {
    BuildMatchFnArgs,
    LocaleDayPeriod,
    LocaleUnit,
    LocaleParsePatternWidth,
    LocalePatternWidth,
    MatchFn,
  } from '../../types'
  
  export default function buildMatchFn<
    Result extends LocaleUnit,
    DefaultMatchWidth extends LocalePatternWidth,
    DefaultParseWidth extends LocaleParsePatternWidth
  >(
    args: BuildMatchFnArgs<Result, DefaultMatchWidth, DefaultParseWidth>
  ): MatchFn<Result> {
    return (string, options = {}) => {
      const width = options.width
  
      const matchPattern =
        (width && args.matchPatterns[width]) ||
        args.matchPatterns[args.defaultMatchWidth]
      const matchResult = string.match(matchPattern)
  
      if (!matchResult) {
        return null
      }
      const matchedString = matchResult[0]
  
      const parsePatterns =
        (width && args.parsePatterns[width]) ||
        args.parsePatterns[args.defaultParseWidth]
  
      const key = (Array.isArray(parsePatterns)
        ? findIndex(parsePatterns, (pattern) => pattern.test(matchedString))
        : findKey(parsePatterns, (pattern: any) =>
            pattern.test(matchedString)
          )) as Result extends LocaleDayPeriod ? string : number
  
      let value: Result
  
      value = (args.valueCallback ? args.valueCallback(key) : key) as Result
      value = options.valueCallback ? options.valueCallback(value) : value
  
      const rest = string.slice(matchedString.length)
  
      return { value, rest }
    }
  }
  
  function findKey<Value, Obj extends { [key in string | number]: Value }>(
    object: Obj,
    predicate: (value: Value) => boolean
  ): keyof Obj | undefined {
    for (const key in object) {
      if (object.hasOwnProperty(key) && predicate(object[key])) {
        return key
      }
    }
    return undefined
  }
  
  function findIndex<Item>(
    array: Item[],
    predicate: (item: Item) => boolean
  ): number | undefined {
    for (let key = 0; key < array.length; key++) {
      if (predicate(array[key])) {
        return key
      }
    }
    return undefined
  }
  