An Advance File System API
🏠 Homepage
npm install filic
This library aims to simplify how applications access File System via fs
API. The Filic API is really simple to use to make your experience great with File System API.
Filic uses object oriented approach to handle files and directories.
Filic's First Priority is to make API type-safe and simple.
import Filic from 'filic';
const fs = Filic.create() // new Filic
const greetings = fs.openFile("greetings.json")
greetings.writeSync([
"Good Morning",
"Good Afternoon",
"Good Night"
])
console.log(greetings.readSync()); // ["Good Morning","Good Afternoon","Good Night"]
import * as FilicTypes from 'filic/types/Filic.d';
import * as DirectoryTypes from 'filic/types/Directory.d';
import * as FileTypes from 'filic/types/File.d';
-
Allows to create Filic Instance
import Filic from 'filic' const fs = Filic.create(BasePath, autoCreate?);
- BasePath:
string
- Path of Directory from where every path will be resolved. defaults to
process.cwd()
- Path of Directory from where every path will be resolved. defaults to
- autoCreateDir:
boolean
- if
true
and theBasePath
does not exists, it will create the directory. iffalse
client will not force createBasePath
directory. defaults totrue
- if
- BasePath:
-
Opens Directory
const users = fs.openDir("users", options?);
- dirname:
string
- Name of Directory that you want open
- options:
FilicTypes.DirectoryOptions
- dirname:
-
Opens File
const foo = fs.openFile("foo", options?);
- filename:
string
- Name of File that you want open
- options:
FilicTypes.FileOptions
- filename:
const dir = fs.openDir(dirname, options?);
-
dirname:
string
-
options:
Filic.DirectoryOptions
-
- opens a directory inside the directory
dir.openDir(path, options?) // returns Directory
- path:
string
- path of the directory
- options:
FilicTypes.DirectoryOptions
-
- opens a file inside the directory
dir.openFile(path, options?) // returns Directory
- path:
string
- path of the file
- options:
FilicTypes.FileOptions
-
- Create directory
const dir = fs.openDir("dir", { autoCreate: false }); dir.createSync(options?) // creates directory
- options:
DirectoryTypes.createSyncOptions
-
- Delete Directory
dir.deleteSelfSync(options?)
- options:
DirectoryTypes.deleteSelfSyncOptions
-
- Raw Listing
dir.listRawSync();
-
- Listing as Entity Instances
dir.listSync(); // returns (Directory | File)[]
-
- delete File inside directory
dir.deleteFileSync(path, openFileOptions?, deleteOptions?);
- path:
string | File
- Path/File Instance of the file you want to delete
- openFileOptions:
FilicTypes.FileOptions
- deleteOptions:
FileTypes.deleteSyncOptions
-
- delete Directory inside directory
dir.deleteDirSync(path, openDirOptions?, deleteSelfOptions?);
- path:
string | Directory
- Path/Directory Instance of the file you want to delete
- openDirOptions:
FilicTypes.DirectoryOptions
- deleteSelfOptions:
FileTypes.deleteSelfSyncOptions
-
- delete everything inside
dir.clearSync()
-
- checks if file or directory exists inside
dir.has(path) // returns boolean
- path:
string
- path of file or directory
-
- copies all file inside to destination directory
dir.copyAllSync(destination, copyFileOptions?)
- destination:
Directory
- copyFileOptions:
FileTypes.copyFileOptions
-
- copies it self to destination directory
dir.copySync(destination)
- destination:
Directory
-
- moves all file inside to destination directory
dir.moveAllSync(destination)
- destination:
Directory
-
- moves it self to destination directory
dir.moveSync(destination)
- destination:
Directory
-
- Creates second copy of self in parent directory
dir.secondCopySync(dirname)
- dirname:
string
-
- Creates second copy of self in parent directory
dir.search(searchTerm, searchOptions)
- searchTerm:
string
- searchOptions:
DirectoryTypes.searchOptions
-
- Executes a command in the directory
dir.$(command, options?)
- command:
string
- options:
execa.Options
-
- creates
Filic
Instance of directory Path asBasePath
dir.toFilic() // returns Filic
- creates
-
- returns size of directory in bytes
dir.size // returns number
-
- returns directory name of directory
dir.dirname // returns string
const file = fs.openFile(filename, options?);
-
dirname:
string
-
options:
Filic.FileOptions
-
- Create File
const file = fs.openFile("file", { autoCreate: false }); file.createSync(options?) // creates File
- options:
FileTypes.createSyncOptions
-
- delete File
file.deleteSync(options?) // deletes File
- options:
FileTypes.deleteSyncOptions
-
- reads content of file and returns as string
file.readRawSync(options?)
- options:
FileTypes.readRawSyncOptions
-
- reads content of file and returns custom string object
file.readSync(options?) // returns FileTypes.readSyncReturn
- options:
FileTypes.readSyncOptions
-
- writes string to file
file.writeRawSync(options?)
- options:
FileTypes.writeRawSyncOptions
-
- writes to file and tries to parse if not provided string
- Parser tries to parse JSON, Buffer, number.
file.writeSync(options?)
- options:
FileTypes.writeSyncOptions
-
- Appends string at the end of the file
file.appendSync(content, readRawSyncOptions?, writeRawSyncOptions?) // returns new content
- content:
string
- readRawSyncOptions:
FileTypes.readRawSyncOptions
- writeRawSyncOptions:
FileTypes.writeRawSyncOptions
-
- Prepends string at the start of the file
file.prependSync(content, readRawSyncOptions?, writeRawSyncOptions?) // returns new content
- content:
string
- readRawSyncOptions:
FileTypes.readRawSyncOptions
- writeRawSyncOptions:
FileTypes.writeRawSyncOptions
-
- deletes the file
file.deleteSync(options?)
- options:
FileTypes.deleteSyncOptions
-
- copies the file to destination directory
file.copySync(destination, filename?, options?)
- destination:
Directory
- filename:
string
- options:
FileTypes.copySyncOptions
-
- moves the file to destination directory
file.moveSync(destination, filename?, options?)
- destination:
Directory
- filename:
string
- options:
FileTypes.moveSyncOptions
-
- Creates second copy of self in parent directory
file.secondCopySync(filename)
- filename:
string
-
- rename the name of the file
file.renameSync(filename)
- filename:
string
-
- replace the file content with given File
file.replaceWithSync(file)
- file:
File
-
- updates file content with callback function
file.updateSync((content)=>{ return newContent });
- callback:
(content: FileTypes.readSyncReturn) => any
-
- returns size of file in bytes
file.size // returns number
-
- returns name of file
file.dirname // returns string
-
- returns read stream of file
file.createReadStream(options?);
- options:
FileTypes.createReadStreamOptions
-
- returns write stream of file
file.createWriteStream(options?);
- options:
FileTypes.createWriteStreamOptions
-
- returns checksum of file
file.checksum(options?)
- options:
FileTypes.checksumOptions
-
- encrypts file and stores the encrypted result in given file.
file.encrypt(key, file?, options?)
- key:
string
- file:
File
- by default the result will be stored in the same directory in file with filename
<filename>.enc
- by default the result will be stored in the same directory in file with filename
- options:
FileTypes.encryptOptions
-
- decrypts file and stores the decrypted result in given file.
file.decrypt(key, file?, options?)
- key:
string
- file:
File
- by default the result will be stored in the same directory in file with filename
<filename>.dec
- by default the result will be stored in the same directory in file with filename
- options:
FileTypes.decryptOptions
-
- returns extension of file
file.extension // returns string
-
- returns absolute path of directory or file
dir.absolutePath // string // or file.absolutePath // string
-
- returns parent filic instance
dir.Filic // Filic // or file.Filic // Filic
-
- returns if file or directory exists
dir.exists // boolean // or file.exists // boolean
-
- returns parent directory as
Directory
Instance
dir.parentDir // Directory // or file.parentDir // Directory
- returns parent directory as
-
- returns parent directory absolute path
dir.dirPath // string // or file.dirPath // string
-
- returns stats of entity
dir.stats // string // or file.stats // string
👤 Henil Malaviya
- E-mail: me@henil.xyz
- Website: henil.xyz
- Twitter: @henilmalaviya
- Github: @henil0604
Contributions, issues and feature requests are welcome!
Feel free to check issues page.
Give a ⭐️ if this project helped you!