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

repodb

v1.0.0

Published

Make your Github private repository become a JSON database

Downloads

8

Readme

Overview

This TypeScript module will make your Github private repository become a JSON database.

Get Started

Github API Token

Before you start, please make sure you have a Github API access token of your account. (https://github.com/settings/tokens?type=beta)

And you need to confirm the settings of Repository Access and Account Permissions. | Type | Setting | |:--------------------|:--------------------------------------------------------------------------------------------------------| | Repository Access | All repositories | | Account Permissions | Administration (Read and write) Commit statuses (Read and write) Contents (Read and write) |

Setup

You need to install module repodb first.

npm i repodb

Import the module

import repodb, { Data, GithubOptions } from "repodb";

Initiate repodb by using function repodb.initiate(options). Please note that it is an async/await function.

It will check your Github repository. If there is no the targeted repository, a private repository will be created automatically.

const githubOptions: GithubOptions = {
  token: "YOUR_GITHUB_API_TOKEN",
  username: "YOUR_USERNAME",
  repo: "YOUR_REPO_NAME",
};
await repodb.initiate(githubOptions);

Create Data Object

You also need to create a data object by using function repodb.newData(dataName) to handle CRUD operations.

This function will check JSON File [dataName].json on your repository. If there is no the JSON file, it will be created automatically. Please note that it is an async/await function.

You don't need to create the data object for existing data in the repository, since the module has already updated the data at the initiation stage.

const STUDENTS = "students";
await repodb.addData(STUDENTS);

Read Data

You just need to get the array repodb.data[dataName] to read the data.

You can also use type Data for type checking (which is optional).

// Type checking (optional)
interface Student {
  name: string;
  age: number;
}
const students: Data<Student> = repodb.data[STUDENTS];
students; // Get the whole data array
students[0]; // Get the 1st item of the data array

You can also use vanilla JS array functions to read the data.

students.find((item: Student) => item.age > 15); // Vanilla JS array function
students.filter((item: Student) => item.name !== "Amy"); // Vanilla JS array function

Update Data

Regarding data update, we can change the array repodb.data[dataName] directly. Once you finish the amendment, you can use function repodb.data[dataName].update() to let the changees upload to the Github Repository. Please note that it is an async/await function.

students.push({ name: "Bob", age: 17 }); // Vanilla JS array function
students.pop(); // Vanilla JS array function
await students.update();

Delete Data

If you want to delete the data in the repository, use function repodb.data[dataName].delete(). It will deleted the JSON file in the repository. Please note that it is an async/await function.

await students.delete();

Delete Repository

It you want to delete the whole database(the repository), use function repodb.deleteRepo(). Please note that it is an async/await function.

await repodb.deleteRepo();

Example

Please check the code in /src/examples/exmaple.ts