ensure-get-list-val
v0.0.2
Published
Make sure you get a usable value from the list
Downloads
8
Readme
ensure-get-list-val
Read this in other languages: 简体中文
Make sure you can get an available value from the list
Installation
npm install ensure-get-list-val
或者
yarn add ensure-get-list-val
API
| 参数 | 说明 | 类型 | 默认值 | | :----| :---- | :---- | :---- | | items | list data | ItemType[] | undefined | | value | val | ValueType | undefined | | getVal | Function to get value | (item: ItemType) => ValueType | item => item | | pos | The position of the returned value when no data is queried | 'first','last' | 'frist' |
Usage
import ensureGetValFromList from 'ensure-get-list-val'
const currentVal = ensureGetValFromList<number>({
items: [1, 2, 3]
})
currentVal // 1
import ensureGetValFromList from 'ensure-get-list-val'
interface stringSelectOptinos {
label: string;
value: string;
}
const currentVal = ensureGetValFromList<stringSelectOptinos, string>({
items: ['1', '2', '3'].map(item => ({label: item, value: item})),
value: '4',
getVal: (item) => item.value,
})
currentVal // 1