adds typings for the 'level-codec' package

This commit is contained in:
Daniel Byrne 2018-08-27 09:42:15 -07:00
parent cd1db00d94
commit c8a0139cb1
4 changed files with 68 additions and 0 deletions

32
types/level-codec/index.d.ts vendored Normal file
View File

@ -0,0 +1,32 @@
// Type definitions for level-codec 9.0
// Project: https://github.com/Level/codec
// Definitions by: Daniel Byrne <https://github.com/danwbyrne>
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
export interface CodecEncoder {
encode: (val: any) => any;
decode: (val: any) => any;
buffer: boolean;
type: string;
}
export interface CodecOptions {
keyEncoding?: string | CodecEncoder;
valueEncoding?: string | CodecEncoder;
}
export interface Codec {
encodeKey(key: any, opts?: CodecOptions, batchOpts?: CodecOptions): any;
encodeValue(value: any, opts?: CodecOptions, batchOpts?: CodecOptions): any;
decodeKey(key: any, opts?: CodecOptions): any;
decodeValue(value: any, opts?: CodecOptions): any;
encodeBatch(ops: any, opts?: CodecOptions): any;
encodeLtgt(ltgt: any): any;
createStreamDecoder(opts: CodecOptions): any;
keyAsBuffer(opts?: CodecOptions): any;
valueAsBuffer(opts?: CodecOptions): any;
}
export interface CodecConstructor {
new (options?: CodecOptions): Codec;
(options?: CodecOptions): Codec;
}
export const Codec: CodecConstructor;

View File

@ -0,0 +1,12 @@
import { Codec } from "level-codec";
const test = (codec: Codec) => {
return codec.keyAsBuffer();
};
test(new Codec({ keyEncoding: "hex" }));
test(new Codec());
// new not needed
test(Codec({ keyEncoding: "hex" }));
test(Codec());

View File

@ -0,0 +1,23 @@
{
"compilerOptions": {
"module": "commonjs",
"lib": [
"es6"
],
"noImplicitAny": true,
"noImplicitThis": true,
"strictNullChecks": true,
"strictFunctionTypes": true,
"baseUrl": "../",
"typeRoots": [
"../"
],
"types": [],
"noEmit": true,
"forceConsistentCasingInFileNames": true
},
"files": [
"index.d.ts",
"level-codec-tests.ts"
]
}

View File

@ -0,0 +1 @@
{ "extends": "dtslint/dt.json" }