How to use any-base - 10 common examples

To help you get started, we’ve selected a few any-base examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github oculus42 / short-uuid / index.js View on Github external
function MakeConvertor(toAlphabet) {

        // Default to Flickr 58
        var useAlphabet = toAlphabet || flickrBase58;

        // UUIDs are in hex, so we translate to and from.
        var fromHex = anyBase(anyBase.HEX, useAlphabet);
        var toHex = anyBase(useAlphabet, anyBase.HEX);

        return {
            new: function() { return shortenUUID(uuidV4(), fromHex); },
            uuid: uuidV4,
            fromUUID: function(uuid) { return shortenUUID(uuid, fromHex); },
            toUUID: function(shortUuid) { return enlargeUUID(shortUuid, toHex); },
            alphabet: useAlphabet
        };
    }
github oculus42 / short-uuid / index.js View on Github external
function MakeConvertor(toAlphabet) {

        // Default to Flickr 58
        var useAlphabet = toAlphabet || flickrBase58;

        // UUIDs are in hex, so we translate to and from.
        var fromHex = anyBase(anyBase.HEX, useAlphabet);
        var toHex = anyBase(useAlphabet, anyBase.HEX);

        return {
            new: function() { return shortenUUID(uuidV4(), fromHex); },
            uuid: uuidV4,
            fromUUID: function(uuid) { return shortenUUID(uuid, fromHex); },
            toUUID: function(shortUuid) { return enlargeUUID(shortUuid, toHex); },
            alphabet: useAlphabet
        };
    }
github oliver-moran / jimp / packages / core / src / index.js View on Github external
import composite from './composite';
import promisify from './utils/promisify';
import * as MIME from './utils/mime';
import { parseBitmap, getBuffer, getBufferAsync } from './utils/image-bitmap';
import * as constants from './constants';

const alphabet =
  '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ$_';

// an array storing the maximum string length of hashes at various bases
// 0 and 1 do not exist as possible hash lengths
const maxHashLength = [NaN, NaN];

for (let i = 2; i < 65; i++) {
  const maxHash = anyBase(anyBase.BIN, alphabet.slice(0, i))(
    new Array(64 + 1).join('1')
  );
  maxHashLength.push(maxHash.length);
}

// no operation
function noop() {}

// error checking methods

function isArrayBuffer(test) {
  return (
    Object.prototype.toString
      .call(test)
      .toLowerCase()
      .indexOf('arraybuffer') > -1
github oliver-moran / jimp / packages / core / src / index.js View on Github external
}

    if (typeof base !== 'number') {
      return throwError.call(this, 'base must be a number', cb);
    }

    if (base < 2 || base > 64) {
      return throwError.call(
        this,
        'base must be a number between 2 and 64',
        cb
      );
    }

    let hash = this.pHash();
    hash = anyBase(anyBase.BIN, alphabet.slice(0, base))(hash);

    while (hash.length < maxHashLength[base]) {
      hash = '0' + hash; // pad out with leading zeros
    }

    if (isNodePattern(cb)) {
      cb.call(this, null, hash);
    }

    return hash;
  }
github qoomon / otp-authenticator-webapp / bundle.js View on Github external
(function e(t,n,r){function s(o,u){if(!n[o]){if(!t[o]){var a=typeof require=="function"&&require;if(!u&&a)return a(o,!0);if(i)return i(o,!0);var f=new Error("Cannot find module '"+o+"'");throw f.code="MODULE_NOT_FOUND",f}var l=n[o]={exports:{}};t[o][0].call(l.exports,function(e){var n=t[o][1][e];return s(n?n:e)},l,l.exports,e,t,n,r)}return n[o].exports}var i=typeof require=="function"&&require;for(var o=0;o= minLength) {
       return str
   }
   return pad.repeat(minLength - str.length) + str;
};

function getTotp(secretBase32){
  var stepSeconds = 30;
  var secretHex = base32ToHex(secretBase32);
  var epochSeconds = Math.floor(new Date().getTime() / 1000.0);
  var timeHex = decToHex(String(Math.floor(epochSeconds / stepSeconds)))
  var timeHexPadded = leftPad(timeHex, 16, '0');
github ticky / markdown-component-loader / src / lowercase-hash.js View on Github external
export default (content) => (
  anyBase(anyBase.HEX, 'abcdefghijklmnopqrstuvwxyz')(
    new SHA256()
      .update(content, 'utf-8')
      .digest('hex')
  )
);
github qoomon / otp-authenticator-webapp / bundle.js View on Github external
(function e(t,n,r){function s(o,u){if(!n[o]){if(!t[o]){var a=typeof require=="function"&&require;if(!u&&a)return a(o,!0);if(i)return i(o,!0);var f=new Error("Cannot find module '"+o+"'");throw f.code="MODULE_NOT_FOUND",f}var l=n[o]={exports:{}};t[o][0].call(l.exports,function(e){var n=t[o][1][e];return s(n?n:e)},l,l.exports,e,t,n,r)}return n[o].exports}var i=typeof require=="function"&&require;for(var o=0;o= minLength) {
       return str
   }
   return pad.repeat(minLength - str.length) + str;
};

function getTotp(secretBase32){
  var stepSeconds = 30;
  var secretHex = base32ToHex(secretBase32);
  var epochSeconds = Math.floor(new Date().getTime() / 1000.0);
  var timeHex = decToHex(String(Math.floor(epochSeconds / stepSeconds)))
  var timeHexPadded = leftPad(timeHex, 16, '0');
  var shaObj = new jsSHA("SHA-1", "HEX");
  shaObj.setHMACKey(secretHex, "HEX");
github seek-oss / treat / packages / treat / webpack-plugin / AllocationHandler.js View on Github external
const anyBase = require('any-base');
const { writeManifest, readManifest } = require('./manifest');

const validClassCharacters = `abcdefghijklmnopqrstuvwxyz${anyBase.DEC}`;

const decToIdent = anyBase(anyBase.DEC, validClassCharacters);

const SEP = '?';

module.exports = class AllocationHandler {
  constructor({ manifestFile }) {
    this.newAllocations = false;
    this.allocations = [];
    this.manifestFile = manifestFile;

    this.enableNewAllocations = this.enableNewAllocations.bind(this);
    this.purgeAllocations = this.purgeAllocations.bind(this);
    this.getAllocationKey = this.getAllocationKey.bind(this);
    this.getAllocationIndex = this.getAllocationIndex.bind(this);
    this.allocate = this.allocate.bind(this);
    this.getAllocationIdent = this.getAllocationIdent.bind(this);
    this.getAllocations = this.getAllocations.bind(this);
github seek-oss / treat / packages / treat / webpack-plugin / AllocationHandler.js View on Github external
const anyBase = require('any-base');
const { writeManifest, readManifest } = require('./manifest');

const validClassCharacters = `abcdefghijklmnopqrstuvwxyz${anyBase.DEC}`;

const decToIdent = anyBase(anyBase.DEC, validClassCharacters);

const SEP = '?';

module.exports = class AllocationHandler {
  constructor({ manifestFile }) {
    this.newAllocations = false;
    this.allocations = [];
    this.manifestFile = manifestFile;

    this.enableNewAllocations = this.enableNewAllocations.bind(this);
    this.purgeAllocations = this.purgeAllocations.bind(this);
    this.getAllocationKey = this.getAllocationKey.bind(this);
    this.getAllocationIndex = this.getAllocationIndex.bind(this);
    this.allocate = this.allocate.bind(this);

any-base

Converter from any base to other any base

MIT
Latest version published 7 years ago

Package Health Score

65 / 100
Full package analysis