Overview
Common functions for file path
Table of contents
- directoryDepth (function)
- foldPath (function)
- getAbsoluteFilePath (function)
- getDirectoryName (function)
- getFileName (function)
- isExtName (function)
- isFullPath (function)
- isSubPath (function)
- notExtName (function)
- splitPath (function)
directoryDepth (function)
Calculate a path depth
Signature
export const directoryDepth = (strPath: string): number => ...
Added in v0.2.0
foldPath (function)
fold for path array
Signature
export const foldPath = (a: string[]): string => ...
Added in v0.2.0
getAbsoluteFilePath (function)
Get process.cwd() + inputPath
when first char is not /
,or get orgin path
Signature
export const getAbsoluteFilePath = (filePath: string) => ...
Example
import { getAbsoluteFilePath } from 'macoolka-fs/lib/path'
expect(getAbsoluteFilePath('abc')).toEqual(process.cwd() + '/abc')
expect(getAbsoluteFilePath('/abc')).toEqual('/abc')
Added in v0.2.0
getDirectoryName (function)
Get directory from path
Signature
export const getDirectoryName = (strPath: string): string => ...
Added in v0.2.0
getFileName (function)
Returns name of file name.
Signature
export const getFileName = (strPath: string): string => ...
Added in v0.2.0
isExtName (function)
Check a file with extname
Signature
export const isExtName = (extname: string) => (filePath: string) => ...
Example
import { isExtName } from 'macoolka-fs'
expect(isExtName('ts')('abc.ts')).toEqual(true)
expect(isExtName('ts')('abc.ts1')).toEqual(false)
isFullPath (function)
check path in root is full path
Signature
export const isFullPath = (strRoot: string, strPath: string): boolean => ...
Added in v0.2.0
isSubPath (function)
check a path is int parent path
Signature
export const isSubPath = (parent: string, sub: string): boolean => ...
Added in v0.2.0
notExtName (function)
Check a file not with extname
Signature
export const notExtName = (extname: string) => ...
Example
import { notExtName } from 'macoolka-fs'
expect(notExtName('ts')('abc.ts')).toEqual(false)
expect(notExtName('ts')('abc.ts1')).toEqual(true)
splitPath (function)
split path with path.sep
Signature
export const splitPath = (a: string): string[] => ...
Added in v0.2.0