Merge pull request #31672 from BendingBender/parse-filepath

[parse-filepath] Add types
This commit is contained in:
Wesley Wigham
2018-12-25 13:07:41 -08:00
committed by GitHub
4 changed files with 109 additions and 0 deletions
+69
View File
@@ -0,0 +1,69 @@
// Type definitions for parse-filepath 1.0
// Project: https://github.com/jonschlinkert/parse-filepath
// Definitions by: BendingBender <https://github.com/BendingBender>
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
export = parseFilepath;
/**
* Pollyfill for node.js `path.parse()`, parses a filepath into an object.
*
* @param filepath
*/
declare function parseFilepath(filepath: string): parseFilepath.ParsedPath;
declare namespace parseFilepath {
interface ParsedPath {
/**
* The root of the path such as `'/'` or `'c:\'`
*/
root: string;
/**
* The full directory path such as `'/home/user/dir'` or `'c:\path\dir'`
*/
dir: string;
/**
* The file name including extension (if any) such as `'index.html'`
*/
base: string;
/**
* The file extension (if any) such as `'.html'`
*/
ext: string;
/**
* The file name without extension (if any) such as `'index'`
*/
name: string;
/**
* alias for `ext`
*/
extname: string;
/**
* alias for `base`
*/
basename: string;
/**
* alias for `dir`
*/
dirname: string;
/**
* alias for `name`
*/
stem: string;
/**
* the original filepath
*/
path: string;
/**
* fully resolved, absolute filepath
*/
absolute: string;
/**
* `true` if the given path is absolute
*/
isAbsolute: boolean;
}
}
@@ -0,0 +1,16 @@
import parsePath = require('parse-filepath');
const parsedPath = parsePath('foo/bar/baz/index.js');
parsedPath.absolute; // $ExpectType string
parsedPath.base; // $ExpectType string
parsedPath.basename; // $ExpectType string
parsedPath.dir; // $ExpectType string
parsedPath.dirname; // $ExpectType string
parsedPath.ext; // $ExpectType string
parsedPath.extname; // $ExpectType string
parsedPath.isAbsolute; // $ExpectType boolean
parsedPath.name; // $ExpectType string
parsedPath.path; // $ExpectType string
parsedPath.root; // $ExpectType string
parsedPath.stem; // $ExpectType string
+23
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",
"parse-filepath-tests.ts"
]
}
+1
View File
@@ -0,0 +1 @@
{ "extends": "dtslint/dt.json" }