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react-aria/src/i18n/useFilter.ts"],"sourcesContent":["/*\n * Copyright 2020 Adobe. All rights reserved.\n * This file is licensed to you under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License. You may obtain a copy\n * of the License at http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software distributed under\n * the License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS\n * OF ANY KIND, either express or implied. See the License for the specific language\n * governing permissions and limitations under the License.\n */\n\nimport {useCallback, useMemo} from 'react';\nimport {useCollator} from './useCollator';\n\nexport interface Filter {\n  /** Returns whether a string starts with a given substring. */\n  startsWith: (string: string, substring: string) => boolean;\n  /** Returns whether a string ends with a given substring. */\n  endsWith: (string: string, substring: string) => boolean;\n  /** Returns whether a string contains a given substring. */\n  contains: (string: string, substring: string) => boolean;\n}\n\n/**\n * Provides localized string search functionality that is useful for filtering or matching items in\n * a list. Options can be provided to adjust the sensitivity to case, diacritics, and other\n * parameters.\n */\nexport function useFilter(options?: Intl.CollatorOptions): Filter {\n  let collator = useCollator({\n    usage: 'search',\n    ...options\n  });\n\n  // TODO(later): these methods don't currently support the ignorePunctuation option.\n  let startsWith = useCallback(\n    (string, substring) => {\n      if (substring.length === 0) {\n        return true;\n      }\n\n      // Normalize both strings so we can slice safely\n      // TODO: take into account the ignorePunctuation option as well...\n      string = string.normalize('NFC');\n      substring = substring.normalize('NFC');\n      return collator.compare(string.slice(0, substring.length), substring) === 0;\n    },\n    [collator]\n  );\n\n  let endsWith = useCallback(\n    (string, substring) => {\n      if (substring.length === 0) {\n        return true;\n      }\n\n      string = string.normalize('NFC');\n      substring = substring.normalize('NFC');\n      return collator.compare(string.slice(-substring.length), substring) === 0;\n    },\n    [collator]\n  );\n\n  let contains = useCallback(\n    (string, substring) => {\n      if (substring.length === 0) {\n        return true;\n      }\n\n      string = string.normalize('NFC');\n      substring = substring.normalize('NFC');\n\n      let scan = 0;\n      let sliceLen = substring.length;\n      for (; scan + sliceLen <= string.length; scan++) {\n        let slice = string.slice(scan, scan + sliceLen);\n        if (collator.compare(substring, slice) === 0) {\n          return true;\n        }\n      }\n\n      return false;\n    },\n    [collator]\n  );\n\n  return useMemo(\n    () => ({\n      startsWith,\n      endsWith,\n      contains\n    }),\n    [startsWith, endsWith, contains]\n  );\n}\n"],"names":[],"version":3,"file":"useFilter.mjs.map"}