makeMap.ts 580 B

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