@mc-wiki/snbt
Version:
A library for parsing SNBT (Stringified NBT) format
97 lines (94 loc) • 3.55 kB
TypeScript
declare class IntegerValue {
value: bigint;
signed: boolean;
type: 'byte' | 'short' | 'int' | 'long' | null;
private resolved;
constructor(value: bigint, signed: boolean, type: 'byte' | 'short' | 'int' | 'long' | null);
_resolve(outType?: 'byte' | 'short' | 'int' | 'long', error?: base.ParsingError): IntegerValue;
}
declare class FloatValue {
value: number;
type: 'float' | 'double';
}
declare class IntegerList {
values: bigint[];
type: 'byte' | 'short' | 'int' | 'long';
}
declare function createInteger(num: bigint | number, signed?: boolean, type?: 'byte' | 'short' | 'int' | 'long'): IntegerValue;
declare function createFloat(num: number, type?: 'float' | 'double'): FloatValue;
type SNBTValue = IntegerValue | FloatValue | IntegerList | string | boolean | {
[p: string]: SNBTValue;
} | Array<SNBTValue>;
declare namespace base {
type ParsingError = (s: string, where?: any) => void;
enum IntegerTypeSuffix {
BYTE = "byte",
SHORT = "short",
INTEGER = "int",
LONG = "long"
}
enum FloatTypeSuffix {
FLOAT = "float",
DOUBLE = "double"
}
enum SignedPrefix {
SIGNED = "signed",
UNSIGNED = "unsigned"
}
enum Sign {
PLUS = "+",
MINUS = "-"
}
enum Base {
HEX = 16,
DEC = 10,
BIN = 2
}
interface IntegerLiteral {
sign: Sign | string;
suffix: {
signed: SignedPrefix | null;
type: IntegerTypeSuffix | null;
};
base: number;
value: string;
}
interface FloatLiteral {
sign: Sign | string;
integer: string;
frac: string;
exp?: {
sign: Sign | string;
value: string;
};
suf: FloatTypeSuffix | null;
}
function getBitsForInteger(suffix: IntegerTypeSuffix): 8n | 16n | 32n | 64n;
namespace BuiltinOperation {
function register(name: string, fn: (error: ParsingError, ...args: SNBTValue[]) => SNBTValue, length: number): void;
function get(name: string, length: number): (error: ParsingError, ...args: SNBTValue[]) => SNBTValue;
}
function convertToIntTypeSuffix(suffix: string): IntegerTypeSuffix;
function convertToFloatTypeSuffix(suffix: string): FloatTypeSuffix;
function checkNum(num: string, error: ParsingError): string;
function convertNum(num: IntegerLiteral, error: ParsingError): IntegerValue;
function convertFloat(num: FloatLiteral, error: ParsingError): FloatValue;
function convertHexString(str: string, error: ParsingError): string;
function convertUnicodeNameString(str: string, error: ParsingError): string;
function convertUnquotedOrBuiltin(str: string, argv: SNBTValue[] | null, error: ParsingError): string | boolean | IntegerValue | FloatValue | IntegerList | {
[p: string]: SNBTValue;
} | SNBTValue[];
function convertIntList(prefix: string, list: IntegerValue[], error: ParsingError): {
type: IntegerTypeSuffix;
values: bigint[];
};
}
type HighlightToken = {
start: number;
end: number;
type: 'number' | 'numberSuffix' | 'string' | 'key' | 'operation' | 'arrayType';
};
declare const parse: (input: string, options?: Record<string, any>) => SNBTValue;
declare const highlights: (input: string, options?: Record<string, any>) => HighlightToken[];
export { FloatValue, IntegerList, IntegerValue, createFloat, createInteger, highlights, parse };
export type { HighlightToken, SNBTValue };