From 62a51906a208fea0ad6e02899c25ad751fe9c1c7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Elias=20Sj=C3=B6green?= Date: Mon, 27 Feb 2023 19:31:54 +0100 Subject: [PATCH] refactor: make the endianess util constant (#7) --- .github/workflows/depsbot.yml | 21 --------------------- LICENSE | 2 +- README.md | 10 +++++----- types/mod.ts | 2 ++ types/primitive/f32.ts | 2 +- types/primitive/f64.ts | 2 +- types/primitive/i16.ts | 2 +- types/primitive/i32.ts | 2 +- types/primitive/i64.ts | 2 +- types/primitive/u16.ts | 2 +- types/primitive/u32.ts | 2 +- types/primitive/u64.ts | 2 +- util.ts | 9 --------- utils.ts | 7 +++++++ 14 files changed, 23 insertions(+), 44 deletions(-) delete mode 100644 .github/workflows/depsbot.yml delete mode 100644 util.ts create mode 100644 utils.ts diff --git a/.github/workflows/depsbot.yml b/.github/workflows/depsbot.yml deleted file mode 100644 index 705242d..0000000 --- a/.github/workflows/depsbot.yml +++ /dev/null @@ -1,21 +0,0 @@ -name: depsbot - -on: - push: - branches: [main] - pull_request: - branches: [main] - schedule: - - cron: "0 0 */2 * *" - -jobs: - run: - runs-on: ubuntu-latest - steps: - - name: Checkout Repository - uses: actions/checkout@v2 - - - name: Run depsbot - uses: denosaurs/depsbot@master - with: - github_token: ${{ secrets.GITHUB_TOKEN }} diff --git a/LICENSE b/LICENSE index e2af421..53a7bd2 100644 --- a/LICENSE +++ b/LICENSE @@ -1,6 +1,6 @@ MIT License -Copyright (c) 2021-2022 the denosaurs team +Copyright (c) 2021-2023 the denosaurs team Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal diff --git a/README.md b/README.md index edee3ae..592647e 100644 --- a/README.md +++ b/README.md @@ -1,12 +1,12 @@ # byte_type [![Tags](https://img.shields.io/github/release/denosaurs/byte_type)](https://github.com/denosaurs/byte_type/releases) -[![CI Status](https://img.shields.io/github/workflow/status/denosaurs/byte_type/check)](https://github.com/denosaurs/byte_type/actions) -[![Dependencies](https://img.shields.io/github/workflow/status/denosaurs/byte_type/depsbot?label=dependencies)](https://github.com/denosaurs/depsbot) +[![Checks](https://img.shields.io/github/actions/workflow/status/denosaurs/byte_type/checks.yml?branch=main)](https://github.com/denosaurs/byte_type/actions) [![License](https://img.shields.io/github/license/denosaurs/byte_type)](https://github.com/denosaurs/byte_type/blob/master/LICENSE) -`byte_type` is a small helper module for working with different raw types -represented as a bunch of bytes. +`byte_type` is a small helper module for efficiently working with different raw +types represented as a bunch of bytes. Now with performance being close to +native js performance and ergonomic interfaces! ## Usage @@ -33,4 +33,4 @@ Pull request, issues and feedback are very welcome. Code style is formatted with ### Licence -Copyright 2021, the denosaurs team. All rights reserved. MIT license. +Copyright 2021-2023, the denosaurs team. All rights reserved. MIT license. diff --git a/types/mod.ts b/types/mod.ts index 279b261..d3bd892 100644 --- a/types/mod.ts +++ b/types/mod.ts @@ -1,6 +1,8 @@ export * from "./array/mod.ts"; export * from "./bitflags/mod.ts"; +export * from "./misc/mod.ts"; export * from "./primitive/mod.ts"; export * from "./string/mod.ts"; export * from "./struct/mod.ts"; export * from "./tuple/mod.ts"; +export * from "./types.ts"; diff --git a/types/primitive/f32.ts b/types/primitive/f32.ts index 1a9f5c3..398a9df 100644 --- a/types/primitive/f32.ts +++ b/types/primitive/f32.ts @@ -6,7 +6,7 @@ export class F32 implements AlignedType { byteAlign = 4; endian; - constructor(endian: boolean = endianess()) { + constructor(endian: boolean = endianess) { this.endian = endian; } diff --git a/types/primitive/f64.ts b/types/primitive/f64.ts index f141c7b..f692c37 100644 --- a/types/primitive/f64.ts +++ b/types/primitive/f64.ts @@ -6,7 +6,7 @@ export class F64 implements AlignedType { byteAlign = 8; endian; - constructor(endian: boolean = endianess()) { + constructor(endian: boolean = endianess) { this.endian = endian; } diff --git a/types/primitive/i16.ts b/types/primitive/i16.ts index 8c64ddb..c7dff67 100644 --- a/types/primitive/i16.ts +++ b/types/primitive/i16.ts @@ -6,7 +6,7 @@ export class I16 implements AlignedType { byteAlign = 2; endian; - constructor(endian: boolean = endianess()) { + constructor(endian: boolean = endianess) { this.endian = endian; } diff --git a/types/primitive/i32.ts b/types/primitive/i32.ts index 4e2b834..6cd6781 100644 --- a/types/primitive/i32.ts +++ b/types/primitive/i32.ts @@ -6,7 +6,7 @@ export class I32 implements AlignedType { byteAlign = 4; endian; - constructor(endian: boolean = endianess()) { + constructor(endian: boolean = endianess) { this.endian = endian; } diff --git a/types/primitive/i64.ts b/types/primitive/i64.ts index cc2aab5..a37cbfc 100644 --- a/types/primitive/i64.ts +++ b/types/primitive/i64.ts @@ -6,7 +6,7 @@ export class I64 implements AlignedType { byteAlign = 8; endian; - constructor(endian: boolean = endianess()) { + constructor(endian: boolean = endianess) { this.endian = endian; } diff --git a/types/primitive/u16.ts b/types/primitive/u16.ts index 4ada47b..fd03ef0 100644 --- a/types/primitive/u16.ts +++ b/types/primitive/u16.ts @@ -6,7 +6,7 @@ export class U16 implements AlignedType { byteAlign = 2; endian; - constructor(endian: boolean = endianess()) { + constructor(endian: boolean = endianess) { this.endian = endian; } diff --git a/types/primitive/u32.ts b/types/primitive/u32.ts index bc432a4..a6853b2 100644 --- a/types/primitive/u32.ts +++ b/types/primitive/u32.ts @@ -6,7 +6,7 @@ export class U32 implements AlignedType { byteAlign = 4; endian; - constructor(endian: boolean = endianess()) { + constructor(endian: boolean = endianess) { this.endian = endian; } diff --git a/types/primitive/u64.ts b/types/primitive/u64.ts index 2d01a6c..360e2e7 100644 --- a/types/primitive/u64.ts +++ b/types/primitive/u64.ts @@ -6,7 +6,7 @@ export class U64 implements AlignedType { byteAlign = 8; endian; - constructor(endian: boolean = endianess()) { + constructor(endian: boolean = endianess) { this.endian = endian; } diff --git a/util.ts b/util.ts deleted file mode 100644 index e1eb388..0000000 --- a/util.ts +++ /dev/null @@ -1,9 +0,0 @@ -/** - * Checks the endianess of your machine, returns true - * if little endian and false if big endian. - */ -export function endianess(): boolean { - const buffer = new ArrayBuffer(2); - new DataView(buffer).setInt16(0, 256, true); - return new Int16Array(buffer)[0] === 256; -} diff --git a/utils.ts b/utils.ts new file mode 100644 index 0000000..308919c --- /dev/null +++ b/utils.ts @@ -0,0 +1,7 @@ +const buffer = new ArrayBuffer(2); +new DataView(buffer).setInt16(0, 256, true); + +/** + * The endianess of your machine, true if little endian and false if big endian. + */ +export const endianess = new Int16Array(buffer)[0] === 256;