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 🙏

© 2026 – Pkg Stats / Ryan Hefner

@kansa/common

v1.1.0

Published

Common objects and utilities shared across the Kansa server & modules

Readme

@kansa/common

Common objects and utilities shared across the Kansa server & modules.

User authentication

const { isSignedIn, hasRole, matchesId } = require('@kansa/common/auth-user')

function isSignedIn(req, res, next)

Express.js middleware function that verifies that the current user is signed in. On failure, calls next(new AuthError()).

function hasRole(role: string | string[]): function(req, res, next)

Function returning an Express.js middleware function that verifies that the current user is signed in and has the specified role (or one of the roles, if an array). On failure, calls next(new AuthError()).

function matchesId(db, req, role?: string | string[]): Promise<number>

Verifies that the id parameter of the request req grants access to the session user's email. If set, role may define one or multiple roles that the user may have that grant access without a matching email.

db should be a pg-promise instance, or e.g. a task extended from such an instance. Returns a promise that either resolves to the id value, or rejects with either AuthError, InputError, or a database error.

new AuthError(message: string)

Configuration

const config = require('@kansa/common/config')

The server configuration, sourced from config/kansa.yaml and read during server start.

Errors

const { AuthError, InputError } = require('@kansa/common/errors')

new AuthError(message: string)

new InputError(message: string)

Handled by the server's error handling. May also have their status set.

Log entries

const LogEntry = require('@kansa/common/log-entry')
new LogEntry(req, 'Log message').write(db)

new LogEntry(req, message: string)

Creates a new log entry for tracking changes. The entry's fields such as author, description and subject are modifiable before the entry gets stored with its write(db): Promise method.

Mail

function sendMail(type: string, data: any, delay?: number): Promise

Schedule an email message of type with data to be sent, with an optional delay in minutes. The message should have a correspondingly named template available under config/message-templates/.

function updateMailRecipient(db, email: string): Promise

Using the pg-promise instance db, fetch the appropriate data for email and forward it to be sent to Sendgrid. Returns a promise that will never reject.

Split names

const splitName = require('@kansa/common/split-name')

splitName('Bob Tucker')
// ['', 'Bob Tucker']

splitName('Bob Tucker', 8)
// ['Bob', 'Tucker']

splitName('Arthur Wilson "Bob" Tucker')
// [ 'Arthur Wilson', '"Bob" Tucker' ]

function splitName(name: string, maxLength = 14): [string, string]

Splits a name (or other string) prettily on two lines.

If the name already includes newlines, the first will be used to split the string and the others replaced with spaces. If the name is at most maxLength characters, it'll be returned as ['', name]. Otherwise, we find the most balanced white space to use as a split point.

Trueish

const isTrueish = require('@kansa/common/trueish')

isTrueish() // false
isTrueish('0') // false
isTrueish(' False') // false
isTrueish(-1) // true

function isTrueish(v: any): boolean

Casts input into boolean values. In addition to normal JavaScript casting rules, also trims and lower-cases strings before comparing them to the following: '', '0', 'false', 'null'. Matches to these result in a false value. The primary intent is to enable human-friendly handling of query parameter values.