makeMap.ts 486 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. /*! #__NO_SIDE_EFFECTS__ */
  9. export function makeMap(
  10. str: string,
  11. expectsLowerCase?: boolean,
  12. ): (key: string) => boolean {
  13. const set = new Set(str.split(','))
  14. return expectsLowerCase
  15. ? val => set.has(val.toLowerCase())
  16. : val => set.has(val)
  17. }