@svizzle/file/path

Methods

(static) filterJsonExtensions(extensions) → {array}

Source:
Since:
  • 0.4.0

Filter an array of file names to contain only those with extension .json or .geojson. [node environment]

Example
> filterJsonExtensions(['file.json', 'file.geojson', 'file.csv'])
['file.json', 'file.geojson']
Parameters:
Name Type Description
extensions array

Array of file names

Returns:
Type
array

(static) getPathExt(filepath) → {string}

Source:
Since:
  • 0.11.0

Return the extension of the provided file path [node environment]

Example
> getPathExt('foo/bar.txt')
'txt'
> getPathExt('foo/bar.todo.md')
'md'
Parameters:
Name Type Description
filepath string
Returns:
  • the extension of the file path
Type
string

(static) hasAnyExtensionOf(extensions) → {boolean}

Source:
Since:
  • 0.4.0

Detect if a file name has one of the provided extensions. [node environment]

Example
> isJsonOrGeojson = hasAnyExtensionOf(['.json', '.geojson'])
> isJsonOrGeojson('file.json')
true
> isJsonOrGeojson('file.geojson')
true
> isJsonOrGeojson('file.csv')
false
Parameters:
Name Type Description
extensions array

An array of extensions

Returns:
Type
boolean

(static) isFileWithExt(extension) → {boolean}

Source:
Since:
  • 0.11.0

Return a function that returns true if the input file name has the provided extension [node environment]

Example
> isJson = isFileWithExt('json')
> isJson('file.json')
true
> isJson('file.txt')
false
Parameters:
Name Type Description
extension string
Returns:
Type
boolean

(static) renameToExtension(extension) → {function}

Source:
Since:
  • 0.4.0

Return a function expecting a filepath and returning it renamed to the provided extension. Note that if the original provided filepath has multiple extensions only the last one gets changed. [node environment]

Example
> renameToJson = renameToExtension('.json')
> renameToJson('file.txt')
'file.json'
> renameToJson('file.min.js')
'file.txt'
Parameters:
Name Type Description
extension string

file extension, including the dot (.txt, .csv, etc)

Returns:
  • String -> String
Type
function

(static) resolveToDir(dirPath) → {function}

Source:
Since:
  • 0.10.0

Return a function expecting a filename and returning it resolved to the provided directory path [node environment]

Example
> resolve = resolveToDir('/output/dir/');

> resolve('file1.txt')
'/output/dir/file1.txt'

> resolve('file2.txt')
'/output/dir/file2.txt'
Parameters:
Name Type Description
dirPath string

path of the dir to resolve to

Returns:
  • String -> String
Type
function