A TypeScript library providing a strongly-typed enum for WebSocket connection close codes as defined in RFC 6455. Version 1.0.0 is the current stable release. It offers a single enum (CloseCode) with all standard close codes (NORMAL_CLOSURE, GOING_AWAY, PROTOCOL_ERROR, etc.) and maps them to their numeric values. Unlike plain string or number constants, this library provides compile-time type checking and autocomplete in IDEs, reducing errors from mistyped magic numbers. Suitable for both Node.js and browser environments with ESM and CommonJS support. No dependencies. Ships TypeScript declaration files.
npm install websocket-close-codesNo compatibility data collected yet for this library.
Verified import paths — ran on the pinned version, not inferred.
Demonstrates importing the CloseCode enum and using it to close a WebSocket connection with a standard code.
Always use one of the defined enum values, not raw numbers like 0.
Only use the named members from CloseCode (1000-1003, 1005, etc.) as defined in the documentation.
Use only standard codes (1000-1015) unless you control both endpoints and have agreed on private codes.
Use `import { CloseCode } from 'websocket-close-codes';`Use `const { CloseCode } = require('websocket-close-codes');`Do not try to change enum values; they are read-only constants. Use the enum directly: `CloseCode.NORMAL_CLOSURE`
No dependency data recorded yet.