mirror of
https://github.com/FlipsideCrypto/DefinitelyTyped.git
synced 2026-02-06 10:56:53 +00:00
[sparse-bitfield] Add types
This commit is contained in:
parent
9272fc1637
commit
bc5ffa8aa7
74
types/sparse-bitfield/index.d.ts
vendored
Normal file
74
types/sparse-bitfield/index.d.ts
vendored
Normal file
@ -0,0 +1,74 @@
|
||||
// Type definitions for sparse-bitfield 3.0
|
||||
// Project: https://github.com/mafintosh/sparse-bitfield
|
||||
// Definitions by: BendingBender <https://github.com/BendingBender>
|
||||
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
|
||||
|
||||
/// <reference types="node" />
|
||||
|
||||
import { PagerInstance } from 'memory-pager';
|
||||
|
||||
export = BitField;
|
||||
|
||||
declare const BitField: BitField;
|
||||
|
||||
interface BitField {
|
||||
(bufferOrOptions?: BitField.Options | Buffer): BitField.BitFieldInstance;
|
||||
new (bufferOrOptions?: BitField.Options | Buffer): BitField.BitFieldInstance;
|
||||
}
|
||||
|
||||
declare namespace BitField {
|
||||
interface Options {
|
||||
/**
|
||||
* @default 0
|
||||
*/
|
||||
pageOffset?: number;
|
||||
/**
|
||||
* How big should the partial buffers be.
|
||||
* @default 1024
|
||||
*/
|
||||
pageSize?: number;
|
||||
/**
|
||||
* A pre-configured Pager instance.
|
||||
*/
|
||||
pages?: PagerInstance;
|
||||
/**
|
||||
* An existing bitfield.
|
||||
*/
|
||||
buffer?: Buffer;
|
||||
/**
|
||||
* Track when pages are being updated in the pager.
|
||||
* @default false
|
||||
*/
|
||||
trackUpdates?: boolean;
|
||||
}
|
||||
|
||||
interface BitFieldInstance {
|
||||
/**
|
||||
* A `memory-pager` instance that is managing the underlying memory.
|
||||
* If you set `trackUpdates` to `true` in the constructor you can use `.lastUpdate()` on this instance
|
||||
* to get the last updated memory page.
|
||||
*/
|
||||
readonly pages: PagerInstance;
|
||||
|
||||
/**
|
||||
* Get the value of a bit.
|
||||
*/
|
||||
get(index: number): boolean;
|
||||
/**
|
||||
* Get the value of a byte.
|
||||
*/
|
||||
getByte(index: number): number;
|
||||
/**
|
||||
* Set a bit to true or false.
|
||||
*/
|
||||
set(index: number, value: boolean): boolean;
|
||||
/**
|
||||
* Set a byte to a new value.
|
||||
*/
|
||||
setByte(index: number, byte: number): boolean;
|
||||
/**
|
||||
* Get a single buffer representing the entire bitfield.
|
||||
*/
|
||||
toBuffer(): Buffer;
|
||||
}
|
||||
}
|
||||
24
types/sparse-bitfield/sparse-bitfield-tests.ts
Normal file
24
types/sparse-bitfield/sparse-bitfield-tests.ts
Normal file
@ -0,0 +1,24 @@
|
||||
import BitField = require('sparse-bitfield');
|
||||
import Pager = require('memory-pager');
|
||||
|
||||
const bits = BitField();
|
||||
BitField(new Buffer(1));
|
||||
BitField({ pageOffset: 1 });
|
||||
BitField({ pageSize: 1024 });
|
||||
BitField({ pages: new Pager() });
|
||||
BitField({ buffer: new Buffer(1) });
|
||||
BitField({ trackUpdates: true });
|
||||
new BitField();
|
||||
new BitField(new Buffer(1));
|
||||
new BitField({ pageOffset: 1 });
|
||||
new BitField({ pageSize: 1024 });
|
||||
new BitField({ pages: new Pager() });
|
||||
new BitField({ buffer: new Buffer(1) });
|
||||
new BitField({ trackUpdates: true });
|
||||
|
||||
bits.get(0); // $ExpectType boolean
|
||||
bits.getByte(0); // $ExpectType number
|
||||
bits.set(0, true); // $ExpectType boolean
|
||||
bits.setByte(0, 1); // $ExpectType boolean
|
||||
bits.toBuffer(); // $ExpectType Buffer
|
||||
bits.pages; // $ExpectType PagerInstance
|
||||
23
types/sparse-bitfield/tsconfig.json
Normal file
23
types/sparse-bitfield/tsconfig.json
Normal 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",
|
||||
"sparse-bitfield-tests.ts"
|
||||
]
|
||||
}
|
||||
1
types/sparse-bitfield/tslint.json
Normal file
1
types/sparse-bitfield/tslint.json
Normal file
@ -0,0 +1 @@
|
||||
{ "extends": "dtslint/dt.json" }
|
||||
Loading…
Reference in New Issue
Block a user