Revamping to matrix style
This commit is contained in:
21
node_modules/typesafe-path/LICENSE
generated
vendored
Normal file
21
node_modules/typesafe-path/LICENSE
generated
vendored
Normal file
@@ -0,0 +1,21 @@
|
||||
MIT License
|
||||
|
||||
Copyright (c) 2022-present Johnson Chu
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
||||
31
node_modules/typesafe-path/README.md
generated
vendored
Normal file
31
node_modules/typesafe-path/README.md
generated
vendored
Normal file
@@ -0,0 +1,31 @@
|
||||
# TypeSafe Path
|
||||
|
||||
This library is aim to explicitly annotate path format of the code, and throwing error when passing incorrect format paths.
|
||||
|
||||
The advantage is that we can avoid using `upath` to convert all paths to unix path, and ensure current code logic always correctly know the path format that should be processed.
|
||||
|
||||
Please note that you should only use it in your modules that are coupled to the filesystem.
|
||||
|
||||
## Usage
|
||||
|
||||
```ts
|
||||
import * as path from 'typesafe-path';
|
||||
|
||||
/**
|
||||
* win32: __dirname is 'c:\\foo\\bar.js'
|
||||
* posix: __dirname is '/foo/bar.js'
|
||||
*/
|
||||
const osPath = __dirname as path.OsPath;
|
||||
const win32Path = '..\\aaa\\bbb' as path.Win32Path;
|
||||
|
||||
/**
|
||||
* win32: 'c:\\foo\\aaa\\bbb' <-- good result
|
||||
* posix: '/foo/bar.js/..\\aaa\\bbb' <-- bad result
|
||||
*/
|
||||
path.resolve(osPath, win32Path);
|
||||
// ^ Argument of type 'Win32Path' is not assignable to parameter of type 'OsPath | PosixPath'.
|
||||
|
||||
// Fixs
|
||||
const posixPath = win32Path.replace(/\\/g, '/') as path.PosixPath;
|
||||
path.resolve(osPath, posixPath); // no type error
|
||||
```
|
||||
54
node_modules/typesafe-path/index.d.ts
generated
vendored
Normal file
54
node_modules/typesafe-path/index.d.ts
generated
vendored
Normal file
@@ -0,0 +1,54 @@
|
||||
declare const OsPathSymbol: unique symbol;
|
||||
declare const PosixPathSymbol: unique symbol;
|
||||
declare const Win32PathSymbol: unique symbol;
|
||||
|
||||
type _PlatformPath<PlatformPath, TArg, TReturn> = {
|
||||
[K in keyof PlatformPath]: PlatformPath[K] extends (...args: any) => any ? (
|
||||
Parameters<PlatformPath[K]> extends [string] ? (path: TArg) => _ReturnType<PlatformPath[K], TReturn>
|
||||
: Parameters<PlatformPath[K]> extends [string, string] ? (from: TArg, to: TArg) => _ReturnType<PlatformPath[K], TReturn>
|
||||
: Parameters<PlatformPath[K]> extends string[] ? (...paths: TArg[]) => _ReturnType<PlatformPath[K], TReturn>
|
||||
// basename
|
||||
: PlatformPath[K] extends (path: string, ext?: string) => string ? (path: TArg, ext?: string) => TReturn
|
||||
: PlatformPath[K]
|
||||
) : PlatformPath[K]
|
||||
};
|
||||
type _ReturnType<T extends (...args: any) => any, T2> = ReturnType<T> extends string ? T2 : ReturnType<T>;
|
||||
|
||||
declare module 'typesafe-path' {
|
||||
|
||||
namespace path {
|
||||
type OsPath = string & { [OsPathSymbol]: true; };
|
||||
type PosixPath = string & { [PosixPathSymbol]: true; };
|
||||
type Win32Path = string & { [Win32PathSymbol]: true; };
|
||||
}
|
||||
|
||||
const path: Omit<_PlatformPath<import('path').PlatformPath, path.OsPath | path.PosixPath, path.OsPath>, 'win32' | 'posix'>;
|
||||
|
||||
export = path;
|
||||
}
|
||||
|
||||
declare module 'typesafe-path/win32' {
|
||||
|
||||
namespace path {
|
||||
type OsPath = string & { [OsPathSymbol]: true; };
|
||||
type PosixPath = string & { [PosixPathSymbol]: true; };
|
||||
type Win32Path = string & { [Win32PathSymbol]: true; };
|
||||
}
|
||||
|
||||
const path: _PlatformPath<import('path').PlatformPath, string, path.Win32Path>;
|
||||
|
||||
export = path;
|
||||
}
|
||||
|
||||
declare module 'typesafe-path/posix' {
|
||||
|
||||
namespace path {
|
||||
type OsPath = string & { [OsPathSymbol]: true; };
|
||||
type PosixPath = string & { [PosixPathSymbol]: true; };
|
||||
type Win32Path = string & { [Win32PathSymbol]: true; };
|
||||
}
|
||||
|
||||
const path: _PlatformPath<import('path').PlatformPath, path.PosixPath, path.PosixPath>;
|
||||
|
||||
export = path;
|
||||
}
|
||||
1
node_modules/typesafe-path/index.js
generated
vendored
Normal file
1
node_modules/typesafe-path/index.js
generated
vendored
Normal file
@@ -0,0 +1 @@
|
||||
module.exports = require('path');
|
||||
19
node_modules/typesafe-path/package.json
generated
vendored
Normal file
19
node_modules/typesafe-path/package.json
generated
vendored
Normal file
@@ -0,0 +1,19 @@
|
||||
{
|
||||
"name": "typesafe-path",
|
||||
"version": "0.2.2",
|
||||
"main": "index.js",
|
||||
"types": "index.d.ts",
|
||||
"license": "MIT",
|
||||
"files": [
|
||||
"*.js",
|
||||
"*.d.ts"
|
||||
],
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "https://github.com/johnsoncodehk/typesafe-path.git"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@types/node": "latest",
|
||||
"typescript": "latest"
|
||||
}
|
||||
}
|
||||
1
node_modules/typesafe-path/posix.d.ts
generated
vendored
Normal file
1
node_modules/typesafe-path/posix.d.ts
generated
vendored
Normal file
@@ -0,0 +1 @@
|
||||
/// <reference path="./index.d.ts" />
|
||||
1
node_modules/typesafe-path/posix.js
generated
vendored
Normal file
1
node_modules/typesafe-path/posix.js
generated
vendored
Normal file
@@ -0,0 +1 @@
|
||||
module.exports = require('path').posix;
|
||||
1
node_modules/typesafe-path/win32.d.ts
generated
vendored
Normal file
1
node_modules/typesafe-path/win32.d.ts
generated
vendored
Normal file
@@ -0,0 +1 @@
|
||||
/// <reference path="./index.d.ts" />
|
||||
1
node_modules/typesafe-path/win32.js
generated
vendored
Normal file
1
node_modules/typesafe-path/win32.js
generated
vendored
Normal file
@@ -0,0 +1 @@
|
||||
module.exports = require('path').win32;
|
||||
Reference in New Issue
Block a user