Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor TypeScript definition to CommonJS compatible export #15

Merged
merged 1 commit into from
Mar 31, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
45 changes: 29 additions & 16 deletions index.d.ts
Original file line number Diff line number Diff line change
@@ -1,25 +1,38 @@
/// <reference types="node"/>

/**
* Read a chunk from a file asyncronously.
*
* @param filePath - The path to the file.
* @param startPosition - Position to start reading.
* @param length - Number of bytes to read.
* @returns The read chunk.
*/
declare const readChunk: {
/**
Read a chunk from a file asyncronously.

@param filePath - The path to the file.
@param startPosition - Position to start reading.
@param length - Number of bytes to read.
@returns The read chunk.

@example
```
import readChunk = require('read-chunk');

// foo.txt => hello

readChunk.sync('foo.txt', 1, 3);
//=> 'ell'
```
*/
(filePath: string, startPosition: number, length: number): Promise<Buffer>;

/**
* Read a chunk from a file synchronously.
*
* @param filePath - The path to the file.
* @param startPosition - Position to start reading.
* @param length - Number of bytes to read.
* @returns The read chunk.
*/
Read a chunk from a file synchronously.

@param filePath - The path to the file.
@param startPosition - Position to start reading.
@param length - Number of bytes to read.
@returns The read chunk.
*/
sync(filePath: string, startPosition: number, length: number): Buffer;

// TODO: Remove this for the next major release
default: typeof readChunk;
};

export default readChunk;
export = readChunk;
1 change: 1 addition & 0 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ const readChunk = (filePath, startPosition, length) => {
};

module.exports = readChunk;
// TODO: Remove this for the next major release
module.exports.default = readChunk;

module.exports.sync = (filePath, startPosition, length) => {
Expand Down
4 changes: 2 additions & 2 deletions index.test-d.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import {expectType} from 'tsd-check';
import readChunk from '.';
import {expectType} from 'tsd';
import readChunk = require('.');

expectType<Promise<Buffer>>(readChunk('foo.txt', 1, 3));
expectType<Buffer>(readChunk.sync('foo.txt', 1, 3));
12 changes: 6 additions & 6 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
"node": ">=6"
},
"scripts": {
"test": "xo && ava && tsd-check"
"test": "xo && ava && tsd"
},
"files": [
"index.js",
Expand All @@ -35,13 +35,13 @@
],
"dependencies": {
"pify": "^4.0.1",
"with-open-file": "^0.1.5"
"with-open-file": "^0.1.6"
},
"devDependencies": {
"@types/node": "^11.10.4",
"ava": "^1.3.1",
"sinon": "^7.2.7",
"tsd-check": "^0.3.0",
"@types/node": "^11.12.2",
"ava": "^1.4.1",
"sinon": "^7.3.1",
"tsd": "^0.7.1",
"xo": "^0.24.0"
}
}