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

better-sqlite3-plus

v1.1.2

Published

A collection of functions that can be easily applied to better-sqlite3 database instances

Downloads

8

Readme

better-sqlite3-plus

This module is a collection of functions that can be added to your sqlite3 database instance. The aim is to provide common database functionality that will speed up development of features commonly found a database.

crypto

Functions

A number of functions will be added to your sqlite3 instance. Those functions are as follows:

genHash

Generates a hash value based on the provided string input

Parameters

  • data (Required): A string representing the value to be hashed
  • algorithm (Default: sha256): The hashing algorithim to use
  • encoding (Default: hex): The encoding to be used when generating the output
import Database from 'better-sqlite3';
import bs3plus from 'better-sqlite3-plus';

const db = new Database('test.db');

bs3plus.crypto(db);

const { hash } = db
  .prepare(`select genHash(?, ?, ?) as hash`)
  .get('string to hash', 'sha256', 'hex');

const { hash } = db.prepare(`select genHash(?, ?) as hash`).get('string to hash', 'sha256');

const { hash } = db.prepare(`select genHash(?) as hash`).get('string to hash');

genPasswordHash

Generates a password hash value based on the provided inputs

Parameters

  • password (Required): The password that will be used to generate the hash
  • salt (Required): The salt value used to enhance the security of the password
  • keyLength (Default: 32): The length of the generated hash value
  • iterations (Default: 500): Number of iterations to use when generating the hash
  • algorithm (Default: sha512): The algorithm to use when generating the has value
  • encoding (Default: hex): The encoding to be used when generating the output
import Database from 'better-sqlite3';
import bs3plus from 'better-sqlite3-plus';

const db = new Database('test.db');

bs3plus.crypto(db);

const { hash } = db
  .prepare(`select genPasswordHash(?, ?, ?, ?, ?, ?) as hash`)
  .get('password1!', 'randomSaltValue', 32, 500, 'sha512', 'hex');

const { hash } = db
  .prepare(`select genPasswordHash(?, ?, ?, ?, ?) as hash`)
  .get('password1!', 'randomSaltValue', 32, 500, 'sha512');

const { hash } = db
  .prepare(`select genPasswordHash(?, ?, ?, ?) as hash`)
  .get('password1!', 'randomSaltValue', 32, 500);

const { hash } = db
  .prepare(`select genPasswordHash(?, ?, ?) as hash`)
  .get('password1!', 'randomSaltValue', 32);

const { hash } = db
  .prepare(`select genPasswordHash(?, ?) as hash`)
  .get('password1!', 'randomSaltValue');

genSalt

Generates a salt value based on the provided inputs

Parameters

  • size (Default: 32): The size of the salt value in bytes
  • encoding (Default: hex): The encoding to be used when generating the output
import Database from 'better-sqlite3';
import bs3plus from 'better-sqlite3-plus';

const db = new Database('test.db');

bs3plus.crypto(db);

const { salt } = db.prepare(`select genSalt(?, ?) as salt`).get(32, 'hex');

const { salt } = db.prepare(`select genSalt(?) as salt`).get(32);

const { salt } = db.prepare(`select genSalt() as salt`).get();

Statements

When adding the crypto functions module to your sqlite3 instance, a number of statements and statement generators are also returned for you to use at your convenience.

createSaltAndPasswordHash

This function receives as input an options object and returns a sqlite3 statment based on the provided options. The options are:

  • algorithm (Default: sha512): The algorithm to use when generating the has value
  • encoding (Default: hex): The encoding to be used when generating the output
  • iterations (Default: 500): Number of iterations to use when generating the hash
  • keyLength (Default: 16): The length of the generated hash value
import Database from 'better-sqlite3';
import bs3plus from 'better-sqlite3-plus';

const db = new Database('test.db');

const cryptoHelpers = bs3plus.crypto(db);

const myPasswordHashingStatement = cryptoHelpers.createSaltAndPasswordHash({
  algorithm: 'sha512',
  encoding: 'hex',
  iterations: 500,
  keyLength: 16
});

const result = myPasswordHashingStatement.get({ password: 'myPassword1!' });

console.log(result);

// PRINTS
// {
//   salt: '4ecc819ec883c5df7eac7615f80e0d23',
//   hash: '23c55169ff62921a018fbbd8616621d9'
// }