Overview

HTTPS SSH

abcq

Generates character combinations from numbers: a b c ... aa ab ac ... foo fop foq

Documentation

npm Coveralls branch bitHound Overall Score Standard Version js-standard-style Commitizen friendly
Travis David David
GitHub license GitHub issues GitHub forks GitHub stars

  • Convert numbers to character combinations.
  • Count by character combination
  • Create unique ids
  • Create simple hashes
npm i abcq

Basic usage

const shortid = new abcQ()

shortid.generate()
// -> a
shortid.generate()
// -> b
shortid.encode(1234567890)
// -> clRjXk
shortid.decode('clRjXk')
// -> 1234567890

When unicorns make love

Use an Array for chars if it contains special characters. Set the counter to modify the start point

const unicornLove = new abcQ({
  chars: ['🦄','💖'],
  counter: 42
})

unicornLove.generate()
// -> 🦄💖💖🦄💖
unicornLove.encode(8)
// -> 🦄💖🦄

Use with cssmodules (+ browserify)

const browserify = require('browserify')
const cssModulesify = require('css-modulesify')
const abcQ = require('abcq')

function generator() {
  const shortid = new abcQ()
  this.names = {}
  return (name, file) => {
    const obj = this.names[file] || {}
    if (!(name in obj)) {
      obj[name] = shortid.generate()
    }
    this.names[file] = obj
    return obj[name]
  }
}

const entries = 'index.js'
const output = 'style.css'
const generateScopedName = new generator()

const b = browserify({entries})
b.plugin(cssModulesify, {output, generateScopedName})

Options

chars

  • type: { Array | String }
  • default: 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ'

counter

  • type: { Number }
  • default: -1

Methods

generate

const abc = new abcQ()
abc.generate()
// -> a
abc.generate()
// -> b

encode

const abc = new abcQ()
abc.encode(1234567890)
// -> clRjXk

decode

const abc = new abcQ()
abc.decode('clRjXk')
// -> 1234567890