Skip to content

Latest commit

 

History

History
59 lines (41 loc) · 1.41 KB

README.md

File metadata and controls

59 lines (41 loc) · 1.41 KB

ensure-get-list-val

Build Status NPM Version

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