TypeScript Character Code Enumeration

0.0.0 · abandoned · verified Sun Apr 19

typescript-char is a lightweight, type-definition-only library providing a TypeScript enumeration for common character codes. Its primary purpose is to eliminate 'magic numbers' in code, enhancing readability and maintainability when dealing with character-based operations, such as in parsers, lexers, or character stream processing. The library currently stands at version 0.0.0, indicating a pre-release or unversioned state. As a 'header-only' library, it consists solely of a `.d.ts` file, meaning it introduces no runtime JavaScript code or overhead. Its release cadence is effectively non-existent, with no updates since 2017. Key differentiators include its zero-runtime footprint and its focus purely on providing type-safe, named constants for character codes within a TypeScript environment, allowing direct usage of `Char.OpenBrace` instead of numerical literals like `123`.

Common errors

Warnings

Install

Imports

Quickstart

Demonstrates importing the `Char` enumeration and using its constants for character codes, including converting a code back to its string representation.

import Char from 'typescript-char';

// Use a character code from the enumeration
const openBraceCode: Char = Char.OpenBrace;
console.log(`Open Brace Code: ${openBraceCode}`); // Expected output: 123

// Convert the character code back to a string character
console.log(`Character from code: ${String.fromCharCode(openBraceCode)}`); // Expected output: {

// Example in a simple parser context (conceptual, as it's types only)
function processInput(input: string) {
  if (input.charCodeAt(0) === Char.OpenParen) {
    console.log('Input starts with an opening parenthesis.');
  } else if (input.charCodeAt(0) === Char.A) {
    console.log('Input starts with an 'A'.');
  } else {
    console.log('Input starts with another character.');
  }
}

processInput('(');
processInput('Apple');
processInput('Banana');

view raw JSON →