makeMap.ts 564 B

12345678910111213141516
  1. // Make a map and return a function for checking if a key
  2. // is in that map.
  3. //
  4. // IMPORTANT: all calls of this function must be prefixed with /*#__PURE__*/
  5. // So that rollup can tree-shake them if necessary.
  6. export function makeMap(
  7. str: string,
  8. expectsLowerCase?: boolean
  9. ): (key: string) => boolean {
  10. const map: Record<string, boolean> = Object.create(null)
  11. const list: Array<string> = str.split(',')
  12. for (let i = 0; i < list.length; i++) {
  13. map[list[i]] = true
  14. }
  15. return expectsLowerCase ? val => !!map[val.toLowerCase()] : val => !!map[val]
  16. }