2022-11-01 20:31:39 +08:00
|
|
|
<script setup lang="ts">
|
|
|
|
import { computed } from 'vue'
|
|
|
|
import ApiTyping from './vp-api-typing.vue'
|
|
|
|
|
2022-11-01 21:52:16 +08:00
|
|
|
import type { PropType } from 'vue'
|
|
|
|
|
|
|
|
type ParamType = [string, string]
|
|
|
|
|
2022-11-01 20:31:39 +08:00
|
|
|
const props = defineProps({
|
2022-11-01 21:52:16 +08:00
|
|
|
/**
|
|
|
|
* @description params list, shape of Array<[key: string, value: string]>
|
|
|
|
*/
|
2022-11-01 20:31:39 +08:00
|
|
|
params: {
|
2022-11-01 21:52:16 +08:00
|
|
|
type: Array as PropType<Array<ParamType>>,
|
|
|
|
default: () => [],
|
2022-11-01 20:31:39 +08:00
|
|
|
},
|
|
|
|
returns: {
|
|
|
|
type: String,
|
|
|
|
default: 'void',
|
|
|
|
},
|
|
|
|
})
|
|
|
|
|
2022-11-01 21:52:16 +08:00
|
|
|
const mappedParams = computed(() =>
|
|
|
|
props.params
|
2022-11-04 23:31:33 +08:00
|
|
|
.reduce((params, [key, val]) => {
|
|
|
|
let type = val
|
|
|
|
if (Array.isArray(val)) {
|
|
|
|
type = val.join(' | ')
|
|
|
|
}
|
|
|
|
return params.concat([`${key}: ${type}`])
|
|
|
|
}, [] as string[])
|
2022-11-01 21:52:16 +08:00
|
|
|
.join(', ')
|
|
|
|
)
|
|
|
|
|
|
|
|
const details = computed(() => `(${mappedParams.value}) => ${props.returns}`)
|
2022-11-01 20:31:39 +08:00
|
|
|
</script>
|
|
|
|
|
|
|
|
<template>
|
|
|
|
<api-typing type="Function" :details="details" />
|
|
|
|
</template>
|