Skip to content

引入

ts
import { normalizePath, getRelativePath } from 't-comm';

// 不支持 tree-shaking 的项目
import { normalizePath, getRelativePath} from 't-comm/lib/path/index';

// 只支持 ESM 的项目
import { normalizePath, getRelativePath} from 't-comm/es/path/index';

normalizePath

描述

格式化路径

参数

参数名描述
path

文件路径,或目录路径

返回:

格式化后的路径

示例

ts
normalizePath('xxx/xxx/xxx');

normalizePath('xxx\\xxx\\xxx');

getRelativePath(pathA, pathB)

描述

A引用B时,拿引用路径

参数

参数名描述
pathA

路径A

pathB

路径B

返回:

相对路径

示例

ts
getRelativePath('a', 'b');

// './b'