ensure-get-list-val
TypeScript icon, indicating that this package has built-in type declarations

0.0.2 • Public • Published

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

Readme

Keywords

Package Sidebar

Install

npm i ensure-get-list-val

Weekly Downloads

2

Version

0.0.2

License

MIT

Unpacked Size

17.5 kB

Total Files

13

Last publish

Collaborators

  • wsa123456