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

@leismore/token

v6.0.2

Published

An authentication token class.

Downloads

15

Readme

Token Class

The authentication Token class for NodeJS.

Donation

Buy me a coffee via PayPal Donation

Motivation

Define a universal authentication token class for LMOS NodeJS project.

Installation

npm install @leismore/token

Test

npm test

Example

import {Token} from '@leismore/token';

Token.create().then(token=>{
  console.log(String(token));
});

API

class Token
{
  public token:      string;         // Random string
  public generated:  number;         // Unix timestamp (milliseconds)
  public expiry:     (number|null);  // Unix timestamp (milliseconds)

  /**
   * Create a Token instance
   * @param     {int}             [bitSize=TOKEN_DEFAULT_BITSIZE]     - Token bit-length (multiple of 8)
   * @param     {string}          [baseEncoding=UIDGenerator.BASE58]  - Token baseEncoding
   * @param     {int|null}        [expiry=now+30min]                  - Token expiry Unix-timestamp (millisecond)
   * @return    {Promise<Token>}                                      - A Token instance
   * @throw     {Error}                                               - invalid_bitSize | invalid_baseEncoding | invalid_expiry
   */
  public static async create
  (
    bitSize:      number           = TOKEN_DEFAULT_BITSIZE,
    baseEncoding: string           = UIDGenerator.BASE58,
    expiry:       (number|null)    = ( Date.now() + TOKEN_DEFAULT_EXPIRY * 60 * 1000 )
  ):Promise<Token>

  /**
   * @param {TokenData} token
   * @throw {Error}     - invalid_token | invalid_generated | invalid_expiry
   */
  public constructor(token: TokenData)

  public verify(token:string):boolean

  public toString():string
}

type TokenData = {
  token:     string,           // Random string
  generated: number,           // Unix timestamp (milliseconds)
  expiry:    (number|null)     // Unix timestamp (milliseconds)
};

const TOKEN_MIN_SIZE        = 6;   // Characters
const TOKEN_MIN_BITSIZE     = 32;  // Bit-length
const TOKEN_DEFAULT_BITSIZE = 128; // Bit-length
const TOKEN_DEFAULT_EXPIRY  = 30;  // Minutes

License

GNU Affero General Public License v3.0

Authors

Credit