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

ts-sdb

v1.0.1

Published

Fast reliable flat-file database.

Downloads

6

Readme

TSDB (TypeScript Database)

TSDB is a fast and reliable database port of the original sdb database written in PHP. It is my first TypeScript package, and I welcome any comments or feedback on my website or social media.

Installation

To install TSDB, you can use npm:

npm install ts-sdb

Usage

Here is an example of how to use TSDB in your TypeScript project:

import { TSDB } from 'tsdb';

// Create a new instance of TSDB
const db = new TSDB();

// Load the database
db.load('mydatabase');

// Perform operations on the database
db.create('key1', 'value1');
db.create('key2', 'value2');
db.update('key1', { value: 'newvalue' });
db.delete('key2');

// Save changes to the database
db.save();

Documentation

Class: Debug

The Debug class provides logging and error handling functionalities.

Constructor

constructor(mode: boolean = false)
  • mode (optional): A boolean value indicating the debug mode. Default is false.

log

Logs a message to the console if debug mode is enabled.

log(message: string, flag: string = 'DEBUG'): boolean | void
  • message: The message to be logged.
  • flag (optional): The log flag. Default is 'DEBUG'.

error

Logs an error message to the console.

error(message: string, code: string = 'unknown', flag: string = 'ERROR')
  • message: The error message to be logged.
  • code (optional): The error code. Default is 'unknown'.
  • flag (optional): The error flag. Default is 'ERROR'.

Interface: Data

The Data interface represents a database record.

interface Data {
  id: any;
  key: string;
  value: any;
}
  • id: The unique identifier of the record.
  • key: The key of the record.
  • value: The value associated with the key.

Class: TSDB

The TSDB class represents the TSDB database.

Constructor

constructor()

Creates a new instance of the TSDB class.

load

Loads a database file.

load(file: string, directory: string = ''): boolean
  • file: The name of the database file.
  • directory (optional): The directory where the database file is located. Default is an empty string.

Returns true if the database is successfully loaded, false otherwise.

save

Saves the changes made to the database.

save(): boolean

Returns true if the changes are successfully saved, false otherwise.

create

Creates a new record in the database.

create(key: string, value: any): number
  • key: The key of the record.
  • value: The value associated with the key.

Returns the ID of the created record.

readById

Reads a record from the database by its ID.

readById(id: number): Data | undefined
  • id: The ID of the record.

Returns the record if found, undefined otherwise.

read

Reads a record from the database by its key.

read(key: string): Data | undefined
  • key: The key of

the record.

Returns the record if found, undefined otherwise.

updateById

Updates a record in the database by its ID.

updateById(id: number, data: Partial<Data>): void
  • id: The ID of the record.
  • data: The partial data to update.

update

Updates a record in the database by its key.

update(key: string, data: Partial<Data>): void
  • key: The key of the record.
  • data: The partial data to update.

delete

Deletes a record from the database by its key.

delete(key: string): void
  • key: The key of the record.

has

Checks if a record with the given key exists in the database.

has(key: string): boolean
  • key: The key to check.

Returns true if the record exists, false otherwise.

map

Returns a JSON string representation of the database.

map(): string | number

Returns the JSON string representation of the database if it exists, -1 otherwise.

mapObject

Returns the database as an array of Data objects.

mapObject(): Data[] | number

Returns the database as an array of Data objects if it exists, -1 otherwise.

Contributors

License

This project is licensed under the MIT License. See the LICENSE file for details.