Security News
Fluent Assertions Faces Backlash After Abandoning Open Source Licensing
Fluent Assertions is facing backlash after dropping the Apache license for a commercial model, leaving users blindsided and questioning contributor rights.
English | 简体中文
typescript enum Convert to an option data structure
npm install enum-opt --save
npx enum-opt yourfile.ts
Or add script in package.json script
"scripts": {
"enum-opt": "enum-opt"
}
npm run enum-opt
Command | Description | Default |
---|---|---|
-o | Output file directory | . |
Add enumoptconfig.json or.enumoptrc.js to the root directory
enumoptconfig.json
{
"entry": "enum.ts"
}
.enumoptrc.js
module.exports = {
entry: "enum.ts"
}
Property | Description | Type | Default |
---|---|---|---|
entry | Enumeration file path to be parsed, multiple files can be configured using objects | string|object | - |
outDir | Output file directory | string | ./ |
fileSuffix | The output file name is the entry file name + the file name suffix (invalid if the entry type is object). | string | -opt |
optionSuffix | Output option variable suffix | string | Options |
exclude | Excluded enumeration, excluded options will not be generated | string | - |
enum.ts
/**
* action type
*/
export enum ActionType {
// add
Add,
// edit
Edit,
// detail
Detail,
// perfect
Perfect,
}
npx enum-opt enum.ts
generate enum-opt.ts
// @ts-ignore
import { ActionType } from 'enum'
/**
* action type
*/
export const actionTypeOptions = [
{
label: 'add',
value: ActionType.Add,
},
{
label: 'edit',
value: ActionType.Edit,
},
{
label: 'detail',
value: ActionType.Detail,
},
{
label: 'perfect',
value: ActionType.Perfect,
},
]
enumoptconfig.json
{
"entry": {
"enum-options": "enum.ts",
"actions-options": "action-enum.ts"
}
}
enum-options.ts and actions-options.ts will be printed
import { valueToLabel, labelToValue } from 'enum-opt'
import { actionTypeOptions } from './util/enum-opt'
import { ActionType } from './enum'
valueToLabel(ActionType.Add, actionTypeOptions) // add
labelToValue('add', actionTypeOptions) // 1
FAQs
typescript enum to options
The npm package enum-opt receives a total of 2 weekly downloads. As such, enum-opt popularity was classified as not popular.
We found that enum-opt demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 0 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Fluent Assertions is facing backlash after dropping the Apache license for a commercial model, leaving users blindsided and questioning contributor rights.
Research
Security News
Socket researchers uncover the risks of a malicious Python package targeting Discord developers.
Security News
The UK is proposing a bold ban on ransomware payments by public entities to disrupt cybercrime, protect critical services, and lead global cybersecurity efforts.