feature-flag.ts 575 B

12345678910111213141516171819202122
  1. import { computed, unref } from 'vue'
  2. import { useData } from 'vitepress'
  3. import { isClient, useBrowserLocation } from '@vueuse/core'
  4. import type { MaybeRef } from '@vueuse/core'
  5. const location = useBrowserLocation()
  6. export const useFeatureFlag = (flag: MaybeRef<string>) => {
  7. const { theme } = useData()
  8. return computed(() => {
  9. const _flag = unref(flag)
  10. if (isClient) {
  11. const params = new URLSearchParams(location.value.search)
  12. if (params.get(`feature:${_flag}`)) {
  13. return true
  14. }
  15. }
  16. return theme.value.features[_flag]
  17. })
  18. }