npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

txt2bas

v1.22.2

Published

Converts BASIC to Text and back again

Downloads

47

Readme

txt2bas and bas2txt - tooling for ZX Spectrum NextBASIC

This code is inspired by the .txt2bas dot command on the ZX Spectrum Next (not that I could read the asm code!).

This project provides:

  • txt2bas command line tool
  • bas2txt command line tool
  • NextBASIC validation
  • library for BASIC and text manipulation, validation and renumbering

Installation

Node and npm (included with node) are required to install and run the code.

For the command line tooling - this installs both tools:

npm install --global txt2bas

Command line usage

Command line arguments are the same for both txt2bas and bas2txt:

txt2bas -i source.txt -o result.bas # generate a 3dos basic file
bas2txt -i source.bas -o result.txt # generates plain text

Omitting -o will print to stdout.

By default the generated file is a +3DOS format unless the output or input filename ends in .tap or using the format option -f tap:

txt2bas -i source.txt -o result.tap # generates a tap file

The command line can also read from stdin though this works best on txt2bas and not recommended for bas2txt.

Note that #autostart directive is also supported.

Command line options

  • -i FILENAME - input filename
  • -o FILENAME - output filename
  • -t - (txt2bas only) test and validate the NextBASIC source
  • -C - (txt2bas only) strip comments (to reduce final size)
  • -bank - (txt2bas only) generate a BANK loadable result
  • -A #n - (txt2bas only) set autostart line to #n
  • -f 3dos|tap - set the output format
  • -H- omit the file header (either in output or in parsing input)
  • -udg - UDGs are used so encode with binary not utf8
  • -tokens - (txt2bas only) show parser tokens (for debugging)
  • -h - Show help options
  • -v - Show current version

Library API

Problematically using the library exposes a number of paired functions:

  • line2bas(String: line): Object<Uint8Array: basic, Number: lineNumber, Array: tokens, Number: length> - the byte data is contained in result.basic
  • bas2line(Uint8Array: data): String - expects to include the line number, line length and the line itself as bytes
  • file2bas(String: source, Object<String=3dos: format, filename=UNTITLED: String, validate=false: Boolean>): Uint8Array - results full byte array with correct format header, if validate is true, will throw on token errors
  • bas2file(Uint8Array: source, String=3dos: format): String - formatted BASIC text
  • formatText(String: line): String - processes the line through line2bas then bas2line to result the formatted line
  • validateTxt(String: source): Array[String] - parses each line collecting and returning any token errors
  • plus3DOSHeader and tapHeader - file headers for the appropriate data formats
  • codes an object lookup from NextBASIC numerical value to text value, ie. 0xf5 = 'PRINT'
  • statements(String: source): Array[Statement] - returns the parsed statement which include lineNumber and tokens for each line.
  • renumber(String: source, Object<start: Number, end: Number, step=10: Number, base=start: Number>) - renumbers source lines and GO TO line number targets.

Development

  • Currently the latest code uses node@21 (due to specific use of syntax)
  • To test with another project: npm link
  • For new features of language or validation changes, ensure a test is provided
  • txt2bas also support different NextOS versions, specified through parser-version

Licence