npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

jsdav-promise

v0.0.4

Published

A promise interface implementing virtual file and folder with jsDAV

Downloads

5

Readme

jsdav-promise

A promise interface implementing virtual file and folder with jsDAV

Usage - ES5

The module exports two classes: 'File' and 'Collection'. Extend them to create virtual files and folders.

var JsDAVPromise = require('jsdav-promise');
var File = JsDAVPromise.File;
var Collection = JsDAVPromise.Collection;

var SomeFolder = Collection.extend(
{
    initialize: function(name) {
        this.name = name;
        this.path = '/' + name;
    },

    createDirectoryAsync: function(name) {
	/* ... */
    },

    deleteAsync: function() {
	/* ... */
    },

    getChildrenAsync: function() {
	/* ... */
    },

    setNameAsync: function(name) {
	/* ... */
    },    
});

var SomeFile = File.extend(
{    
    initialize: function(folder, name) {
        this.name = name;
	this.path = folder.path + '/' + name;
    },

    getAsync: function() {
	    /* ... */
    },

    putAsync: function(data, type) {
	    /* ... */
    },

    deleteAsync: function() {
	    /* ... */
    },

    getSizeAsync: function() {
	    /* ... */
    },

    getETagAsync: function() {
	    /* ... */
    },

    getContentTypeAsync: function() {
	    /* ... */
    },

    getLastModifiedAsync: function() {
	    /* ... */
    },

    setNameAsync: function(name) {
	    /* ... */
    },
});

Usage - ES7

const { File, Collection } = require('jsdav-promise/es6');

class SomeFolder extends Collection {
    constructor(name) {
        super();
        this.name = name;
        this.path = '/' + name;
    }

    async createDirectoryAsync(name) {
	    /* ... */
    }

    async deleteAsync() {
	    /* ... */
    }

    async getChildrenAsync() {
	    /* ... */
    }

    async setNameAsync(name) {
	    /* ... */
    }
}

class SomeFile extends File {    
    constructor(folder, name) {
        this.name = name;
	    this.path = folder.path + '/' + name;
    }

    async getAsync() {
	    /* ... */
    }

    async putAsync(data, type) {
	    /* ... */
    }

    async deleteAsync() {
	    /* ... */
    }

    async getSizeAsync() {
	    /* ... */
    }

    async getETagAsync() {
	    /* ... */
    }

    async getContentTypeAsync() {
	    /* ... */
    }

    async getLastModifiedAsync() {
	    /* ... */
    }

    async setNameAsync(name) {
	    /* ... */
    }
}

Methods for both File and Collection

deleteAsync()

Delete the file or folder. Should return a promise of true.

If not implemented, a Forbidden error will be thrown when the client attempts to perform the operation.

If the promise resolves to null or undefined, a FileNotFound error will be thrown.

getLastModifiedAsync()

Get the last-modified date of the file or folder. Should return a promise of a Date object.

If not implemented, the current date is returned.

If the promise resolves to null or undefined, a FileNotFound error will be thrown.

getName()

Get the name of the file or folder. Should return a string.

The default implementation return this.name.

setNameAsync(name)

Change the name of the file or folder. Should return a promise of true.

If not implemented, a Forbidden error will be thrown when the client attempts to perform the operation.

If the promise resolves to null or undefined, a FileNotFound error will be thrown.

Methhods for Collection

childExistsAsync(name)

Check if a child node exists. Should return a promise of a boolean.

If not implemented, getChildAsync() or getChildrenAsync() will be called to determine the child's existence.

createDirectoryAsync(name)

Create a child folder. Should return a promise of true. If the child already exists, promise should reject with a Conflict error.

If not implemented, a Forbidden error will be thrown when the client attempts to perform the operation.

If the promise resolves to null or undefined, a FileNotFound error will be thrown.

createFileAsync(name, data, type)

Create a file in the folder containing the data given. Should return a promise of true. If the file already exists, promise should reject with a Conflict error.

If not implemented, a Forbidden error will be thrown when the client attempts to perform the operation.

If the promise resolves to null or undefined, a FileNotFound error will be thrown.

getChildAsync(name)

Get a child by name. Should return a promise of a object extending either File or Collection--or null if the child does not exists.

If not implemented, getChildren() will be called to find the child.

If the promise resolves to null or undefined, a FileNotFound error will be thrown.

getChildrenAsync()

Get a list of all child nodes. Should return a promise of an array of objects extending either File or Collection.

If not implemented, an empty array is returned.

If the promise resolves to null or undefined, a FileNotFound error will be thrown.

Methhods for File

getAsync()

Get the content of a virtual file. Should return a promise of a Buffer object.

If not implemented, a Forbidden error will be thrown when the client attempts to perform the operation.

If the promise resolves to null or undefined, a FileNotFound error will be thrown.

getContentTypeAsync()

Get the MIME type of a virtual file. Should return a promise of a string.

If not implemented, null is returned.

If the promise resolves to null or undefined, a FileNotFound error will be thrown.

getETagAsync()

Get the E-tag of a virtual file. Should return a promise of a string.

If not implemented, null is returned.

If the promise resolves to null or undefined, a FileNotFound error will be thrown.

getSizeAsync()

Get the E-tag of a virtual file. Should return a promise of a number.

If not implemented, 0 is returned.

If the promise resolves to null or undefined, a FileNotFound error will be thrown.

putAsync(data, type)

Replace the contents of a virtual file. Should return a promise of true.

If not implemented, a Forbidden error will be thrown when the client attempts to perform the operation.

If the promise resolves to null or undefined, a FileNotFound error will be thrown.

Exceptions

For convenience sake, the module re-exports the following error classes from jsDAV:

  • BadRequest (400)
  • Conflict (409)
  • AceConflict
  • Locked (423)
  • ConflictingLock
  • FileNotFound (404)
  • Forbidden (403)
  • NeedPrivileges (403)
  • InsufficientStorage (507)
  • InvalidResourceType
  • LockTokenMatchesRequestUri
  • MethodNotAllowed (405)
  • NotAuthenticated (401)
  • NotImplemented (501)
  • PaymentRequired (402)
  • PreconditionFailed (412)
  • NoAbstract
  • NotRecognizedPrincipal
  • NotSupportedPrivilege
  • ReportNotImplemented
  • RequestedRangeNotSatisfiable (416)
  • ServiceUnavailable (503)
  • UnsupportedMediaType (415)
  • UnprocessableEntity (422)