Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/adam-rocska/ts-codec
TypeScript library that delivers reliable contracts for encoding and decoding values with strong type safety.
https://github.com/adam-rocska/ts-codec
codec coder decoder decoding encoder encoding json transformation typescript typescript-library
Last synced: 1 day ago
JSON representation
TypeScript library that delivers reliable contracts for encoding and decoding values with strong type safety.
- Host: GitHub
- URL: https://github.com/adam-rocska/ts-codec
- Owner: adam-rocska
- License: mit
- Created: 2023-03-27T17:35:14.000Z (almost 2 years ago)
- Default Branch: master
- Last Pushed: 2025-01-08T16:55:05.000Z (6 days ago)
- Last Synced: 2025-01-13T01:09:01.908Z (2 days ago)
- Topics: codec, coder, decoder, decoding, encoder, encoding, json, transformation, typescript, typescript-library
- Language: TypeScript
- Homepage:
- Size: 611 KB
- Stars: 3
- Watchers: 1
- Forks: 0
- Open Issues: 10
-
Metadata Files:
- Readme: README.md
- Contributing: CONTRIBUTING.md
- Funding: .github/FUNDING.yml
- License: LICENSE
Awesome Lists containing this project
README
# Codec – Encode & Decode for TypeScript
[![NPM Version](https://img.shields.io/npm/v/@adam-rocska/ts-codec.svg)](https://www.npmjs.com/package/@adam-rocska/ts-codec)
[![License](https://img.shields.io/npm/l/@adam-rocska/ts-codec)](https://github.com/adam-rocska/ts-codec-typescript/blob/master/LICENSE)| Aspect | Badge |
| -------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------- |
| Minified | [![Minified](https://badgen.net/bundlephobia/min/@adam-rocska/ts-codec)](https://bundlephobia.com/package/@adam-rocska/ts-codec) |
| Minified + gzip | [![Minified + gzip](https://badgen.net/bundlephobia/minzip/@adam-rocska/ts-codec)](https://bundlephobia.com/package/@adam-rocska/ts-codec) |
| Dependency Count | [![Dependency Count](https://badgen.net/bundlephobia/dependency-count/@adam-rocska/ts-codec)](https://bundlephobia.com/package/@adam-rocska/ts-codec) |
| Tree-shaking Support | [![Tree-shaking Support](https://badgen.net/bundlephobia/tree-shaking/@adam-rocska/ts-codec)](https://bundlephobia.com/package/@adam-rocska/ts-codec) |A TypeScript library that provides a strongly-typed and
user-friendly API for encoding and decoding data types.Inspired by Swift's Codable API, this library aims to offer
a straightforward functional API for basic encoding and
decoding tasks. While it's a simplified initial release,
future iterations will introduce more advanced features.For detailed API documentation, please refer to this
repository's GitHub Pages.## Example
```typescript
const testCodec = record({
firstName: string,
lastName: optional(string),
age: optional(number),
traits: array(
record({
isVenerable: boolean,
label: string,
labelAlternatives: set(string),
aquiredOn: date,
})
),
});type TestRecord = SourceType;
const source: TestRecord = {
firstName: 'Adam',
lastName: 'Rocska',
age: undefined,
traits: [],
};
const str = testCodec.encode(source);
const result = testCodec.decode(str);
expect(result).toMatchObject(source);
```