# @swim/codec

> Incremental I/O; functional parsers and writers; display, debug, and diagnostic formatters; and Unicode and binary codecs

Latest version **4.0.0** (published 2024-06-09) · Apache-2.0 license · 0 weekly downloads

## Install

```sh
npm install @swim/codec
pnpm add @swim/codec
yarn add @swim/codec
bun add @swim/codec
```

## Health

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

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

Warnings: low downloads.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 4.0.0 |
| Published | 2024-06-09 |
| First published | 2019-02-18 |
| Weekly downloads | 0 |
| License | Apache-2.0 |
| TypeScript types | bundled |
| Module format | ESM + CommonJS |
| Dependencies | 2 |
| Unpacked size | 1.1 MB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Author | Chris Sachs |
| Maintainers | cwjames19, ajay-gov, c9r |
| Keywords | codec, decoder, encoder, incremental, iteratee, functional, parser, serialization, swim, writer |

## Links

- npm: https://www.npmjs.com/package/@swim/codec
- Repository: https://github.com/swimos/swim-js
- Homepage: https://github.com/swimos/swim-js/tree/main/swim-core/swim-codec
- Issues: https://github.com/swimos/swim-js/issues
- npm.io page: https://npm.io/package/@swim/codec

## Dependencies (2)

- [tslib](https://npm.io/package/tslib.md) >= 2.5
- [@swim/util](https://npm.io/package/@swim/util.md) 4.0.0

## Alternatives

- [babylon](https://npm.io/package/babylon.md) — 5.1M weekly downloads
- [csscolorparser](https://npm.io/package/csscolorparser.md) — 3.7M weekly downloads
- [expr-eval-fork](https://npm.io/package/expr-eval-fork.md) — 1.5M weekly downloads
- [@leeoniya/ufuzzy](https://npm.io/package/@leeoniya/ufuzzy.md) — 247.7K weekly downloads
- [xml-parser](https://npm.io/package/xml-parser.md) — 78.4K weekly downloads

## Recent versions

- 4.0.0 (latest) — 2024-06-09
- 4.0.0-dev.20240413 (dev) — 2024-04-13
- 4.0.0-dev.20210927.3 — 2024-04-04
- 4.0.0-dev.20230923 — 2023-09-23
- 4.0.0-dev.20220527.3 — 2022-05-27
- 4.0.0-dev.20220527.2 — 2022-05-27
- 4.0.0-dev.20220527.1 — 2022-05-27
- 4.0.0-dev.20220527 — 2022-05-27
- 4.0.0-dev.20210927.2 — 2021-11-11
- 4.0.0-dev.20210927.1 — 2021-09-27
- 4.0.0-dev.20210927 — 2021-09-27
- 4.0.0-dev.20210923 — 2021-09-23
- 4.0.0-dev.20210920 — 2021-09-20
- 4.0.0-dev.20210826 — 2021-08-26
- 3.11.1 — 2021-08-17
- … 21 more at https://npm.io/package/@swim/codec/versions

## README

# [![Swim](https://docs.swimos.org/readme/breach-marlin-blue-wide.svg)](https://www.swimos.org) Swim Codec Library

The Swim Codec library implements an incremental I/O engine, providing:

- functional parsers and writers
- display, debug, and diagnostic formatters
- Unicode and binary codecs

## Overview

### Inputs and Outputs

An `Input` reader abstracts over a non-blocking token input stream, with single
token lookahead. An `Output` writer abstracts over a non-blocking token output
stream.

### Parsers and Writers

A `Parser` incrementally reads from a sequence of `Input` chunks to produce a
parsed result. A `Writer` incrementally writes to a sequence of `Output`
chunks.

### Binary codecs

The `Binary` factory has methods to create `Input` readers that read bytes out
of byte buffers, and methods to create `Output` writers that write bytes into
byte buffers.

### Text codecs

The `Unicode` factory has methods to create `Input` readers that read Unicode
code points out of strings, and methods to create `Output` writers that write
Unicode code points into strings.

The `Utf8` factory has methods to create `Input` readers that decode Unicode
code points out of UTF-8 encoded byte buffers, and methods to create `Output`
writers that encode Unicode code points into UTF-8 encoded byte buffers.

### Binary formats

The `Base10` factory has methods to create `Parser`s that incrementally parse
decimal formatted integers, and methods to create `Writer`s that incrementally
write decimal formatted integers.

The `Base16` factory has methods to create `Parser`s that incrementally decode
hexadecimal encoded text input into byte buffers, and methods to create
`Writer`s that incrementally encode byte buffers to hexadecimal encoded text
output.

The `Base64` factory has methods to create `Parser`s that incrementally decode
base-64 encoded text input into byte buffers, and methods to create `Writer`s
that incrementally encode byte buffers to base-64 encoded text output.

### Formatters

The `Display` interface provides a standard way for implementing classes to
directly output human readable display strings. Similarly, the `Debug`
interface provides a standard way for implementing classes to directly output
developer readable debug strings.

`Format` provides extension methods to output display and debug strings for all
types, including builtin JavaScript types. `OutputStyle` provides helper
functions to conditionally emit ASCII escape codes to stylize text for console
output.

### Diagnostics

A `Tag` abstracts over a source input location. A `Mark` describes a source
input position, and a `Span` describes a source input range. A `Diagnostic`
attaches an informational message to a source input location, and supports
displaying the diagnostic as an annotated snippet of the relevant source input.

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