Skip to content

Commit

Permalink
Refactor TypeScript definition to CommonJS compatible export (#12)
Browse files Browse the repository at this point in the history
  • Loading branch information
BendingBender authored and sindresorhus committed Apr 1, 2019
1 parent f2216b0 commit dacf4e9
Show file tree
Hide file tree
Showing 4 changed files with 68 additions and 42 deletions.
98 changes: 61 additions & 37 deletions index.d.ts
@@ -1,45 +1,69 @@
export interface Options {
/**
* **Don't use this option unless you really have to!**
*
* Suffix appended to the project name to avoid name conflicts with native apps. Pass an empty string to disable it.
*
* @default 'nodejs'
*/
readonly suffix?: string;
declare namespace envPaths {
export interface Options {
/**
__Don't use this option unless you really have to!__
Suffix appended to the project name to avoid name conflicts with native apps. Pass an empty string to disable it.
@default 'nodejs'
*/
readonly suffix?: string;
}

export interface Paths {
/**
Directory for data files.
*/
readonly data: string;

/**
Directory for data files.
*/
readonly config: string;

/**
Directory for non-essential data files.
*/
readonly cache: string;

/**
Directory for log files.
*/
readonly log: string;

/**
Directory for temporary files.
*/
readonly temp: string;
}
}

export interface Paths {
declare const envPaths: {
/**
* Directory for data files.
*/
readonly data: string;
Get paths for storing things like data, config, cache, etc.
/**
* Directory for data files.
*/
readonly config: string;
@param name - Name of your project. Used to generate the paths.
@returns The paths to use for your project on current OS.
/**
* Directory for non-essential data files.
*/
readonly cache: string;
@example
```
import envPaths = require('env-paths');
/**
* Directory for log files.
*/
readonly log: string;
const paths = envPaths('MyApp');
/**
* Directory for temporary files.
*/
readonly temp: string;
}
paths.data;
//=> '/home/sindresorhus/.local/share/MyApp-nodejs'
paths.config
//=> '/home/sindresorhus/.config/MyApp-nodejs'
```
*/
(name: string, options?: envPaths.Options): envPaths.Paths;

// TODO: Remove this for the next major release, refactor the whole definition to:
// declare function envPaths(name: string, options?: envPaths.Options): envPaths.Paths;
// export = envPaths;
default: typeof envPaths;
};

/**
* Get paths for storing things like data, config, cache, etc.
*
* @param name - Name of your project. Used to generate the paths.
* @returns The paths to use for your project on current OS.
*/
export default function envPaths(name: string, options?: Options): Paths;
export = envPaths;
1 change: 1 addition & 0 deletions index.js
Expand Up @@ -70,4 +70,5 @@ const envPaths = (name, options) => {
};

module.exports = envPaths;
// TODO: Remove this for the next major release
module.exports.default = envPaths;
5 changes: 3 additions & 2 deletions index.test-d.ts
@@ -1,5 +1,6 @@
import {expectType} from 'tsd-check';
import envPaths, {Paths} from '.';
import {expectType} from 'tsd';
import envPaths = require('.');
import {Paths} from '.';

expectType<Paths>(envPaths('MyApp'));
expectType<Paths>(envPaths('MyApp', {suffix: 'test'}));
Expand Down
6 changes: 3 additions & 3 deletions package.json
Expand Up @@ -13,7 +13,7 @@
"node": ">=6"
},
"scripts": {
"test": "xo && ava && tsd-check"
"test": "xo && ava && tsd"
},
"files": [
"index.js",
Expand All @@ -38,8 +38,8 @@
"unix"
],
"devDependencies": {
"ava": "^1.2.1",
"tsd-check": "^0.3.0",
"ava": "^1.4.1",
"tsd": "^0.7.1",
"xo": "^0.24.0"
}
}

0 comments on commit dacf4e9

Please sign in to comment.