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.
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"}`
}
Open your terminal and install via npm
:
npm install git+https://github.com/novacbn/uristorage#0.0.5
Download current in-development code:
npm install git+https://github.com/novacbn/uristorage
See TypeDoc documentation at novacbn.github.io/uristorage
LEGEND:
base
— means the API is the base API that all inherting classes implementshared
— means the API should works in all Javascript contextswhatwg
— means the API works in Javascript contexts that implement the WHATWG HTML Living Standard
Adapters
BaseAdapter
— base
IndexedDBAdapter
— whatwg
MemoryAdapter
— shared
WebStorageAdapter
— base
LocalStorageAdapter
— whatwgSessionStorageAdapter
— whatwgOverlays
BaseOverlay
— base
FileSystemOverlay
— shared
FileSystemOverlay.create_directory
FileSystemOverlay.create_scope
FileSystemOverlay.create_url_object
FileSystemOverlay.exists
FileSystemOverlay.get_stats
FileSystemOverlay.read_directory
FileSystemOverlay.read_file
FileSystemOverlay.read_file_json
FileSystemOverlay.read_file_text
FileSystemOverlay.remove_directory
FileSystemOverlay.remove_file
FileSystemOverlay.write_file
FileSystemOverlay.write_file_json
FileSystemOverlay.write_file_text
Registries
StorageRegistry
— base
FileSystemRegistry
— shared
FileSystemRegistry.create_directory
FileSystemRegistry.create_scope
FileSystemRegistry.create_url_object
FileSystemRegistry.exists
FileSystemRegistry.get_stats
FileSystemRegistry.read_directory
FileSystemRegistry.read_file
FileSystemRegistry.read_file_json
FileSystemRegistry.read_file_text
FileSystemRegistry.remove_directory
FileSystemRegistry.remove_file
FileSystemRegistry.write_file
FileSystemRegistry.write_file_json
FileSystemRegistry.write_file_text
Utilities
Adapters
create_url_object
— sharedcan_watch
— sharedfilter_query
— sharedhook_watcher
— sharedCompression
compress
— shareddecompress
— sharedEncoding
decode_safe
— shareddecode_text
— sharedencode_safe
— sharedencode_text
— sharedUNIX Globs
make_glob
— sharedMime Types
get_mime_type
— sharedPaths
Generated using TypeDoc