Skip to content

wsafight/ensure-get-list-val

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published