8000 Refactor TypeScript definition to CommonJS compatible export by BendingBender · Pull Request #5 · sindresorhus/move-file · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Refactor TypeScript definition to CommonJS compatible export #5

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

Merged
merged 1 commit into from
Apr 4, 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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
73 changes: 42 additions & 31 deletions index.d.ts
Original file line number Diff line number Diff line change
@@ -1,33 +1,44 @@
export interface Options {
/**
* Overwrite existing destination file.
*
* @default true
*/
readonly overwrite?: boolean;
declare namespace moveFile {
interface Options {
/**
Overwrite existing destination file.

@default true
*/
readonly overwrite?: boolean;
}
}

/**
* Move a file.
*
* @param source - File you want to move.
* @param destination - Where you want the file moved.
* @returns A `Promise` that resolves when the file has been moved.
*/
export default function moveFile(
source: string,
destination: string,
options?: Options
): Promise<void>;

/**
* Move a file synchronously.
*
* @param source - File you want to move.
* @param destination - Where you want the file moved.
*/
export function sync(
source: string,
destination: string,
options?: Options
): void;
declare const moveFile: {
/**
Move a file.

@param source - File you want to move.
@param destination - Where you want the file moved.
@returns A `Promise` that resolves when the file has been moved.

@example
```
import moveFile = require('move-file');

(async () => {
await moveFile('source/unicorn.png', 'destination/unicorn.png');
console.log('The file has been moved');
})();
```
*/
(source: string, destination: string, options?: moveFile.Options): Promise<void>;

/**
Move a file synchronously.

@param source - File you want to move.
@param destination - Where you want the file moved.
*/
sync(source: string, destination: string, options?: moveFile.Options): void;

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

export = moveFile;
1 change: 1 addition & 0 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ const moveFile = async (source, destination, options) => {
};

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

module.exports.sync = (source, destination, options) => {
Expand Down
10 changes: 6 additions & 4 deletions index.test-d.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,17 @@
import {expectType} from 'tsd-check';
import moveFile, {sync as moveFileSync} from '.';
import {expectType} from 'tsd';
import moveFile = require('.');

expectType<Promise<void>>(
moveFile('source/unicorn.png', 'destination/unicorn.png')
);
expectType<Promise<void>>(
moveFile('source/unicorn.png', 'destination/unicorn.png', {overwrite: false})
);
expectType<void>(moveFileSync('source/unicorn.png', 'destination/unicorn.png'));
expectType<void>(
moveFileSync('source/unicorn.png', 'destination/unicorn.png', {
moveFile.sync('source/unicorn.png', 'destination/unicorn.png')
);
expectType<void>(
moveFile.sync('source/unicorn.png', 'destination/unicorn.png', {
overwrite: false
})
);
14 changes: 7 additions & 7 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
"node": ">=8"
},
"scripts": {
"test": "xo && ava && tsd-check"
"test": "xo && ava && tsd"
},
"files": [
"index.js",
Expand All @@ -36,16 +36,16 @@
"partitions"
],
"dependencies": {
"cp-file": "^6.0.0",
"make-dir": "^2.1.0",
"cp-file": "^6.1.0",
"make-dir": "^3.0.0",
"path-exists": "^3.0.0"
},
"devDependencies": {
"ava": "^1.2.1",
"sinon": "^7.2.6",
"temp-write": "^3.3.0",
"ava": "^1.4.1",
"sinon": "^7.3.1",
"temp-write": "^3.4.0",
"tempy": "^0.2.1",
"tsd-check": "^0.3.0",
"tsd": "^0.7.2",
"xo": "^0.24.0"
}
}
0