2019-10-16 00:19:46 +08:00
|
|
|
// Make a map and return a function for checking if a key
|
|
|
|
// is in that map.
|
|
|
|
//
|
2019-10-16 00:22:32 +08:00
|
|
|
// IMPORTANT: all calls of this function must be prefixed with /*#__PURE__*/
|
2019-10-16 00:19:46 +08:00
|
|
|
// So that rollup can tree-shake them if necessary.
|
2019-10-16 00:11:08 +08:00
|
|
|
export function makeMap(
|
|
|
|
str: string,
|
|
|
|
expectsLowerCase?: boolean
|
|
|
|
): (key: string) => boolean {
|
|
|
|
const map: Record<string, boolean> = Object.create(null)
|
|
|
|
const list: Array<string> = str.split(',')
|
|
|
|
for (let i = 0; i < list.length; i++) {
|
|
|
|
map[list[i]] = true
|
|
|
|
}
|
|
|
|
return expectsLowerCase ? val => !!map[val.toLowerCase()] : val => !!map[val]
|
|
|
|
}
|