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

@humanwhocodes/object-store

v0.2.0

Published

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

Downloads

276

Readme

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.

Copying Files

const store = new ObjectStore();
const file = store.createFile("foo.txt", { content: "Foo", parentId: "folder_id" });
const copiedFile = store.copyFile(file.id, { parentId: "some_other_folder_id", name: "bar.txt"});
console.log(copiedFile);
/*
{
    id: "copy-file-id",
    name: "bar.txt",
    type: "file",
    parent_id: "some_other_folder_id",
    created_at: "2022-10-20T12:00:00Z",
    modified_at: "2022-10-20T12:00:00Z"
}
*/

Note: name is optional. When parentId is not specified, the ID of the original's parent is used.

Moving/Renaming Files

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

Note: Both name and parentId are optional.

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.

Copying Folders

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

Note: name is optional. When parentId is not specified, the ID of the original's parent is used.

Moving/Renaming Folders

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

Deleting Folders

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

store.deleteFolder(folder.id);

Developer Setup

  1. Fork the repository
  2. Clone your fork
  3. Run npm install to setup dependencies
  4. Run npm test to run tests

License

Apache 2.0