Skip to content

Take an arbitrary string or integer and generate a short alphabetic code

License

Notifications You must be signed in to change notification settings

ForbesLindesay/generate-alphabetic-name

Repository files navigation

Generate Alphabetic Name

Take an arbitrary string or integer and generate a short alphabetic code. It works in the browser and node.js and is designed to be as small as possible, and extremely fast.

It uses the murmurhash algorithm, and borrows its implementation from the code for generating class names in styled-components

Installation

yarn add generate-alphabetic-name

Usage

import {readFileSync} from 'fs';
import generateAlphabeticName from './generateAlphabeticName';

console.log(generateAlphabeticName(readFileSync(__filename, 'utf8')));
console.log(generateAlphabeticName(42));

You can also just hash a string to a number:

import {readFileSync} from 'fs';
import {hash} from './generateAlphabeticName';

console.log(hash(readFileSync(__filename, 'utf8')));

If you prefer, you can directly reference generateAlphabeticNameFromNumber:

import {readFileSync} from 'fs';
import {hash, generateAlphabeticNameFromNumber} from './generateAlphabeticName';

console.log(
  generateAlphabeticNameFromNumber(hash(readFileSync(__filename, 'utf8'))),
);

License

MIT

About

Take an arbitrary string or integer and generate a short alphabetic code

Resources

License

Stars

Watchers

Forks

Packages

No packages published