ts-py-struct
TypeScript icon, indicating that this package has built-in type declarations

1.2.3 • Public • Published

CI npm version Coverage Bugs Code Smells Duplicated Lines (%) Maintainability Rating Reliability Rating Security Rating Technical Debt Vulnerabilities Lines of Code Codacy Badge

ts-py-struct

port python's struct to typescript.

Feature

Requirements

  • Typescript 4.1.x or later

Usage

import { pack, unpack } from 'ts-py-struct'
//const packed: Uint8Array = pack('<hHl',7777, 65534) // Compile Error: Expected 4 arguments, but got 3.
const packed: Uint8Array = pack('<hHl', 7777, 65534, 3123213)
//const unpacked: [number,  number] = unpack('<hHl',packed) // Compile Error: Type '[number, number, number]' is not assignable to type '[number]'.  Source has 3 element(s) but target allows only 1.ts(2322)
const unpacked: [number, number, number] = unpack('<hHl', packed)

class interface

import { Struct } from 'ts-py-struct'
const s = new Struct('2c')
// const packed = s.pack('A', 22) // Compile Error:  Argument of type 'number' is not assignable to parameter of type 'string'.ts(2345)
const packed = s.pack('A', '0')
const unpacked = s.unpack(packed) // unpacked type is [string, string]

Readme

Keywords

Package Sidebar

Install

npm i ts-py-struct

Weekly Downloads

1

Version

1.2.3

License

ISC

Unpacked Size

24.7 kB

Total Files

13

Last publish

Collaborators

  • satoren