1.0.0 • Published 12 months ago

@aak.lear/enum-objects v1.0.0

Weekly downloads
-
License
MIT
Repository
github
Last release
12 months ago

@aak.lear/enum-objects

This package provides utilities and types for using const objects as enums in JavaScript and TypeScript

Install

npm

npm i @aak.lear/enum-objects

yarn

yarn add @aak.lear/enum-objects

Usage

import { createEnumObject, createEnumObjectTypeGuard, Values } from '@aak.lear/enum-objects';

/* declarations */

export const AXES = createEnumObject(['vertical', 'horizontal']);

export const isAxis = createEnumObjectTypeGuard(AXES);

export type Axis = Values<typeof AXES>;

/* usage */

const x = AXES.horizontal // x is 'horizontal' and it's type is 'horizontal'
const y = AXES.vertical // y is 'vertical' and it's type is 'vertical'

let someAxis: Axis | undefined

if (isAxis(someAxis)) {
  // someAxis type is Axis
} else {
  // someAxis type is undefined
}
1.0.0

12 months ago

1.0.0-beta.4

2 years ago

1.0.0-beta.3

2 years ago

1.0.0-beta.2

2 years ago

1.0.0-beta.1

2 years ago