rofrischmann/tokenize-sync

View on GitHub
modules/getFirstMatchingRule.js

Summary

Maintainability
A
0 mins
Test Coverage
/* @flow */
import type { RuleMap } from '../types/RuleMap'

export default function getFirstMatchingRule(
  str: string,
  ruleMap: RuleMap
): string | false {
  for (const token in ruleMap) {
    if (ruleMap[token].test(str)) {
      return token
    }
  }

  // return false if not rule matches
  return false
}