
Security News
Open Source CAI Framework Handles Pen Testing Tasks up to 3,600× Faster Than Humans
CAI is a new open source AI framework that automates penetration testing tasks like scanning and exploitation up to 3,600× faster than humans.
Tiny library to get all values/keys of a Typescript enum.
yarn
: yarn add enum-for
npm
: npm install --save enum-for
import {getAllEnumKeys, getAllEnumValues, getAllEnumEntries} from 'enum-for'
getAllEnumKeys
returns all keys of the enum objectgetAllEnumValues
returns all values of the enum objectgetAllEnumEntries
returns all entries ([key, value]) of the enum objectThe source code of the project is very simple (3 LOCs). You can copy and use it directly in your project.
However, I recommend installing this package instead, because it is well tested.
exports.getAllEnumKeys = enumType => Object.keys(enumType).filter(key => isNaN(Number(key)))
exports.getAllEnumValues = enumType => exports.getAllEnumKeys(enumType).map(key => enumType[key])
exports.getAllEnumEntries = enumType => exports.getAllEnumKeys(enumType).map(key => [key, enumType[key]])
import {getAllEnumKeys, getAllEnumValues, getAllEnumEntries} from 'enum-for'
enum MyEnum {
foo = 0,
bar = '1',
'1foo' = 2,
'2foo' = '3'
}
console.log(getAllEnumKeys(MyEnum))
console.log(getAllEnumValues(MyEnum))
console.log(getAllEnumEntries(MyEnum))
console.log(Object.keys(MyEnum))
console.log(Object.values(MyEnum))
console.log(Object.entries(MyEnum))
This script will print. Note that the results returned from Object.keys
, Object.values
are incorrect.
[ 'foo', 'bar', '1foo', '2foo' ]
[ 0, '1', 2, '3' ]
[ [ 'foo', 0 ], [ 'bar', '1' ], [ '1foo', 2 ], [ '2foo', '3' ] ]
[ '0', '2', 'foo', 'bar', '1foo', '2foo' ]
[ 'foo', '1foo', 0, '1', 2, '3' ]
[ [ '0', 'foo' ], [ '2', '1foo' ], [ 'foo', 0 ], [ 'bar', '1' ], [ '1foo', 2 ], [ '2foo', '3' ] ]
FAQs
An utility library to get all values/keys of a Typescript enum
The npm package enum-for receives a total of 3,674 weekly downloads. As such, enum-for popularity was classified as popular.
We found that enum-for demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer 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
CAI is a new open source AI framework that automates penetration testing tasks like scanning and exploitation up to 3,600× faster than humans.
Security News
Deno 2.4 brings back bundling, improves dependency updates and telemetry, and makes the runtime more practical for real-world JavaScript projects.
Security News
CVEForecast.org uses machine learning to project a record-breaking surge in vulnerability disclosures in 2025.