monsterId is the Node.js implementation of monsterId PHP library. It creates a unique avatar starting from a string, typically a username, used to generate a unique seed number.
This library depends on node-gd so, in order to use monsterId, you need to have libgd installed on your system. You can follow node-gd installastion's instructions here.
To install monsterId just type the following command:
$ npm install monsterid
The usage is actually simple;
Import the library an call monsterId
function with a username to have back a binary object which represents your unique avatar 👾.
const http = require('http');
const monsterId = require('monsterId');
http.createServer(async (req, res) => {
const username = 'username';
const avatar = await monsterId(username);
res.writeHead(200, { 'Content-type': 'image/png' });
res.end(avatar, 'binary');
}).listen('8080');
monsterId
function accepts an optional configuration object that can be used to specify the desired size of the avatar:
const monsterId = require('monsterId');
const avatar = monsterId('username', {
size: 200,
});
monsterId is authored in ES6, transpiled with Babel, and exported as a CommonJS module. To transpile the src files run this command:
$ npm run build
To launch unit tests suite (with Jest) run this command:
$ npm run test
Thanks to Andreas Gohr for his job on the original library.