mirror of
https://github.com/cupcakearmy/canihazusername.git
synced 2024-12-21 23:26:25 +00:00
version 2
This commit is contained in:
parent
9cb4060617
commit
133447baa7
16
.gitignore
vendored
16
.gitignore
vendored
@ -1,6 +1,14 @@
|
||||
node_modules/
|
||||
package-lock.json
|
||||
# Editors
|
||||
.vscode
|
||||
.idea
|
||||
|
||||
test/bundle.js
|
||||
lib
|
||||
# Node
|
||||
node_modules/
|
||||
package-lock.json
|
||||
yarn.lock
|
||||
|
||||
# Build
|
||||
lib
|
||||
dist
|
||||
.cache
|
||||
src/*.js
|
@ -1,3 +1,2 @@
|
||||
*
|
||||
!lib/index.js
|
||||
!lib/canihazusername.d.ts
|
||||
!lib/*
|
1
generate/wordlist
Submodule
1
generate/wordlist
Submodule
@ -0,0 +1 @@
|
||||
Subproject commit 7cec9b716babec59b68075abf27fdfae90f51871
|
41
generate/wordlist.js
Normal file
41
generate/wordlist.js
Normal file
@ -0,0 +1,41 @@
|
||||
/* jshint esversion: 8, asi: true */
|
||||
|
||||
const fs = require('fs')
|
||||
const path = require('path')
|
||||
const util = require('util')
|
||||
|
||||
const endsWithTxt = /^.*\.txt$/
|
||||
|
||||
function walkDir(dir, callback) {
|
||||
fs.readdirSync(dir).forEach(f => {
|
||||
const dirPath = path.join(dir, f)
|
||||
const isDirectory = fs.statSync(dirPath).isDirectory()
|
||||
isDirectory
|
||||
? walkDir(dirPath, callback)
|
||||
: callback(path.join(dir, f))
|
||||
})
|
||||
}
|
||||
|
||||
function convertAndSaveWordlistAsJSON() {
|
||||
const wordlist = {}
|
||||
|
||||
walkDir('./generate/wordlist', (filename) => {
|
||||
// Not a txt file
|
||||
if (!endsWithTxt.test(filename)) return
|
||||
|
||||
// Read the file
|
||||
const file = fs.readFileSync(filename, 'utf-8')
|
||||
|
||||
// Each line of the file to an array removing the empty lines
|
||||
const lines = file.split('\n').filter(entry => entry !== '').map(entry => entry.trim())
|
||||
|
||||
// Remove duplicates
|
||||
const set = new Set(lines)
|
||||
const name = path.basename(filename, 'utf-8').slice(0, -4)
|
||||
wordlist[name] = [...set]
|
||||
})
|
||||
|
||||
fs.writeFileSync('./src/wordlist.json', JSON.stringify(wordlist))
|
||||
}
|
||||
|
||||
convertAndSaveWordlistAsJSON()
|
24
package.json
24
package.json
@ -1,21 +1,25 @@
|
||||
{
|
||||
"name": "canihazusername",
|
||||
"version": "1.0.3",
|
||||
"description": "Username Generator",
|
||||
"description": "username generator. typed, simple and customizable",
|
||||
"main": "./lib/index.js",
|
||||
"types": "./lib/canihazusername.d.ts",
|
||||
"types": "./lib/index.d.ts",
|
||||
"scripts": {
|
||||
"generate": "git -C ./generate/wordlist pull && node ./generate/wordlist.js",
|
||||
"dev": "webpack -d -w",
|
||||
"build": "webpack -p",
|
||||
"test": "mocha",
|
||||
"prepublish": "npm run build && npm run test"
|
||||
"prepublishOnly": "npm run build && npm run test"
|
||||
},
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "git+https://github.com/CupCakeArmy/canihazusername.git"
|
||||
},
|
||||
"keywords": [
|
||||
"UI"
|
||||
"username",
|
||||
"generator",
|
||||
"types",
|
||||
"customizable"
|
||||
],
|
||||
"author": "Niccolo Borgioli",
|
||||
"license": "MIT",
|
||||
@ -25,12 +29,8 @@
|
||||
"homepage": "https://github.com/CupCakeArmy/canihazusername#readme",
|
||||
"dependencies": {},
|
||||
"devDependencies": {
|
||||
"awesome-typescript-loader": "^5.2.1",
|
||||
"dts-bundle": "^0.7.3",
|
||||
"dts-bundle-webpack": "^1.0.2",
|
||||
"mocha": "^5.2.0",
|
||||
"typescript": "^3.2.4",
|
||||
"webpack": "^4.29.0",
|
||||
"webpack-cli": "^3.2.1"
|
||||
"parcel-bundler": "^1.12.4",
|
||||
"ts-node-dev": "^1.0.0-pre.44",
|
||||
"typescript": "3.7"
|
||||
}
|
||||
}
|
||||
}
|
34
src/index.ts
34
src/index.ts
@ -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
|
@ -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
1
src/wordlist.json
Normal file
File diff suppressed because one or more lines are too long
@ -1,8 +0,0 @@
|
||||
const assert = require('assert')
|
||||
const cihu = require('../lib/index').default
|
||||
|
||||
describe('Array', () => {
|
||||
it('Should return a string', () => {
|
||||
assert.equal(typeof cihu(), 'string')
|
||||
})
|
||||
})
|
@ -1,21 +1,30 @@
|
||||
{
|
||||
"compilerOptions": {
|
||||
"outDir": "./lib",
|
||||
"target": "es6",
|
||||
"module": "commonjs",
|
||||
"declaration": true,
|
||||
"declarationMap": false,
|
||||
"sourceMap": false,
|
||||
"outDir": "./lib",
|
||||
"rootDir": "./src",
|
||||
"removeComments": true,
|
||||
"strict": true,
|
||||
"noImplicitAny": true,
|
||||
"strictNullChecks": true,
|
||||
"removeComments": true,
|
||||
"declaration": true,
|
||||
"sourceMap": true,
|
||||
"noEmit": true,
|
||||
"jsx": "react"
|
||||
"strictFunctionTypes": true,
|
||||
"strictBindCallApply": true,
|
||||
"strictPropertyInitialization": true,
|
||||
"noImplicitThis": true,
|
||||
"alwaysStrict": true,
|
||||
// "noUnusedLocals": true,
|
||||
// "noUnusedParameters": true,
|
||||
"noImplicitReturns": true,
|
||||
"noFallthroughCasesInSwitch": true,
|
||||
"esModuleInterop": true,
|
||||
"resolveJsonModule": true,
|
||||
"forceConsistentCasingInFileNames": true
|
||||
},
|
||||
"include": [
|
||||
"./src/**/*.tsx",
|
||||
"./src/**/*.ts"
|
||||
],
|
||||
"exclude": [
|
||||
"node_modules"
|
||||
"./src"
|
||||
]
|
||||
}
|
@ -1,17 +0,0 @@
|
||||
const common = {
|
||||
stats: {
|
||||
assets: true,
|
||||
assetsSort: 'size',
|
||||
all: false,
|
||||
errors: true,
|
||||
colors: true,
|
||||
performance: true,
|
||||
timings: true,
|
||||
},
|
||||
}
|
||||
|
||||
const src = require('./src/webpack.config.js')
|
||||
|
||||
module.exports = [
|
||||
Object.assign({}, common, src),
|
||||
]
|
8
website/index.html
Normal file
8
website/index.html
Normal file
@ -0,0 +1,8 @@
|
||||
<!DOCTYPE html>
|
||||
<html>
|
||||
|
||||
<body>
|
||||
<script src="./main.ts"></script>
|
||||
</body>
|
||||
|
||||
</html>
|
3
website/main.ts
Normal file
3
website/main.ts
Normal file
@ -0,0 +1,3 @@
|
||||
import cihu from '../'
|
||||
|
||||
console.log(cihu())
|
Loading…
Reference in New Issue
Block a user