version 2

This commit is contained in:
2020-02-05 21:21:51 +01:00
parent 9cb4060617
commit 133447baa7
13 changed files with 126 additions and 95 deletions

View File

@@ -1,12 +1,32 @@
const animals: string[] = ['Aardvark', 'Abyssinian', 'Affenpinscher', 'Akbash', 'Akita', 'Albatross', 'Alligator', 'Alpaca', 'Angelfish', 'Ant', 'Anteater', 'Antelope', 'Ape', 'Armadillo', 'Ass', 'Avocet', 'Axolotl', 'Baboon', 'Badger', 'Balinese', 'Bandicoot', 'Barb', 'Barnacle', 'Barracuda', 'Bat', 'Beagle', 'Bear', 'Beaver', 'Bee', 'Beetle', 'Binturong', 'Bird', 'Birman', 'Bison', 'Bloodhound', 'Boar', 'Bobcat', 'Bombay', 'Bongo', 'Bonobo', 'Booby', 'Budgerigar', 'Buffalo', 'Bulldog', 'Bullfrog', 'Burmese', 'Butterfly', 'Caiman', 'Camel', 'Capybara', 'Caracal', 'Caribou', 'Cassowary', 'Cat', 'Caterpillar', 'Catfish', 'Cattle', 'Centipede', 'Chameleon', 'Chamois', 'Cheetah', 'Chicken', 'Chihuahua', 'Chimpanzee', 'Chinchilla', 'Chinook', 'Chipmunk', 'Chough', 'Cichlid', 'Clam', 'Coati', 'Cobra', 'Cockroach', 'Cod', 'Collie', 'Coral', 'Cormorant', 'Cougar', 'Cow', 'Coyote', 'Crab', 'Crane', 'Crocodile', 'Crow', 'Curlew', 'Cuscus', 'Cuttlefish', 'Dachshund', 'Dalmatian', 'Deer', 'Dhole', 'Dingo', 'Dinosaur', 'Discus', 'Dodo', 'Dog', 'Dogfish', 'Dolphin', 'Donkey', 'Dormouse', 'Dotterel', 'Dove', 'Dragonfly', 'Drever', 'Duck', 'Dugong', 'Dunker', 'Dunlin', 'Eagle', 'Earwig', 'Echidna', 'Eel', 'Eland', 'Elephant', 'Elephant seal', 'Elk', 'Emu', 'Falcon', 'Ferret', 'Finch', 'Fish', 'Flamingo', 'Flounder', 'Fly', 'Fossa', 'Fox', 'Frigatebird', 'Frog', 'Galago', 'Gar', 'Gaur', 'Gazelle', 'Gecko', 'Gerbil', 'Gharial', 'Giant Panda', 'Gibbon', 'Giraffe', 'Gnat', 'Gnu', 'Goat', 'Goldfinch', 'Goldfish', 'Goose', 'Gopher', 'Gorilla', 'Goshawk', 'Grasshopper', 'Greyhound', 'Grouse', 'Guanaco', 'Guinea fowl', 'Guinea pig', 'Gull', 'Guppy', 'Hamster', 'Hare', 'Harrier', 'Havanese', 'Hawk', 'Hedgehog', 'Heron', 'Herring', 'Himalayan', 'Hippopotamus', 'Hornet', 'Horse', 'Human', 'Hummingbird', 'Hyena', 'Ibis', 'Iguana', 'Impala', 'Indri', 'Insect', 'Jackal', 'Jaguar', 'Javanese', 'Jay', 'Jay, Blue', 'Jellyfish', 'Kakapo', 'Kangaroo', 'Kingfisher', 'Kiwi', 'Koala', 'Komodo dragon', 'Kouprey', 'Kudu', 'Labradoodle', 'Ladybird', 'Lapwing', 'Lark', 'Lemming', 'Lemur', 'Leopard', 'Liger', 'Lion', 'Lionfish', 'Lizard', 'Llama', 'Lobster', 'Locust', 'Loris', 'Louse', 'Lynx', 'Lyrebird', 'Macaw', 'Magpie', 'Mallard', 'Maltese', 'Manatee', 'Mandrill', 'Markhor', 'Marten', 'Mastiff', 'Mayfly', 'Meerkat', 'Millipede', 'Mink', 'Mole', 'Molly', 'Mongoose', 'Mongrel', 'Monkey', 'Moorhen', 'Moose', 'Mosquito', 'Moth', 'Mouse', 'Mule', 'Narwhal', 'Neanderthal', 'Newfoundland', 'Newt', 'Nightingale', 'Numbat', 'Ocelot', 'Octopus', 'Okapi', 'Olm', 'Opossum', 'Orang-utan', 'Oryx', 'Ostrich', 'Otter', 'Owl', 'Ox', 'Oyster', 'Pademelon', 'Panther', 'Parrot', 'Partridge', 'Peacock', 'Peafowl', 'Pekingese', 'Pelican', 'Penguin', 'Persian', 'Pheasant', 'Pig', 'Pigeon', 'Pika', 'Pike', 'Piranha', 'Platypus', 'Pointer', 'Pony', 'Poodle', 'Porcupine', 'Porpoise', 'Possum', 'Prairie Dog', 'Prawn', 'Puffin', 'Pug', 'Puma', 'Quail', 'Quelea', 'Quetzal', 'Quokka', 'Quoll', 'Rabbit', 'Raccoon', 'Ragdoll', 'Rail', 'Ram', 'Rat', 'Rattlesnake', 'Raven', 'Red deer', 'Red panda', 'Reindeer', 'Rhinoceros', 'Robin', 'Rook', 'Rottweiler', 'Ruff', 'Salamander', 'Salmon', 'Sand Dollar', 'Sandpiper', 'Saola', 'Sardine', 'Scorpion', 'Sea lion', 'Sea Urchin', 'Seahorse', 'Seal', 'Serval', 'Shark', 'Sheep', 'Shrew', 'Shrimp', 'Siamese', 'Siberian', 'Skunk', 'Sloth', 'Snail', 'Snake', 'Snowshoe', 'Somali', 'Sparrow', 'Spider', 'Sponge', 'Squid', 'Squirrel', 'Starfish', 'Starling', 'Stingray', 'Stinkbug', 'Stoat', 'Stork', 'Swallow', 'Swan', 'Tang', 'Tapir', 'Tarsier', 'Termite', 'Tetra', 'Tiffany', 'Tiger', 'Toad', 'Tortoise', 'Toucan', 'Tropicbird', 'Trout', 'Tuatara', 'Turkey', 'Turtle', 'Uakari', 'Uguisu', 'Umbrellabird', 'Vicuña', 'Viper', 'Vulture', 'Wallaby', 'Walrus', 'Warthog', 'Wasp', 'Water buffalo', 'Weasel', 'Whale', 'Whippet', 'Wildebeest', 'Wolf', 'Wolverine', 'Wombat', 'Woodcock', 'Woodlouse', 'Woodpecker', 'Worm', 'Wrasse', 'Wren', 'Yak', 'Zebra', 'Zebu', 'Zonkey', 'Zorse']
// const colors = ['amber', 'ash', 'asphalt', 'auburn', 'avocado', 'aquamarine', 'azure', 'beige', 'bisque', 'black', 'blue', 'bone', 'bordeaux', 'brass', 'bronze', 'brown', 'burgundy', 'camel', 'caramel', 'canary', 'celeste', 'cerulean', 'champagne', 'charcoal', 'chartreuse', 'chestnut', 'chocolate', 'citron', 'claret', 'coal', 'cobalt', 'coffee', 'coral', 'corn', 'cream', 'crimson', 'cyan', 'denim', 'desert', 'ebony', 'ecru', 'emerald', 'feldspar', 'fuchsia', 'gold', 'gray', 'green', 'heather', 'indigo', 'ivory', 'jet', 'khaki', 'lime', 'magenta', 'maroon', 'mint', 'navy', 'olive', 'orange', 'pink', 'plum', 'purple', 'red', 'rust', 'salmon', 'sienna', 'silver', 'snow', 'steel', 'tan', 'teal', 'tomato', 'violet', 'white', 'yellow']
const characters: string[] = ['accepting', 'adventurous', 'affable', 'ambitious', 'amiable', 'amicable', 'annoying', 'bold', 'brave', 'bright', 'brutal', 'brute', 'callous', 'calm', 'careful', 'cautious', 'charitable', 'cheerful', 'clever', 'courtly', 'creative', 'cruel', 'curious', 'daring', 'devout', 'eager', 'elegant', 'energetic', 'excited', 'ferocious', 'forgiving', 'free', 'friendly', 'funny', 'generous', 'genteel', 'gentle', 'graceful', 'grim', 'grouchy', 'happy', 'heartless', 'helpful', 'honest', 'humane', 'humble', 'impulsive', 'independent', 'indulgent', 'intense', 'inventive', 'kind', 'lazy', 'lenient', 'loyal', 'meek', 'merciless', 'merry', 'messy', 'mild', 'neat', 'nervous', 'obliging', 'obnoxious', 'odious', 'patient', 'plain', 'pleasant', 'polite', 'proper', 'proud', 'quick', 'quiet', 'refined', 'relaxed', 'religious', 'respectful', 'rude', 'savage', 'selfish', 'sensitive', 'serious', 'shrewd', 'silly', 'simple', 'smart', 'soft', 'sophisticated', 'sophisticated', 'stern', 'strong', 'stubborn', 'tender', 'tense', 'timid', 'tough', 'trusting', 'urbane', 'vain', 'vicious', 'violent', 'warm', 'wise', 'witty']
import wordlist from './wordlist.json'
const randomElementFromArray = <T>(arr: T[]): T => arr[Math.floor(Math.random() * arr.length)]
const safeString = (s: string): string => s.toLowerCase().replace(/ /, '')
const canIHazUsername = (delimiter: string = '-'): string => {
return safeString(randomElementFromArray(characters) + delimiter + randomElementFromArray(animals))
export const showAvailableLists = () => {
const keys = Object.keys(wordlist)
console.log(keys)
return keys
}
export default canIHazUsername
export const generate = (format: string = '{character}_{english}', maxReformats = 16): string => {
for (let i = 0; i < maxReformats; i++) {
const match = /\{.*?\}/.exec(format)
if (match === null) break
const keys = match[0]
.slice(1, -1)
.split('|')
.map(key => key.trim())
.filter(key => key !== '') as [keyof typeof wordlist]
const lists = keys.map(key => Array.isArray(wordlist[key]) ? wordlist[key] : [])
const flatteded = lists.reduce((acc, val) => acc.concat(val), []);
const value: string = flatteded.length > 0
? randomElementFromArray(flatteded)
: ''
format = format.replace(match[0], value)
}
return format
}
export default generate

View File

@@ -1,34 +0,0 @@
const webpack = require('webpack')
const path = require('path')
const DtsBundleWebpack = require('dts-bundle-webpack')
module.exports = {
context: `${__dirname}`,
target: 'node',
entry: [
`./index.ts`,
],
output: {
path: `${__dirname}/../lib`,
filename: 'index.js',
libraryTarget: 'umd',
},
resolve: {
extensions: ['.js', '.jsx', '.ts', '.tsx'],
},
optimization: {
minimize: true,
},
module: {
rules: [{
test: /\.tsx?$/,
loader: 'awesome-typescript-loader'
}, ],
},
plugins: [
new DtsBundleWebpack({
name: 'canihazusername',
main: `./lib/index.d.ts`
})
],
}

1
src/wordlist.json Normal file

File diff suppressed because one or more lines are too long