You're Invited:Meet the Socket Team at RSAC and BSidesSF 2026, March 23–26.RSVP →
Socket
Book a DemoSign in
Socket

@xylabs/enum

Package Overview
Dependencies
Maintainers
5
Versions
248
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@xylabs/enum

Base functionality used throughout XY Labs TypeScript/JavaScript libraries

latest
Source
npmnpm
Version
5.0.86
Version published
Weekly downloads
13K
1151.79%
Maintainers
5
Weekly downloads
Ā 
Created
Source

@xylabs/enum

logo

main-build npm-badge npm-downloads-badge jsdelivr-badge npm-license-badge codacy-badge codeclimate-badge snyk-badge socket-badge

Base functionality used throughout XY Labs TypeScript/JavaScript libraries

Reference

@xylabs/enum

Type Aliases

Type AliasDescription
EnumA utility type that, given a Record<string, unknown>, returns a readonly version of that record. This results in a type where all properties of T are readonly.
EnumKeyA utility type that, given an Enum object, returns the union of its keys.
EnumValueA utility type that, given an Enum object, returns the union of its values.

Functions

FunctionDescription
EnumTransforms a given record object into a readonly "enum-like" structure while preserving the literal types of its values. This allows you to use the returned object both at runtime (for lookups) and at compile time (for strongly typed values).

functions

Enum

@xylabs/enum

function Enum<T>(obj: Readonly<T>): Enum<T>;

Transforms a given record object into a readonly "enum-like" structure while preserving the literal types of its values. This allows you to use the returned object both at runtime (for lookups) and at compile time (for strongly typed values).

To maintain literal types (i.e., prevent them from being widened to string, number, etc.), ensure you annotate your object with as const before passing it to Enum.

Type Parameters

Type ParameterDescription
T extends Record<string | number | symbol, unknown>A record type with string keys and any kind of values.

Parameters

ParameterTypeDescription
objReadonly<T>A readonly record object annotated with as const.

Returns

Enum<T>

A readonly version of the provided record, preserving exact literal value types.

Example

// Defining a record with literal types using as const:
const DnsRecordType = Enum({
  A: 1,
  AAAA: 28,
  CAA: 257,
  CNAME: 5,
  DNAME: 39,
  MX: 15,
  NS: 2,
  PTR: 12,
  SOA: 6,
  SPF: 99,
  SRV: 33,
  TXT: 16,
} as const);

// DnsRecordType is now a readonly object:
// {
//   readonly A: 1;
//   readonly AAAA: 28;
//   readonly CAA: 257;
//   readonly CNAME: 5;
//   readonly DNAME: 39;
//   readonly MX: 15;
//   readonly NS: 2;
//   readonly PTR: 12;
//   readonly SOA: 6;
//   readonly SPF: 99;
//   readonly SRV: 33;
//   readonly TXT: 16;
// }

type-aliases

Enum

@xylabs/enum

type Enum<T> = { readonly [K in keyof T]: T[K] };

A utility type that, given a Record<string, unknown>, returns a readonly version of that record. This results in a type where all properties of T are readonly.

Type Parameters

Type ParameterDescription
T extends Readonly<Record<string | number | symbol, unknown>>The record type to make readonly.

Example

// Given a record:
export const DnsRecordType = Enum({
  A: 1,
  AAAA: 28,
  CAA: 257,
  CNAME: 5,
  DNAME: 39,
  MX: 15,
  NS: 2,
  PTR: 12,
  SOA: 6,
  SPF: 99,
  SRV: 33,
  TXT: 16,
})

// Now the type inference will preserve the literal types:
export type DnsRecordType = Enum<typeof DnsRecordType>

EnumKey

@xylabs/enum

type EnumKey<T, K> = keyof K;

A utility type that, given an Enum object, returns the union of its keys.

Type Parameters

Type ParameterDefault type
T extends Record<string | number | symbol, unknown>-
KEnum<T>

EnumValue

@xylabs/enum

type EnumValue<T, K> = K[keyof K];

A utility type that, given an Enum object, returns the union of its values.

Type Parameters

Type ParameterDefault type
T extends Record<string | number | symbol, unknown>-
KEnum<T>

Part of sdk-js

Maintainers

License

See the LICENSE file for license details

Credits

Made with šŸ”„ and ā„ļø by XYLabs

FAQs

Package last updated on 11 Mar 2026

Did you know?

Socket

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.

Install

Related posts