Socket
Socket
Sign inDemoInstall

abcq

Package Overview
Dependencies
0
Maintainers
1
Versions
13
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    abcq

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


Version published
Weekly downloads
532
increased by33.33%
Maintainers
1
Created
Weekly downloads
 

Readme

Source

abcq

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

Documentation

npm Coveralls branch ![Bithound Code](https://img.shields.io/bithound/code/github/pixelass/abcq.svg 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

FAQs

Last updated on 22 Sep 2016

Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc