Noisy Pirate Mutiny

    localwebstorage

    1.0.0 • Public • Published

    localwebstorage

    Description

    Web Storage like API for interacting with the file system as if it were the browser's local storage.

    require

    const localwebstorage = require('localwebstorage');

    Functions

    • localwebstorage.setDatabase(path);
      • Function: create/load folder in which to create/save database items
      • Parameter: path as String
      • returns nothing
    • localwebstorage.setItem(itemName,itemContent);
      • Function: create folder in which to create/save database items
      • Parameters: name of the item and the item content as a String
      • returns nothing
    • localwebstorage.getItem(itemName);
      • Function: Get the item's content
      • Parameters: name of the item as a string
      • returns the content as a string and returns null if item does not exist
    • localwebstorage.removeItem(itemName);
      • Function: Delete item
      • Parameters: name of the item as a string
      • returns nothing
    • localwebstorage.getAllItems();
      • Function: Get all saved item keys
      • Parameters: takes no parameters
      • returns an array of strings containing all items keys

    Note:

    All functions are asynchronous, meaning you must always call them from async functions and await for its completion. Item Names must follow file system file naming rules otherwise throws an error.

    Important

    Unlike the browser webstorage you first have to specify a file system path to a folder to specify where you want your items to be saved using the function

    localwebstorage.setDatabase(path)

    this function is required to be called only once and always before calling the other functions. By calling this function again with a different path, the functions will now read and write to the newly specified folder. By setting a path, this function will create the necessary folders so that you don't have to manually create them with recursivefolder npm module

    Example:

    async function createAndRead(){
      await localwebstorage.setDatabase('./database');
      await localwebstorage.setItem('test','Hello World');
      console.log(await localwebstorage.getItem('test'));
    }
    createAndRead();

    Install

    npm i localwebstorage

    DownloadsWeekly Downloads

    4

    Version

    1.0.0

    License

    MIT

    Unpacked Size

    4.83 kB

    Total Files

    4

    Last publish

    Collaborators

    • onlinespawn