Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

hotfile

Package Overview
Dependencies
Maintainers
1
Versions
35
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

hotfile

```js const directory = '/some/directory/path' const file = '/some/file/path.ext' const HF = require('hotfile')

  • 0.0.8
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
5
decreased by-28.57%
Maintainers
1
Weekly downloads
 
Created
Source

hotfile

const directory = '/some/directory/path'
const file = '/some/file/path.ext'
const HF = require('hotfile')

const someAsyncFunction = async () => {
    const hotfiles = await HF.map(directory)
    const hotfile = new HF(file)
    const hotdir = hotfiles[0]
    const newdir = await hotdir.appendDirectory('subtitles')
}
const hotdir = new HF(directory)
await hotdir.rename('newfilename', 'ext')

const hotfile = new HF(file)
await hotfile.moveTo(hotdir)

Exclude all Hidden Files

const items = await hotfile.map(someFolderPath, {
    exclude: /(^|\/)\.[^\/\.]/g,
    model: SomeModelThatInheritsFromHotfile
})

Create a Hotfile Wrapper Class

Note that all wrapper class objects must inherit from the Hotfile class.

const HF = require('hotfile')

class SomeName extends HF {
    constructor(path){
        super(path)
        // write your code here ... 
    }
}

Some Usefull Methods you might want to use in your wrapper class

const HF = require('hotfile')

class SomeName extends HF {
    constructor(path){
        super(path)
        // write your code here ... 
    }

    filename(name, ext){
        if(ext) this.ext = ext
        return [
            name || this.name, 
            this.ext && this.ext.replace('.','') || null
        ].filter(e => e != null).join('.')
    }
    
    /* rewriting map function with default settings */
    static async map(path, options = {}){
        return await super.map(path, {
            exclude: /(^|\/)\.[^\/\.]/g,
            model: this
        })
    }

    async rename(name, ext){
        if(ext) this.ext = ext
        const toPath = this.parent + '/' + this.filename(name)
        return await this.move(toPath)
    }

    async moveTo(toPath){
        if(toPath instanceof Hotfile && toPath.isDirectory) toPath = toPath.path
        toPath = toPath + '/' + this.filename()
        return fs.promises.rename(this.path, toPath).then(async () => {
                await Object.assign(this, new Hotfile(toPath))
                return true
        }).catch(() => false)
    }

    async move(toPath){
        return fs.promises.rename(this.path, toPath).then(async () => {
                await Object.assign(this, new Hotfile(toPath))
                return true
        }).catch((err) => {
            console.log(err)
            return false
        })
    }

    async appendDirectory(name){
        if(this.isFile) throw('append only works on directories')
        let path = this.path + '/' + name
        return fs.promises.mkdir(path, { recursive: true })
            .then(() => {
                const dir = new Hotfile(path)
                this.children.push(dir)
                return dir
            }).catch(() => false)
    }

    async delete(){
        return fs.promises.unlink(this.path).then(async () => {
            await Object.assign(this,{parent: null, path: null, name: null, metadata: null})
            return true
        }).catch(() => false)
    }
}

FAQs

Package last updated on 14 Nov 2020

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc