Built and signed on GitHub ActionsBuilt and signed on GitHub Actions
Built and signed on GitHub Actions
latest
Srabutdotcom/enumENUM class and all tls 1.3 enum definitions
This package works with Deno, BrowsersIt is unknown whether this package works with Cloudflare Workers, Node.js, Bun
JSR Score
100%
Published
3 hours ago (0.3.3)
JavaScript Enum Implementation
A robust enumeration implementation for JavaScript/TypeScript that provides Java-style enums with additional features for TLS 1.3 protocol definitions.
Features
- Type-safe enumerations
- Frozen constants to prevent modifications
- Value and name lookups
- Ordinal-based comparison
- JSON serialization
- Built-in TLS 1.3 protocol enumerations
Installation
deno add 'jsr:@tls/enum';
Basic Usage
import { Enum } from 'jsr:@tls/enum'; class Color extends Enum { static RED = new Color('RED', '#FF0000'); static GREEN = new Color('GREEN', '#00FF00'); static BLUE = new Color('BLUE', '#0000FF'); static { this.freeze(); // Prevent further modifications } } // Usage examples console.log(Color.RED.value); // '#FF0000' console.log(Color.RED.name); // 'RED' console.log(Color.RED.ordinal); // 0 console.log(Color.values()); // [Color.RED, Color.GREEN, Color.BLUE] console.log(Color.valueOf('GREEN')); // Color.GREEN console.log(Color.fromValue('#0000FF')); // Color.BLUE
TLS 1.3 Enumerations
SignatureScheme
import { SignatureScheme } from 'jsr:@tls/enum'; // Access signature schemes console.log(SignatureScheme.RSA_PKCS1_SHA256.value); // 0x0401 console.log(SignatureScheme.ED25519.name); // 'ED25519' console.log(SignatureScheme.FromValue(0x0403)); // 'ECDSA_SECP256R1_SHA256' console.log(SignatureScheme.Values()); // [0x0401, 0x0501, ...]
ExtensionType
import { ExtensionType } from 'jsr:@tls/enum'; // Access extension types console.log(ExtensionType.SERVER_NAME.value); // 0 console.log(ExtensionType.SUPPORTED_VERSIONS.name); // 'SUPPORTED_VERSIONS' console.log(ExtensionType.fromValue(43)); // ExtensionType.SUPPORTED_VERSIONS
API Reference
Enum Base Class
Static Methods
size
: Get the number of enum constantsvalues()
: Get all enum constantsnames()
: Get all enum constant namesvalueOf(name)
: Get enum constant by namefromValue(value)
: Get enum constant by valuefreeze()
: Prevent further modificationsisFrozen()
: Check if enum is frozen
Instance Properties
name
: The name of the enum constantvalue
: The value associated with the enum constantordinal
: The position of the constant in the enum
Instance Methods
toString()
: Get string representationtoJSON()
: Get JSON representationequals(other)
: Compare with another enum constantcompareTo(other)
: Compare ordinal positions[Symbol.toPrimitive](hint)
: Convert to primitive type
Examples
Creating Custom Enums
class HttpStatus extends Enum { static OK = new HttpStatus('OK', 200); static NOT_FOUND = new HttpStatus('NOT_FOUND', 404); static INTERNAL_ERROR = new HttpStatus('INTERNAL_ERROR', 500); static { this.freeze(); } } // Usage if (response.status === HttpStatus.OK.value) { console.log('Request successful'); }
Contributing
Contributions to improve the library are welcome. Please open an issue or pull request on the GitHub repository.
Donation
License
This project is licensed under the MIT License - see the LICENSE file for details.
Built and signed on
View transparency logGitHub Actions
Add Package
deno add jsr:@tls/enum
Import symbol
import * as enum from "@tls/enum";
---- OR ----
Import directly with a jsr specifier
import * as enum from "jsr:@tls/enum";
Add Package
npx jsr add @tls/enum
Import symbol
import * as enum from "@tls/enum";
Add Package
yarn dlx jsr add @tls/enum
Import symbol
import * as enum from "@tls/enum";
Add Package
pnpm dlx jsr add @tls/enum
Import symbol
import * as enum from "@tls/enum";
Add Package
bunx jsr add @tls/enum
Import symbol
import * as enum from "@tls/enum";