Add name triple utils
This commit is contained in:
parent
f8ab11c4c0
commit
3fb5b6bb2e
|
@ -1276,6 +1276,11 @@
|
|||
"supports-color": "^2.0.0"
|
||||
}
|
||||
},
|
||||
"chance": {
|
||||
"version": "1.0.16",
|
||||
"resolved": "https://registry.npmjs.org/chance/-/chance-1.0.16.tgz",
|
||||
"integrity": "sha512-2bgDHH5bVfAXH05SPtjqrsASzZ7h90yCuYT2z4mkYpxxYvJXiIydBFzVieVHZx7wLH1Ag2Azaaej2/zA1XUrNQ=="
|
||||
},
|
||||
"chardet": {
|
||||
"version": "0.7.0",
|
||||
"resolved": "https://registry.npmjs.org/chardet/-/chardet-0.7.0.tgz",
|
||||
|
|
|
@ -20,6 +20,7 @@
|
|||
"eslint-plugin-react": "^7.10.0"
|
||||
},
|
||||
"dependencies": {
|
||||
"chance": "^1.0.16",
|
||||
"matrix-appservice-bridge": "^1.6.1",
|
||||
"matrix-js-sdk": "^0.10.9",
|
||||
"npm": "^6.4.1",
|
||||
|
|
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
|
@ -0,0 +1,27 @@
|
|||
const adjectives = require('./adjectives');
|
||||
const animals = require('./animals');
|
||||
const { randGen, seededRandNth } = require('./random');
|
||||
|
||||
const pickRandom = (gen, vector) => seededRandNth(gen, vector);
|
||||
|
||||
const buildGfy = publicKey => {
|
||||
const gen = randGen(publicKey);
|
||||
const firstAdjective = pickRandom(gen, adjectives);
|
||||
const secondAdjective = pickRandom(gen, adjectives);
|
||||
const animal = pickRandom(gen, animals);
|
||||
return `${firstAdjective} ${secondAdjective} ${animal}`;
|
||||
};
|
||||
|
||||
const generateGfy = publicKey => {
|
||||
if (publicKey === null || publicKey === '0') {
|
||||
return 'Unknown';
|
||||
}
|
||||
|
||||
if (typeof publicKey === 'undefined') {
|
||||
return buildGfy(new Date().getTime());
|
||||
}
|
||||
|
||||
return buildGfy(publicKey);
|
||||
};
|
||||
|
||||
module.exports = { generateGfy };
|
|
@ -0,0 +1,9 @@
|
|||
const Chance = require('chance');
|
||||
|
||||
const randGen = seed => new Chance(seed);
|
||||
|
||||
const seededRandInt = (gen, n) => gen.integer({ min: 0, max: n - 1 });
|
||||
|
||||
const seededRandNth = (gen, coll) => coll[seededRandInt(gen, coll.length)];
|
||||
|
||||
module.exports = { randGen, seededRandNth };
|
Loading…
Reference in New Issue