![Maven Central Adds Sigstore Signature Validation](https://cdn.sanity.io/images/cgdhsj6q/production/7da3bc8a946cfb5df15d7fcf49767faedc72b483-1024x1024.webp?w=400&fit=max&auto=format)
Security News
Maven Central Adds Sigstore Signature Validation
Maven Central now validates Sigstore signatures, making it easier for developers to verify the provenance of Java packages.
@gradecam/tsenum
Advanced tools
Typescript supports enum now, but there are times when you may want a little more flexibility than built-in enums give you; this package was adapted from an example in a gist linked from a typescript issue which I cannot now find, but suffice it to say that though we have modified it a bit the idea is not original to us.
npm install --save @gradecam/tsenum
import {MakeEnum, TypeFromEnum} from 'tsenum';
const Colors = MakeEnum({
Red: 'red',
Blue: 'blue',
Green: 'green',
Violet: 'violet',
Black: 'black'
});
type Colors = TypeFromEnum<typeof Colors>;
// type Colors = 'red' | 'blue' | 'green' | 'violet' | 'black'
// value Colors is a frozen object with the keys expected
// typeof Colors.Red is 'red', et al
carColor: Colors = 'red'; // valid
carColor = Colors.Green; // valid
carColor = 'yellow'; // typescript error, not a valid color
MakeEnum will merge multiple enum objects into one (up to 9), allowing you to combine types.
import {MakeEnum, TypeFromEnum} from 'tsenum';
const PrimaryColors = MakeEnum({
Red: 'red',
Blue: 'blue',
Green: 'green',
});
type PrimaryColors = TypeFromEnum<typeof PrimaryColors>;
const SecondaryColors = MakeEnum({
Yellow: 'yellow',
Cyan: 'cyan',
Magenta: 'magenta'
});
type SecondaryColors = TypeFromEnum<typeof SecondaryColors>;
const AllColors = MakeEnum(PrimaryColors, SecondaryColors);
type AllColors = TypeFromEnum<typeof AllColors>;
// type AllColors = 'red' | 'blue' | 'green' | 'yellow' | 'cyan' | 'magenta'
Sometimes you may want an array of possible values, such as when defining an enum type in a mongoose
schema. Since the enum is an object, you can use Object.values
to get that:
import {MakeEnum, TypeFromEnum} from 'tsenum';
const PrimaryColors = MakeEnum({
Red: 'red',
Blue: 'blue',
Green: 'green',
});
type PrimaryColors = TypeFromEnum<typeof PrimaryColors>;
const PrimaryColorList = Object.values(PrimaryColors); // ['red', 'blue', 'green']
// typeof PrimaryColorList = Array<'red'|'blue'|'green'>
FAQs
Super simple typescript library for string-compatible enums
The npm package @gradecam/tsenum receives a total of 0 weekly downloads. As such, @gradecam/tsenum popularity was classified as not popular.
We found that @gradecam/tsenum demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 5 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
Maven Central now validates Sigstore signatures, making it easier for developers to verify the provenance of Java packages.
Security News
CISOs are racing to adopt AI for cybersecurity, but hurdles in budgets and governance may leave some falling behind in the fight against cyber threats.
Research
Security News
Socket researchers uncovered a backdoored typosquat of BoltDB in the Go ecosystem, exploiting Go Module Proxy caching to persist undetected for years.