0.0.1 • Published 8 months ago
format-enum v0.0.1
A Enum Tool
const LIST_ENUM = createEnum([
{ key: 'apple', value: 0, desc: '苹果' },
{ key: 'pear', value: 1, desc: '梨' },
{ key: 'watermelon', value: 2, desc: '西瓜' }
]);
getItem
LIST_ENUM.getItem(0)
// { key: 'apple', value: 0, desc: '苹果' }
getByKey
LIST_ENUM.getByKey('梨')
// pear
getByValue
LIST_ENUM.getByValue('watermelon')
// 2
getByDesc
LIST_ENUM.getByDesc('apple')
// 苹果
getByList
LIST_ENUM.getByList()
// [
// { key: 'apple', value: 0, desc: '苹果' },
// { key: 'pear', value: 1, desc: '梨' },
// { key: 'watermelon', value: 2, desc: '西瓜' }
// ]
getByOptions
LIST_ENUM.getByOptions({ id: 'value', title: 'desc' })
// [
// { id: 0, title: '苹果' },
// { id: 1, title: '梨' },
// { id: 2, title: '西瓜' }
// ]
has
LIST_ENUM.has(2)
// true
Original author: @mengxianghan https://github.com/mengxianghan/xy-enum.git
0.0.1
8 months ago