mirror of
https://github.com/soybeanjs/soybean-admin.git
synced 2025-10-13 05:13:41 +08:00
feat(projects): 1.0 beta
This commit is contained in:
22
src/utils/common.ts
Normal file
22
src/utils/common.ts
Normal file
@@ -0,0 +1,22 @@
|
||||
/**
|
||||
* transform record to option
|
||||
* @param record
|
||||
* @example
|
||||
* ```ts
|
||||
* const record = {
|
||||
* key1: 'label1',
|
||||
* key2: 'label2'
|
||||
* };
|
||||
* const options = transformRecordToOption(record);
|
||||
* // [
|
||||
* // { value: 'key1', label: 'label1' },
|
||||
* // { value: 'key2', label: 'label2' }
|
||||
* // ]
|
||||
* ```
|
||||
*/
|
||||
export function transformRecordToOption<T extends Record<string, string>>(record: T) {
|
||||
return Object.entries(record).map(([value, label]) => ({
|
||||
value,
|
||||
label
|
||||
})) as Common.Option<keyof T>[];
|
||||
}
|
Reference in New Issue
Block a user