Giter Club home page Giter Club logo

uristorage's Introduction

uristorage

Description

Provides a collection of Adapters that abstract various backends into simplistic Object Storages, along with Overlays to provide further common abstractions.

NOTE: This library provides utilities for working with compression, encoding, UNIX Glob patterns, filesystem paths, and mime types. Please use those, as they are tested to work with the library and should be fully Browser-compatible.

Sample

import {FileSystemOverlay, LocalStorageAdapter, MemoryAdapter} from "uristorage";

// Some Browsers may not support `window.localStorage`, or are otherwise in
// Private Browsing mode. So we need to default to another Adapter when not available.
const adapter = LocalStorageAdapter.is_available
    ? // With `LocalStorageAdapter`, we target `window.localStorage` for persistence. Thus
      // when the page is navigated away from, data is saved.
      new LocalStorageAdapter({
          // Option to use LZ77 compression before storing binary objects
          compressed: true, // default

          // Option to how to namespace your Adapter's access
          namespace: "uristorage", // default
      })
    : // with `MemoryAdapter`, we target RAM Memory for persistence. Thus
      // when the page is navigated away from, data is not saved.
      new MemoryAdapter({
          // Option to use LZ77 compression before storing binary objects
          compressed: false, // default
      });

// Using the Adapter we chose as the backend, we can create a
// File System-like abstraction as an Overlay
const filesystem = new FileSystemOverlay(adapter);

// Using the Overlay, you can see how we can perform File System-like operations
await filesystem.write_file_text("README.md", "# Hello World");

const content = await filesystem.read_file_text("README.md");
console.log(content); // prints `# Hello World`

// And even have directories, and query them with things like Glob Patterns
const entries = await filesystem.read_directory({
    glob: "*.md",
});

for (const entry of entries) {
    const {is_file, path} = entry;

    console.log({is_file, path}); // prints `{is_file: true, path: "/README.md"}`
}

Developer

Installation

Open your terminal and install via npm:

npm install git+https://github.com/novacbn/uristorage#0.0.6

Download current in-development code:

npm install git+https://github.com/novacbn/uristorage

Documentation

See TypeDoc documentation at novacbn.github.io/uristorage

API

LEGEND:

  • base — means the API is the base API that all inherting classes implement
  • shared — means the API should works in all Javascript contexts
  • whatwg — means the API works in Javascript contexts that implement the WHATWG HTML Living Standard

uristorage's People

Contributors

novacbn avatar

Watchers

 avatar  avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.