# @simu-x/const-set

> Utility for creating and asserting string constants

Latest version **1.0.2** (published 2022-01-28) · MIT license · 0 weekly downloads

## Install

```sh
npm install @simu-x/const-set
pnpm add @simu-x/const-set
yarn add @simu-x/const-set
bun add @simu-x/const-set
```

## Health

**Score 25/100 (F)** — status: abandoned.

Positive: has types; no vulnerabilities; high quality score.

Warnings: low downloads; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.0.2 |
| Published | 2022-01-28 |
| First published | 2022-01-28 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | CommonJS |
| Dependencies | 0 |
| Unpacked size | 126.6 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 1 |
| Author | Ashley Abbott |
| Maintainers | ashpabb |

## Links

- npm: https://www.npmjs.com/package/@simu-x/const-set
- Repository: https://github.com/simu-x/const-set
- Homepage: https://github.com/simu-x/const-set#readme
- Issues: https://github.com/simu-x/const-set/issues
- npm.io page: https://npm.io/package/@simu-x/const-set

## Recent versions

- 1.0.2 (latest) — 2022-01-28
- 1.0.1 — 2022-01-28
- 1.0.0 — 2022-01-28

## README

# const-set

A Typescript/Javascript utility for making Sets of constant strings

[![Build Status](https://app.travis-ci.com/simu-x/const-set.svg?branch=main)](https://app.travis-ci.com/simu-x/const-set)
[![Coverage Status](https://coveralls.io/repos/github/simu-x/const-set/badge.svg?branch=main)](https://coveralls.io/github/simu-x/const-set?branch=main)

## Installation

```sh
npm install @simu-x/const-set --save
```

## Usage

```typescript
import ConstSet, {ConstSetError} from '@simu-x/const-set';

// Make a ConstSet
const flavors = new ConstSet('strawberry', 'vanilla');

// Works like a read-only JS Set
flavors.size; // '2'

// Indexed constants are type friendly
flavors.value.strawberry; // return constant string value

// You can get the whole set of constant strings as an array
flavors.values();

// Value Checking
flavors.is('vanilla'); // return true since this is a known constant string
flavors.is('chocolatte'); // return false since this is an unknown constant string
// Note: these also function as typeguards

// Value Assertion
try {
  flavors.assert('rocky_road');
} catch (e: Error) {
  /* handle your errors here */
  if (e instanceof ConstSetError) {
    /* handle specific ConstSetError if needed */
  }
}

try {
  const rockyRoad = flavors.assert('rocky_road'); // returns the known constant string if valid
}
```

---
_Source: https://npm.io/package/@simu-x/const-set · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
