From c8a334e298915adeabf1c779ef809baec6c3e925 Mon Sep 17 00:00:00 2001 From: Haaxor1689 Date: Sun, 26 Nov 2023 17:45:26 +0100 Subject: [PATCH] Added undefined type --- README.md | 8 ++++---- package.json | 2 +- src/types.ts | 8 ++++---- 3 files changed, 9 insertions(+), 9 deletions(-) diff --git a/README.md b/README.md index 207246b..bbc494c 100644 --- a/README.md +++ b/README.md @@ -200,16 +200,16 @@ const Level = n.enum(n.int8(), ['LOW', 'MEDIUM', 'HIGH']); Level.options; // ["LOW", "MEDIUM", "HIGH"] ``` -## Never +## Undefined -If you need a placeholder that represents 0 bytes in the binary data, you can use the never type for that: +If you need a placeholder that represents 0 bytes in the binary data, you can use the undefined type for that: ```ts import { n } from '@haaxor1689/nil'; // Declare object schema with given shape const User = n.object({ - empty: n.never(), // represents 0 bytes in buffer + empty: n.undefined(), // represents 0 bytes in buffer active: n.int32() }); @@ -218,7 +218,7 @@ type User = n.output; // Equivalent to type User = { - empty: never; + empty: undefined; active: boolean; }; ``` diff --git a/package.json b/package.json index d92e290..925df4c 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@haaxor1689/nil", - "version": "0.1.1", + "version": "0.1.2", "description": "TypeScript-first binary data parsing library with static type inference", "author": "Maroš Beťko ", "repository": { diff --git a/src/types.ts b/src/types.ts index 2b739be..87666ae 100644 --- a/src/types.ts +++ b/src/types.ts @@ -597,13 +597,13 @@ export class NilEnum< } } -export class NilNever extends NilType { +export class NilUndefined extends NilType { size() { return 0; } _decode() { - return undefined as never; + return undefined; } _encode() { @@ -636,7 +636,7 @@ const enum_ = < type: T, options: O ): NilEnum => new NilEnum({ type, options }); -const never = () => new NilNever({}); +const undefined_ = () => new NilUndefined({}); export { bool, @@ -655,5 +655,5 @@ export { object, buffer, enum_ as enum, - never + undefined_ as undefined };