UNPKG

746 BJavaScriptView Raw
1/**
2 * Copyright 2004-present Facebook. All Rights Reserved.
3 *
4 * @format
5 */
6/* eslint no-bitwise: 0 */
7
8'use strict';
9
10const fbtJenkinsHash = require('./fbtJenkinsHash');
11
12const BaseNSymbols =
13 '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';
14
15// Compute the baseN string for a given unsigned integer.
16function uintToBaseN(number, base) {
17 if (base < 2 || base > 62 || number < 0) {
18 return '';
19 }
20 var output = '';
21 do {
22 output = BaseNSymbols.charAt(number % base).concat(output);
23 number = Math.floor(number / base);
24 } while (number > 0);
25 return output;
26}
27
28function fbtHashKey(jsfbt, desc, nostringify) {
29 return uintToBaseN(fbtJenkinsHash(jsfbt, desc, nostringify), 62);
30}
31
32module.exports = fbtHashKey;