概述
文件路径常用的函数集合
目录
- directoryDepth (函数)
- foldPath (函数)
- getAbsoluteFilePath (函数)
- getDirectoryName (函数)
- getFileName (函数)
- isExtName (函数)
- isFullPath (函数)
- isSubPath (函数)
- notExtName (函数)
- splitPath (函数)
directoryDepth (函数)
得到路径的深度
签名
export const directoryDepth = (strPath: string): number => ...
v0.2.0 中添加
foldPath (函数)
把路径文本数组转换为单一路径
签名
export const foldPath = (a: string[]): string => ...
v0.2.0 中添加
getAbsoluteFilePath (函数)
得到绝对路径,如果第一个字符不是’/’,路径前面增加process.cwd()
签名
export const getAbsoluteFilePath = (filePath: string) => ...
示例
import { getAbsoluteFilePath } from 'macoolka-fs/lib/path'
expect(getAbsoluteFilePath('abc')).toEqual(process.cwd() + '/abc')
expect(getAbsoluteFilePath('/abc')).toEqual('/abc')
v0.2.0 中添加
getDirectoryName (函数)
从一个路径中得到文件夹
签名
export const getDirectoryName = (strPath: string): string => ...
v0.2.0 中添加
getFileName (函数)
从一个路径中得到文件名
签名
export const getFileName = (strPath: string): string => ...
v0.2.0 中添加
isExtName (函数)
检验文件是否是指定的扩展名
签名
export const isExtName = (extname: string) => (filePath: string) => ...
示例
import { isExtName } from 'macoolka-fs'
expect(isExtName('ts')('abc.ts')).toEqual(true)
expect(isExtName('ts')('abc.ts1')).toEqual(false)
isFullPath (函数)
核对一个路径是否是全路径
签名
export const isFullPath = (strRoot: string, strPath: string): boolean => ...
v0.2.0 中添加
isSubPath (函数)
核对一个路径是否是另一个路径的子路径
签名
export const isSubPath = (parent: string, sub: string): boolean => ...
v0.2.0 中添加
notExtName (函数)
检验文件是否不是指定的扩展名
签名
export const notExtName = (extname: string) => ...
示例
import { notExtName } from 'macoolka-fs'
expect(notExtName('ts')('abc.ts')).toEqual(false)
expect(notExtName('ts')('abc.ts1')).toEqual(true)
splitPath (函数)
用 path.sep 拆分路径
签名
export const splitPath = (a: string): string[] => ...
v0.2.0 中添加