Latest Threat ResearchGlassWorm Loader Hits Open VSX via Developer Account Compromise.Details
Socket
Book a DemoInstallSign in
Socket

@humanwhocodes/object-store

Package Overview
Dependencies
Maintainers
0
Versions
3
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@humanwhocodes/object-store

An in-memory object store modeled on cloud drives like Google Drive.

Source
npmnpm
Version
0.1.1
Version published
Weekly downloads
2
Maintainers
0
Weekly downloads
 
Created
Source

Object Store

by Nicholas C. Zakas

If you find this useful, please consider supporting my work with a donation or nominate me for a GitHub Star.

Description

An implementation of an in-memory object store modeled on cloud drives like Google Drive. This is useful mostly for testing purposes.

Usage

Node.js

Install using [npm][npm] or [yarn][yarn]:

npm install @humanwhocodes/object-store

# or

yarn add @humanwhocodes/object-store

Import into your Node.js project:

// CommonJS
const { ObjectStore } = require("@humanwhocodes/object-store");

// ESM
import { ObjectStore } from "@humanwhocodes/object-store";

Deno

Install using JSR:

deno add @humanwhocodes/object-store

#or

jsr add @humanwhocodes/object-store

Then import into your Deno project:

import { ObjectStore } from "@humanwhocodes/object-store";

Bun

Install using this command:

bun add @humanwhocodes/object-store

Import into your Bun project:

import { ObjectStore } from "@humanwhocodes/object-store";

Browser

It's recommended to import the minified version to save bandwidth:

import { ObjectStore } from "https://cdn.skypack.dev/@humanwhocodes/object-store?min";

However, you can also import the unminified version for debugging purposes:

import { ObjectStore } from "https://cdn.skypack.dev/@humanwhocodes/object-store";

API

Creating Files

const store = new ObjectStore();
const file = store.createFile("foo.txt", { content: "Foo", parentId: "folder_id" });

console.log(file);
/*
{
    id: "file_id",
    name: "foo.txt",
    type: "file",
    parent_id: "parent_id",
    created_at: "2022-10-20T12:00:00Z",
    modified_at: "2022-10-20T12:00:00Z",
}
*/

Note: When parentId is omitted, the root folder is used.

Retrieving Files

const store = new ObjectStore();
const file = store.createFile("foo.txt", { content: "Foo" });
const retrievedFile = store.getFile(file.id);
console.log(retrievedFile);
/*
{
    id: "file_id",
    name: "foo.txt",
    type: "file",
    parent_id: "parent_id",
    created_at: "2022-10-20T12:00:00Z",
    modified_at: "2022-10-20T12:00:00Z",
}
*/

Retrieving File Content

const store = new ObjectStore();
const file = store.createFile("foo.txt", { content: "Foo" });
const content = store.getFileContent(file.id);
console.log(content);   // "Foo"

Deleting Files

const store = new ObjectStore();
const file = store.createFile("foo.txt", { content: "Foo" });

store.deleteFile(file.id);

Creating Folders

const store = new ObjectStore();
const folder = store.createFolder("my-folder", { parentId: "parent_folder_id" });
console.log(folder);
/*
{
    id: "folder_id",
    name: "my-folder",
    type: "folder",
    parent_id: "parent_id",
    created_at: "2022-10-20T12:00:00Z",
    modified_at: "2022-10-20T12:00:00Z",
    entries: []
}
*/

Note: When parentId is omitted, the root folder is used.

Deleting Folders

const store = new ObjectStore();
const folder = store.createFolder("my-folder");

store.deleteFolder(folder.id);

Developer Setup

  • Fork the repository
  • Clone your fork
  • Run npm install to setup dependencies
  • Run npm test to run tests

License

Apache 2.0

Keywords

nodejs

FAQs

Package last updated on 20 Jun 2024

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