How to use base62 - 10 common examples

To help you get started, we’ve selected a few base62 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 d4l3k / WebSync / lib / routes.js View on Github external
function wsConnection(ws) {
  console.log('Connection: ', ws.upgradeReq.url);
  var url = ws.upgradeReq.url;
  var base = url.split('?')[0];
  var parts = base.split('/');
  console.log(parts);
  // strip off websockets/ from the path
  parts.shift();
  ws.docId = Base62.decode(parts[1]);
  if (parts[2] !== 'edit' && parts[2] !== 'view') {
    return;
  }

  // Helper Functions
  ws.sendJSON = function(json) {
    this.send(JSON.stringify(json), function(err) {
      if (err) {
        console.error('WS ERROR', err);
      }
    });
  };
  ws.error = function(msg) {
    ws.sendJSON({
      type: 'error',
      reason: msg
github OpenUserJS / OpenUserJS.org / controllers / scriptStorage.js View on Github external
if (!aScript) {
        aNext();
        return;
      }

      // HTTP/1.1 Caching
      aRes.set('Cache-Control', 'public, max-age=' + maxAge +
        ', no-cache, no-transform, must-revalidate');

      script = modelParser.parseScript(aScript);
      meta = script.meta; // NOTE: Watchpoint

      if (/\.json$/.test(aReq.params.scriptname)) {
        // Create a based representation of the hex sha512sum
        eTag = '"'  + Base62.encode(parseInt('0x' + aScript.hash, 16)) + ' .meta.json"';

        // If already client-side... HTTP/1.1 Caching
        if (aReq.get('if-none-match') === eTag) {
          aRes.status(304).send(); // Not Modified
          return;
        }

        // Okay to send .meta.json...
        aRes.set('Content-Type', 'application/json; charset=UTF-8');

        // HTTP/1.0 Caching
        aRes.set('Expires', moment(moment() + maxAge * 1000).utc()
          .format('ddd, DD MMM YYYY HH:mm:ss') + ' GMT');

        // HTTP/1.1 Caching
        aRes.set('Etag', eTag);
github Morgul / rpgkeeper / server / routes / users.js View on Github external
function generateToken()
{
    return base62.encode(new Buffer(uuid.v4(null, [])).readUInt32LE(0));
} // end generateToken
github ampproject / amphtml / build-system / babel-plugins / babel-plugin-transform-log-methods / index.js View on Github external
function getOrCreateMessageId(message) {
    if (message in messages) {
      return messages[message].id;
    }
    const id = base62ascii.encode(nextMessageId++); // [0-9a-zA-Z]
    messages[message] = {id, message};
    return id;
  }
github mozilla / addons-frontend / src / amo / utils / index.js View on Github external
export function getDjangoBase62() {
  // This is the alphabet used by Django.
  base62.setCharacterSet(
    '0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz',
  );
  return base62;
}
github oame / nazr.in / test / url-service.spec.js View on Github external
test.serial('shorten url and retrieve its decoded value', async t => {
  const res = await urlService.shortenURL(testURL)
  t.is(res.url, testURL)
  t.is(res.base62, Base62.encode(res.numerical_id))

  const receivedURL = await urlService.getURL(res.base62)
  t.is(receivedURL.url, testURL)
  t.is(receivedURL.numerical_id, res.numerical_id)
})
github oame / nazr.in / packages / api / src / services / url-service.js View on Github external
export async function shortenURL(url) {
  if (!isURL(url)) {
    throw new Error('Invalid URL provided')
  }

  if (url.indexOf('//nazr.in') > -1) {
    throw new Error('URLs contain nazr.in can not to be shortened')
  }

  const shortLink = new ShortLink()
  await shortLink.save()
  shortLink.url = url
  shortLink.base62 = base64Encode(shortLink.numerical_id)
  await shortLink.save()
  return shortLink
}
github Lapple / ErrorBoard / node_modules / react-tools / node_modules / jstransform / visitors / es6-class-visitors.js View on Github external
function _generateAnonymousClassName(state) {
  var mungeNamespace = state.mungeNamespace || '';
  return '____Class' + mungeNamespace + base62.encode(_anonClassUUIDCounter++);
}
github Lapple / ErrorBoard / node_modules / react-tools / node_modules / jstransform / visitors / es6-class-visitors.js View on Github external
function _getMungedName(identName, state) {
  var mungeNamespace = state.mungeNamespace;
  var shouldMinify = state.g.opts.minify;

  if (shouldMinify) {
    if (!_mungedSymbolMaps[mungeNamespace]) {
      _mungedSymbolMaps[mungeNamespace] = {
        symbolMap: {},
        identUUIDCounter: 0
      };
    }

    var symbolMap = _mungedSymbolMaps[mungeNamespace].symbolMap;
    if (!symbolMap[identName]) {
      symbolMap[identName] =
        base62.encode(_mungedSymbolMaps[mungeNamespace].identUUIDCounter++);
    }
    identName = symbolMap[identName];
  }
  return '$' + mungeNamespace + identName;
}
github andrewshawcare / thoughtworks-email-signature-generator / node_modules / jsxhint / node_modules / jstransform / visitors / es6-class-visitors.js View on Github external
function _generateAnonymousClassName(state) {
  var mungeNamespace = state.mungeNamespace || '';
  return '____Class' + mungeNamespace + base62.encode(_anonClassUUIDCounter++);
}

base62

JavaScript Base62 encode/decoder

MIT
Latest version published 7 months ago

Package Health Score

80 / 100
Full package analysis