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

ganomede-tagizer

v2.0.1

Published

The mighty tagizer of ganomede usernames

Downloads

3

Readme

ganomede-tagizer

The mighty tagizer of ganomede usernames.

Tag function

var tagizer = require('ganomede-tagizer').tag;
tag('p0lO') === tag('pO10');
typeof tag('abcdef') === 'string';

The goal of the tag function is to generate a non-visually ambiguous version of a username. You know, sometimes people confuse a 0 and a O, these sort of things.

This module exposes a single function that, given a username, returns a string: a "tag". Compare 2 tags generated from 2 usernames: if they are equal, it means the usernames look similar on screen.

In my use case, I make sure username's "tags" are globally unique in our users database, preventing confusingly similar-looking usernames to co-exist. A database search by username will search by tag: which should always return a single or no result.

Tag-mode Middleware

Signature: tagizer.middlerware(field, subfield, options = {})

Return value: a middleware for restify

The created middleware will extend req.params with the following:

  • req.params.username = account.id
  • req.params.user.username = account.id
  • req.params.user.tag = account.aliases.tag
  • req.params.user.name = account.aliases.name
  • req.params.user.email = account.aliases.email

It also sets req[field].username = account.id

Example

var tagizer = require('ganomede-tagizer');

var tagParam = tagizer.middleware('params', 'tag');
router.get('/blah/:tag', tagParam, getBlah);

var tagBody  = tagizer.middleware('body', 'username');
router.post('/login', tagBody, login);

Connection with ganomede-directory

The default behavior is to read environment variables:

  • DIRECTORY_PORT_8000_TCP_[ADDR|PORT|PROTOCOL] - for setting up a connection with a directory client.
  • TAG_MODE - only enable if it's a non-empty string

This behavior can be overridden by filling options, the third argument of the tagizer.middleware function, with fields:

  • host, port, protocol - for ganomede-directory connection
  • force - to enable tag-mode regardless of TAG_MODE environment variable

Example

var tagBody  = tagizer.middleware('body', 'username', {
 host: 'localhost',
 port: 8000,
 protocol: 'http',
 force: true
});

Notes

When tag-mode is disabled or fetching the account isn't possible, the middleware sets:

  • req.params.username = tag
  • req.params.user.username = tag
  • req[field].username = tag

Tag-mode Account Loader

Signature: tagizer.loader(options)

Return value: an account loader function

The account loader function takes a tag, name or id and return an object with fields: username, tag and name.

Arguments:

tagizer.loader also accepts an option object with the host, port, protocol and force fields, with similar meaning as the middleware. When not specified, the same environment variables will be used.

Example

var tagizer = require('ganomede-tagizer');
var loader = tagizer.loader();
loader(req, 'ada12', (account) => {
  console.log(`user ada12 should be displayed as #{account.name}`);
});

Notes

If tag-mode isn't enabled or retrieving the user failed, account will be set to:

  • account.username = tag
  • account.tag = tag
  • account.name= tag

Copyright

(c)2017, Fovea