UNPKG

typed-catch-of-the-day

Version:

typescript version of wes bos' catch of the day app

36 lines (28 loc) 1.72 kB
interface HelpersInterface { formatPrice(cents: number); rando(arr: Array<string>); slugify(text: string); getFunName(); } class helpers implements HelpersInterface { formatPrice(cents: number) { return "$" + ( (cents / 100).toFixed(2).replace(/\B(?=(\d{3})+(?!\d))/g, ",") ); } rando(arr: Array<string>) { return arr[Math.floor(Math.random() * arr.length)]; } slugify(text: string) { return text.toString().toLowerCase() .replace(/\s+/g, "-") // Replace spaces with - .replace(/[^\w\-]+/g, "") // Remove all non-word chars .replace(/\-\-+/g, "-") // Replace multiple - with single - .replace(/^-+/, "") // Trim - from start of text .replace(/-+$/, ""); // Trim - from end of text } getFunName() { var adjectives = ["adorable", "beautiful", "clean", "drab", "elegant", "fancy", "glamorous", "handsome", "long", "magnificent", "old-fashioned", "plain", "quaint", "sparkling", "ugliest", "unsightly", "angry", "bewildered", "clumsy", "defeated", "embarrassed", "fierce", "grumpy", "helpless", "itchy", "jealous", "lazy", "mysterious", "nervous", "obnoxious", "panicky", "repulsive", "scary", "thoughtless", "uptight", "worried"]; var nouns = ["women", "men", "children", "teeth", "feet", "people", "leaves", "mice", "geese", "halves", "knives", "wives", "lives", "elves", "loaves", "potatoes", "tomatoes", "cacti", "foci", "fungi", "nuclei", "syllabuses", "analyses", "diagnoses", "oases", "theses", "crises", "phenomena", "criteria", "data"]; return `${this.rando(adjectives)}-${this.rando(adjectives)}-${this.rando(nouns)}`; } } export default helpers;