filic
v3.6.5
Published
An Advance File System API
Downloads
92
Maintainers
Readme
An Advance File System API
🏠 Homepage
Install
npm install filic
Ideology
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.
Quick Start
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"]
API
Types
import * as FilicTypes from 'filic/types/Filic.d';
import * as DirectoryTypes from 'filic/types/Directory.d';
import * as FileTypes from 'filic/types/File.d';
Filic
static Filic.create
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:
Filic.openDir
Opens Directory
const users = fs.openDir("users", options?);
- dirname:
string
- Name of Directory that you want open
- options:
FilicTypes.DirectoryOptions
- dirname:
Filic.openFile
Opens File
const foo = fs.openFile("foo", options?);
- filename:
string
- Name of File that you want open
- options:
FilicTypes.FileOptions
- filename:
Directory
const dir = fs.openDir(dirname, options?);
dirname:
string
options:
Filic.DirectoryOptions
Directory.openDir
- opens a directory inside the directory
dir.openDir(path, options?) // returns Directory
- path:
string
- path of the directory
- options:
FilicTypes.DirectoryOptions
Directory.openFile
- opens a file inside the directory
dir.openFile(path, options?) // returns Directory
- path:
string
- path of the file
- options:
FilicTypes.FileOptions
Directory.create
- Create directory
const dir = fs.openDir("dir", { autoCreate: false }); dir.createSync(options?) // creates directory
- options:
DirectoryTypes.createSyncOptions
Directory.delete
- Delete Directory
dir.deleteSelfSync(options?)
- options:
DirectoryTypes.deleteSelfSyncOptions
Directory.listRaw
- Raw Listing
dir.listRawSync();
Directory.list
- Listing as Entity Instances
dir.listSync(); // returns (Directory | File)[]
Directory.deleteFile
- 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
Directory.deleteDir
- 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
Directory.clear
- delete everything inside
dir.clearSync()
Directory.has
- checks if file or directory exists inside
dir.has(path) // returns boolean
- path:
string
- path of file or directory
Directory.copyAll
- copies all file inside to destination directory
dir.copyAllSync(destination, copyFileOptions?)
- destination:
Directory
- copyFileOptions:
FileTypes.copyFileOptions
Directory.copy
- copies it self to destination directory
dir.copySync(destination)
- destination:
Directory
Directory.moveAll
- moves all file inside to destination directory
dir.moveAllSync(destination)
- destination:
Directory
Directory.move
- moves it self to destination directory
dir.moveSync(destination)
- destination:
Directory
Directory.secondCopy
- Creates second copy of self in parent directory
dir.secondCopySync(dirname)
- dirname:
string
Directory.search
- Creates second copy of self in parent directory
dir.search(searchTerm, searchOptions)
- searchTerm:
string
- searchOptions:
DirectoryTypes.searchOptions
Directory.$
- Executes a command in the directory
dir.$(command, options?)
- command:
string
- options:
execa.Options
Directory.toFilic
- creates
Filic
Instance of directory Path asBasePath
dir.toFilic() // returns Filic
- creates
get Directory.size
- returns size of directory in bytes
dir.size // returns number
get Directory.dirname
- returns directory name of directory
dir.dirname // returns string
File
const file = fs.openFile(filename, options?);
dirname:
string
options:
Filic.FileOptions
File.create
- Create File
const file = fs.openFile("file", { autoCreate: false }); file.createSync(options?) // creates File
- options:
FileTypes.createSyncOptions
File.delete
- delete File
file.deleteSync(options?) // deletes File
- options:
FileTypes.deleteSyncOptions
File.readRaw
- reads content of file and returns as string
file.readRawSync(options?)
- options:
FileTypes.readRawSyncOptions
File.read
- reads content of file and returns custom string object
file.readSync(options?) // returns FileTypes.readSyncReturn
- options:
FileTypes.readSyncOptions
File.writeRaw
- writes string to file
file.writeRawSync(options?)
- options:
FileTypes.writeRawSyncOptions
File.write
- writes to file and tries to parse if not provided string
- Parser tries to parse JSON, Buffer, number.
file.writeSync(options?)
- options:
FileTypes.writeSyncOptions
File.append
- Appends string at the end of the file
file.appendSync(content, readRawSyncOptions?, writeRawSyncOptions?) // returns new content
- content:
string
- readRawSyncOptions:
FileTypes.readRawSyncOptions
- writeRawSyncOptions:
FileTypes.writeRawSyncOptions
File.prepend
- Prepends string at the start of the file
file.prependSync(content, readRawSyncOptions?, writeRawSyncOptions?) // returns new content
- content:
string
- readRawSyncOptions:
FileTypes.readRawSyncOptions
- writeRawSyncOptions:
FileTypes.writeRawSyncOptions
File.delete
- deletes the file
file.deleteSync(options?)
- options:
FileTypes.deleteSyncOptions
File.copy
- copies the file to destination directory
file.copySync(destination, filename?, options?)
- destination:
Directory
- filename:
string
- options:
FileTypes.copySyncOptions
File.move
- moves the file to destination directory
file.moveSync(destination, filename?, options?)
- destination:
Directory
- filename:
string
- options:
FileTypes.moveSyncOptions
File.secondCopy
- Creates second copy of self in parent directory
file.secondCopySync(filename)
- filename:
string
File.rename
- rename the name of the file
file.renameSync(filename)
- filename:
string
File.replaceWith
- replace the file content with given File
file.replaceWithSync(file)
- file:
File
File.update
- updates file content with callback function
file.updateSync((content)=>{ return newContent });
- callback:
(content: FileTypes.readSyncReturn) => any
get File.size
- returns size of file in bytes
file.size // returns number
get File.dirname
- returns name of file
file.dirname // returns string
File.createReadStream
- returns read stream of file
file.createReadStream(options?);
- options:
FileTypes.createReadStreamOptions
File.createWriteStream
- returns write stream of file
file.createWriteStream(options?);
- options:
FileTypes.createWriteStreamOptions
File.checksum
- returns checksum of file
file.checksum(options?)
- options:
FileTypes.checksumOptions
File.encrypt
- 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
File.decrypt
- 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
get File.extension
- returns extension of file
file.extension // returns string
Common Methods between Directory
and File
get absolutePath
- returns absolute path of directory or file
dir.absolutePath // string // or file.absolutePath // string
get Filic
- returns parent filic instance
dir.Filic // Filic // or file.Filic // Filic
get exists
- returns if file or directory exists
dir.exists // boolean // or file.exists // boolean
get parentDir
- returns parent directory as
Directory
Instance
dir.parentDir // Directory // or file.parentDir // Directory
- returns parent directory as
get dirPath
- returns parent directory absolute path
dir.dirPath // string // or file.dirPath // string
get stats
- returns stats of entity
dir.stats // string // or file.stats // string
Author
👤 Henil Malaviya
- E-mail: [email protected]
- Website: henil.xyz
- Twitter: @henilmalaviya
- Github: @henil0604
🤝 Contributing
Contributions, issues and feature requests are welcome!Feel free to check issues page.
Show your support
Give a ⭐️ if this project helped you!