Created
July 3, 2020 06:16
-
-
Save Cobertos/e78d6dc0044ed67d038b4c7bca94b2f1 to your computer and use it in GitHub Desktop.
Unminified Name Generator
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
export const PREFIXES = ["active", "auto", "app", "avi", "base", "co", "coin", "core", "clear", "wallet", "echo", "even", "ever", "fair", "go", "high", "hyper", "in", "inter", "good", "jump", "live", "make", "mass", "work", "matter", "home", "on", "one", "open", "over", "out", "buddy", "real", "peak", "pure", "money", "silver", "solid", "spark", "start", "true", "up", "vibe"]; | |
export const SUFFIXES = ["atlas", "base", "bay", "boost", "case", "center", "cast", "click", "dash", "deck", "dock", "dot", "drop", "engine", "flow", "glow", "grid", "gram", "graph", "hub", "focus", "kit", "lab", "level", "layer", "line", "logic", "load", "loop", "meet", "method", "mode", "mark", "ness", "now", "pass", "port", "post", "press", "push", "rise", "scape", "scale", "scan", "scout", "sense", "set", "shift", "ship", "side", "signal", "snap", "scope", "space", "span", "spark", "spot", "start", "storm", "stripe", "sync", "tap", "tilt", "ture", "type", "view", "verge", "vibe", "ware", "yard", "up"]; | |
export const WORD_SUFFIXES = ["ary", "able", "ance", "ible", "ice", "ite", "er", "eon", "ent", "ful", "gent", "tion", "sion"]; | |
export const ACTUAL_SUFFIXES = SUFFIXES.concat(WORD_SUFFIXES); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import sortBy from "lodash/sortBy"; | |
import gen from "random-seed"; | |
import { permutate } from "./permutate"; | |
import { score } from "./score"; | |
import { normalize } from "./normalize"; | |
export default function NameGenerator(e) { | |
var t = arguments.length > 1 && void 0 !== arguments[1] ? arguments[1] : {}; | |
"string" == typeof e && (e = e.split(" ")); | |
var r = permutate(e), | |
n = gen(t.seed || Math.random()), | |
c = function() { | |
return n.floatBetween(0, 1) | |
}; | |
return r = r.map(function(e) { | |
return { | |
word: normalize(e), | |
score: score(e, { | |
rand: c | |
}) | |
} | |
}), r = sortBy(r, function(e) { | |
e.word; | |
return -1 * e.score | |
}), r = r.map(function(e) { | |
var t = e.word; | |
e.score; | |
return t | |
}) | |
} | |
console.log(NameGenerator(process.argv[2])); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
export function normalize(e) { | |
return e.replace(/e i/, "i") | |
.replace(/th t/, "t") | |
.replace(/(.) (.)/, (e, t, r) => t === r ? t : "" + t + r) | |
.replace(/^./, (e) => e.toUpperCase()) | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"name": "thingy", | |
"version": "1.0.0", | |
"description": "", | |
"main": "index.js", | |
"scripts": { | |
"test": "echo \"Error: no test specified\" && exit 1" | |
}, | |
"author": "", | |
"license": "ISC", | |
"dependencies": { | |
"esm": "^3.2.25", | |
"lodash": "^4.17.15", | |
"random-seed": "^0.3.0", | |
"syllable": "^4.1.0" | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { PREFIXES, SUFFIXES } from "./constants"; | |
export function permutate(e) { | |
return 0 === e.length ? permutateFixes(PREFIXES, SUFFIXES) : permutateFixes(PREFIXES, e).concat(permutateFixes(e, SUFFIXES)) | |
} | |
export function permutateFixes(set1, set2) { | |
return set1.reduce(function(e, r) { | |
return set2.reduce(function(e, set2) { | |
return r === set2 ? e : e.concat([r + " " + set2]) | |
}, set1) | |
}, []) | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import syllable from "syllable"; | |
import { normalize } from "./normalize"; | |
import { ACTUAL_SUFFIXES } from "./constants"; | |
export function score(e, t) { | |
var r = t.rand, | |
n = 0; | |
return n += o(e), n += a(e), n += i(e), n += .4 * r() | |
} | |
function o(e) { | |
var t = syllable(e); | |
return 2 === t ? 6.1 : 3 === t ? 6 : t > 4 ? 2 : 4 | |
} | |
function a(e) { | |
return ACTUAL_SUFFIXES.some(function(t) { | |
return e.substr(e.length - t.length) === t | |
}) ? -1.5 : 0 | |
} | |
function i(e) { | |
return normalize(e).length < 9 ? .1 : 0 | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment