Add name triple utils

This commit is contained in:
Noman 2018-09-20 02:11:58 -04:00
parent f8ab11c4c0
commit 3fb5b6bb2e
No known key found for this signature in database
GPG Key ID: ACD1C4A99857525C
6 changed files with 3139 additions and 0 deletions

5
package-lock.json generated
View File

@ -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",

View File

@ -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

View File

@ -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 };

View File

@ -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 };