1.2.0 • Published 5 years ago

file-utils-easy v1.2.0

Weekly downloads
3
License
MIT
Repository
github
Last release
5 years ago

file-utils-easy

Coverage Status

This is a simply file utils lib.

Installation

npm install file-utils-easy

Usage

const fue = require('file-utils-easy');

fue.readDirectoryFiles('path/')
  .then(files => doSomething(files))
  .catch(err => doSomethingElse())

API

file-utils-easy~writeToFile(fileContent, filePath) ⇒ Promise.<string>

Write a string to a file

Kind: inner method of file-utils-easy
Returns: Promise.<string> - resolve with the filePath received in input

ParamTypeDescription
fileContentstringthe payload of the file
filePathstringpath and filename: where store the file

file-utils-easy~writeToFileStream(fileStream, filePath) ⇒ Promise

Write a stream to a file

Kind: inner method of file-utils-easy
Returns: Promise - resolve with the filePath when the stream finish

ParamTypeDescription
fileStreamstreamthe stream payload
filePathstringpath and filename: where store the file

file-utils-easy~appendToFile(fileContent, filePath) ⇒ Promise.<string>

Append a string to a file

Kind: inner method of file-utils-easy
Returns: Promise.<string> - resolve with the filePath received in input

ParamTypeDescription
fileContentstringthe payload of the file
filePathstringpath and filename: where store the file

file-utils-easy~readFileStats(filePath) ⇒ Promise.<fs.Stats>

Read the metadata of the file

Kind: inner method of file-utils-easy
Returns: Promise.<fs.Stats> - a node fs.Stats that provides information about a file
See: https://nodejs.org/api/fs.html#fs_class_fs_stats

ParamTypeDescription
filePathstringpath and filename: the file to read

file-utils-easy~readDirectoryFiles(directory) ⇒ Promise.<array>

List the files names of a directory, ignoring directories

Kind: inner method of file-utils-easy
Returns: Promise.<array> - strings names of the files in the input directory

ParamTypeDescription
directorystringpath of the directory to read

file-utils-easy~readFile(filePath, encoding) ⇒ Promise.<string>

Read the content of a file

Kind: inner method of file-utils-easy
Returns: Promise.<string> - resolve with the string content of the file

ParamTypeDefaultDescription
filePathstringpath and filename: the file to read
encodingstring"'utf8'"the encoding file

file-utils-easy~readJsonFile(filePath) ⇒ Promise.<object>

Read the content of a file as a UTF8 string and then parse it as a JSON

Kind: inner method of file-utils-easy
Returns: Promise.<object> - resolve with the JSON content of the file

ParamTypeDescription
filePathstringpath and filename: the file to read

file-utils-easy~saveUrlToFile(url, filePath) ⇒ Promise.<string>

Save the content of a url to a file

Kind: inner method of file-utils-easy
Returns: Promise.<string> - resolve with the filePath saved

ParamTypeDescription
urlstringwhere will be done an HTTP/GET to get the content
filePathstringpath and filename where store the output of url

file-utils-easy~deleteFile(filePath) ⇒ Promise.<string>

Delete a file from the file system

Kind: inner method of file-utils-easy
Returns: Promise.<string> - resolve with the filePath deleted

ParamTypeDescription
filePathstringpath and filename: the file to delete

file-utils-easy~deleteDirectoryFiles(directory) ⇒ Promise.<array>

Delete all the files in a directory, applying an optional filter

Kind: inner method of file-utils-easy
Returns: Promise.<array> - resolve with all the files deleted succesfully

ParamTypeDescription
directorystringpath of the directory to clean

file-utils-easy~renameFile(from, to) ⇒ Promise.<string>

Rename a file to another path

Kind: inner method of file-utils-easy
Returns: Promise.<string> - resolve with the destination filePath

ParamTypeDescription
fromstringorigin path and filename
tostringdestination path and filename

file-utils-easy~copyFile(from, to) ⇒ Promise.<string>

Copy a file to another path

Kind: inner method of file-utils-easy
Returns: Promise.<string> - resolve with the destination filePath

ParamTypeDescription
fromstringorigin path and filename
tostringdestination path and filename

file-utils-easy~existFile(filePath) ⇒ Promise.<string>

Check if a file exists

Kind: inner method of file-utils-easy
Returns: Promise.<string> - resolve with the filePath that exists
Throws:

  • error if the file doesn't exist
ParamTypeDescription
filePathstringpath and filename: the file to control

Test

For run the tests simply execute:

npm test

License

Copyright Manuel Spigolon, Licensed under MIT.

1.2.0

5 years ago

1.1.2

5 years ago

1.1.1

5 years ago

1.1.0

6 years ago

1.0.0

6 years ago

0.0.5

6 years ago

0.0.4

6 years ago

0.0.3

6 years ago

0.0.2

6 years ago

0.0.1

6 years ago