HEX
Server: Apache/2.4.52 (Ubuntu)
System: Linux spn-python 5.15.0-89-generic #99-Ubuntu SMP Mon Oct 30 20:42:41 UTC 2023 x86_64
User: arjun (1000)
PHP: 8.1.2-1ubuntu2.20
Disabled: NONE
Upload Files
File: //home/arjun/projects/buyercall/node_modules/bootstrap-vue-next/src/composables/useBooleanish.ts
import type {Booleanish} from '../types'
import {computed, type ComputedRef, type MaybeRefOrGetter, toValue} from 'vue'

const isBooleanish = (input: unknown): input is Booleanish =>
  typeof input === 'boolean' || input === '' || input === 'true' || input === 'false'

/**
 * Resolves a Booleanish type reactively to type boolean
 */
export default <T>(el: MaybeRefOrGetter<T>): ComputedRef<T extends Booleanish ? boolean : T> =>
  computed(() => {
    const value = toValue(el)
    return (
      !isBooleanish(value)
        ? value
        : typeof value === 'boolean'
        ? value
        : value === '' || value === 'true'
        ? true
        : false
    ) as T extends Booleanish ? boolean : T
  })