Skip to content

Commit

Permalink
chore: add index.d.ts
Browse files Browse the repository at this point in the history
  • Loading branch information
XadillaX committed Jul 21, 2020
1 parent 86566ea commit f6f18df
Show file tree
Hide file tree
Showing 17 changed files with 267 additions and 1 deletion.
15 changes: 15 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# http://editorconfig.org
root = true

[*]
indent_style = space
indent_size = 4
charset = utf-8
trim_trailing_whitespace = true
insert_final_newline = true

[*.ts]
indent_size = 2

[*.md]
trim_trailing_whitespace = false
51 changes: 51 additions & 0 deletions index.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
export * from './tags.d';

type Callback<T> = (err: undefined|Error, ret?: T) => void;

interface TagsType {
TAGByte: new () => TAGByte,
TAGShort: new () => TAGShort,
TAGInt: new () => TAGInt,
TAGLong: new () => TAGLong,
TAGFloat: new () => TAGFloat,
TAGDouble: new () => TAGDouble,
TAGByteArray: new () => TAGByteArray,
TAGString: new () => TAGString,
TAGList: new () => TAGList,
TAGCompound: new () => TAGCompound,
TAGIntArray: new () => TAGIntArray,

"1": new () => AGByte,
"2": new () => AGShort,
"3": new () => AGInt,
"4": new () => AGLong,
"5": new () => AGFloat,
"6": new () => AGDouble,
"7": new () => AGByteArray,
"8": new () => AGString,
"9": new () => AGList,
"10": new () =>TAGCompound,
"11": new () =>TAGIntArray,

TAG_Byte: number,
TAG_Short: number,
TAG_Int: number,
TAG_Long: number,
TAG_Float: number,
TAG_Double: number,
TAG_Byte_Array: number,
TAG_String: number,
TAG_List: number,
TAG_Compound: number,
TAG_Int_Array: number,
}

export = class NBT {
loadFromBuffer(buff: Buffer, callback: Callback<void>): void;
loadFromZlibCompressedBuffer(buff: Buffer, callback: Callback<void>): void;

writeToCompressedBuffer(callback: Callback<void>, method?: string): void;
writeToBuffer(): Buffer;

static Tags: TagsType;
}
28 changes: 28 additions & 0 deletions lib/base_tag.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
export type JSONObject = { [key: string]: any; };

export = class BaseTag {
readFromBuffer(buff: Buffer, offset: number): number;
writeBuffer(buff: Buffer, offset: number): number;
calcBufferLength(): number;

getType(): string;
getName(): string;
getId(): string;
getValue(): any;
setValue(value: any): void;

getNextTag(buff: Buffer, offset: number): { length: number, tag: BaseTag };

count(): number;

selectAt(idx: number): BaseTag|undefined;
getAt(idx: number): BaseTag|undefined;
select(name: string): BaseTag|undefined;
get(name: string): BaseTag|undefined;

getTypeId(): number;

inspect(): string;
toString(): string;
toJSON(): JSONObject;
}
51 changes: 51 additions & 0 deletions lib/tags.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
import * as TAGByte from './tags/byte.d';
import * as TAGByteArray from './tags/byte_array.d';
import * as TAGCompound from './tags/compound.d';
import * as TAGDouble from './tags/double.d';
import * as TAGFloat from './tags/float.d';
import * as TAGInt from './tags/int.d';
import * as TAGIntArray from './tags/int_array.d';
import * as TAGList from './tags/list.d';
import * as TAGLong from './tags/long.d';
import * as TAGShort from './tags/short.d';
import * as TAGString from './tags/string.d';

export = {
TAGByte: TAGByte,
TAGShort: TAGShort,
TAGInt: TAGInt,
TAGLong: TAGLong,
TAGFloat: TAGFloat,
TAGDouble: TAGDouble,
TAGByteArray: TAGByteArray,
TAGString: TAGString,
TAGList: TAGList,
TAGCompound: TAGCompound,
TAGIntArray: TAGIntArray,

// Class id -> Class
"1": TAGByte,
"2": TAGShort,
"3": TAGInt,
"4": TAGLong,
"5": TAGFloat,
"6": TAGDouble,
"7": TAGByteArray,
"8": TAGString,
"9": TAGList,
"10": TAGCompound,
"11": TAGIntArray,

// Tag name -> Class id
TAG_Byte: 1,
TAG_Short: 2,
TAG_Int: 3,
TAG_Long: 4,
TAG_Float: 5,
TAG_Double: 6,
TAG_Byte_Array: 7,
TAG_String: 8,
TAG_List: 9,
TAG_Compound: 10,
TAG_Int_Array: 11,
};
8 changes: 8 additions & 0 deletions lib/tags/byte.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import * as BaseTag from '../base_tag.d';

export = class TAGByte extends BaseTag {
getType(): 'TAG_Byte';

getValue(): number;
setValue(value: number): void;
}
14 changes: 14 additions & 0 deletions lib/tags/byte_array.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import BaseTag from '../base_tag.d';

export default class TAGByteArray extends BaseTag {
getType(): 'TAG_Byte_Array';

getValue(): number[];
setValue(value: number[]): void;

unshift(value: number): number;
shift(): number;
push(value: number): number;
pop(): number;
insert(value: number, pos: number): void;
}
14 changes: 14 additions & 0 deletions lib/tags/compound.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import * as BaseTag from '../base_tag.d';

export = class TAGCompound extends BaseTag {
getType(): 'TAG_Compound';

getValue(): { [key: string]: BaseTag; };
setValue(value: { [key: string]: BaseTag; }): void;

setByName(name: string, value: BaseTag, replace?: boolean): void;
deleteByName(name: string): void;
clean(): void;

getNames(): string[];
}
8 changes: 8 additions & 0 deletions lib/tags/double.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import * as BaseTag from '../base_tag.d';

export = class TAGDouble extends BaseTag {
getType(): 'TAG_Double';

getValue(): number;
setValue(value: number): void;
}
8 changes: 8 additions & 0 deletions lib/tags/float.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import * as BaseTag from '../base_tag.d';

export = class TAGFloat extends BaseTag {
getType(): 'TAG_Float';

getValue(): number;
setValue(value: number): void;
}
8 changes: 8 additions & 0 deletions lib/tags/int.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import * as BaseTag from '../base_tag.d';

export = class TAGInt extends BaseTag {
getType(): 'TAG_Int';

getValue(): number;
setValue(value: number): void;
}
14 changes: 14 additions & 0 deletions lib/tags/int_array.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import * as BaseTag from '../base_tag.d';

export = class TAGIntArray extends BaseTag {
getType(): 'TAG_Int_Array';

getValue(): number[];
setValue(value: number[]): void;

unshift(value: number): number;
shift(): number;
push(value: number): number;
pop(): number;
insert(value: number, pos: number): void;
}
18 changes: 18 additions & 0 deletions lib/tags/list.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import * as BaseTag from '../base_tag.d';

export = class TAGList extends BaseTag {
childType: 'TAG_End';

getType(): 'TAG_List';

getValue(): BaseTag[];
setValue(value: BaseTag[]): void;

unshift(value: BaseTag): number;
shift(): BaseTag;
push(value: BaseTag): number;
pop(): BaseTag;
insert(value: BaseTag, pos: number): void;

clean(): void;
}
10 changes: 10 additions & 0 deletions lib/tags/long.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import Long from 'long';

import * as BaseTag from '../base_tag.d';

export = class TAGLong extends BaseTag {
getType(): 'TAG_Long';

getValue(): Long;
setValue(value: Long): void;
}
8 changes: 8 additions & 0 deletions lib/tags/short.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import * as BaseTag from '../base_tag.d';

export = class TAGShort extends BaseTag {
getType(): 'TAG_Short';

getValue(): number;
setValue(value: number): void;
}
8 changes: 8 additions & 0 deletions lib/tags/string.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import * as BaseTag from '../base_tag.d';

export = class TAGString extends BaseTag {
getType(): 'TAG_String';

getValue(): string;
setValue(value: string): void;
}
2 changes: 2 additions & 0 deletions nbt.js
Original file line number Diff line number Diff line change
Expand Up @@ -240,4 +240,6 @@ NBT.prototype.toJSON = function() {
return res;
};

NBT.Tags = require('./lib/tags');

module.exports = NBT;
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
{
"name": "mcnbt",
"version": "0.0.7",
"version": "1.0.0",
"description": "Yet another Minecraft NBT format file / buffer parser for Node.js.",
"main": "nbt.js",
"types": "index.d.ts",
"scripts": {
"test": "make test"
},
Expand Down

0 comments on commit f6f18df

Please sign in to comment.