nbt-parser
Version:
Minecraft NBT (NamedBinary Tags) parser for Node.js
122 lines (121 loc) • 4.25 kB
TypeScript
import { Edition, SNBTError } from "./types";
export declare function concatUint8Arrays(...arrays: Uint8Array[]): Uint8Array;
export declare function isLittleEndian(edition: Edition): edition is "bedrock";
export declare function uuidToIntArray(uuid: string): number[];
export declare function intArrayToUuid(intArray: number[]): string;
export declare class SNBTStringReader {
readonly string: string;
private _index;
/**
* Creates a new StringReader
* @param string The string to read
*/
constructor(string: string);
/**
* Gets pointer position
* @returns pointer position
*/
get index(): number;
/**
* Sets pointer position
* @param index position
* @throws Error if position is out of bounds
*/
set index(index: number);
/**
* Gets the length of the string
*
* Equals to <code>StringReader.string.length</code>
* @returns the length of the string
*/
get length(): number;
/**
* Reads the character at the specified index
* @param index the position of the character to get, defaults to the next character
* @throws Error if position is out of bounds
* @returns the character at the specified index
*/
charAt(index: number): string;
/**
* Reads the next character
*
* Equals to <code>StringReader.charAt(StringReader.index + 1)</code>
* @throws Error if the next position is out of bounds
* @returns the character at the next position
*/
peek(): string;
/**
* Reads all characters starting from the current position
*
* Does not read the current character
* @returns all characters starting from the current position
*/
peekNext(): string;
/**
* Reads the current character
*
* Equals to <code>StringReader.charAt(StringReader.index)</code>
* @returns current character
*/
curr(): string;
/**
* Reads the previous character
*
* Equals to <code>StringReader.charAt(StringReader.index - 1)</code>
* @throws Error if the previous position is out of bounds
*/
peekPrev(): string;
/**
* Moves the pointer to the previous character and returns it
* @throws Error if the previous position is out of bounds
*/
prev(): string;
/**
* Moves the pointer to the next character and returns it
* @throws Error if the next position is out of bounds
*/
next(): string;
/**
* Reads all characters until the specified test function returns false
*
* Does not read the current character
*
* Positions the pointer to the last read character
* @param prediction the test function
* @returns the read characters
*/
nextUnless(prediction: (nextChar: string, reader: SNBTStringReader) => boolean): string;
/**
* Moves the pointer to the specified position and returns it
* @param pos the position to move to
* @throws Error if position is out of bounds
*/
moveTo(pos: number): string;
/**
* Checks if the current position is at the end of the string
* @returns true if the current position is at the end of the string, false otherwise
*/
eof(): boolean;
/**
* Skips all whitespace characters starting from the current position
* and position the pointer before the first non-whitespace character
*/
skipWhitespace(): void;
/**
* Expects the characters at the current position
* @param chars the characters to expect
* @throws Error if the position is out of bounds
* @throws Error if the character is not one of the specified characters
* @returns the expected character
*/
expect<T extends string[]>(...chars: T): typeof chars[number];
/**
* Expects the characters at the next position and moves the pointer to the next position
* @param chars the characters to expect
* @throws Error if the position is out of bounds
* @throws Error if the character is not one of the specified characters
* @returns the expected character
*/
expectNext<T extends string[]>(...chars: T): typeof chars[number];
newSNBTError(message: string): SNBTError;
}