-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Auto-populate the first title if none are chosen
- Loading branch information
Showing
3 changed files
with
97 additions
and
10 deletions.
There are no files selected for viewing
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
legacy-peer-deps=true |
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
import { faker } from "@faker-js/faker" | ||
import _ from "lodash" | ||
|
||
const INCLUDED_TYPES = ['smiley', 'nature'] as const | ||
|
||
|
||
const FILTERED_EMOJIS = new Set([ | ||
'💋', | ||
'🗨️', | ||
'😏', | ||
'😫', | ||
'💮', | ||
'🤮', | ||
'🥵', | ||
'💦' | ||
|
||
]) | ||
const FILTERED_PREPOSITIONS = new Set([ | ||
'abaft', | ||
'amid', | ||
'anti', | ||
'afore', | ||
'aside', | ||
'anenst', | ||
'apropros', | ||
'apud', | ||
'circa', | ||
'lest', | ||
'mid', | ||
'midst', | ||
'pace', | ||
'qua', | ||
'sans', | ||
'save', | ||
'vice' | ||
]) | ||
|
||
const getEmoji = () => { | ||
let emoji: string = '' | ||
while (emoji === '' || FILTERED_EMOJIS.has(emoji)) { | ||
emoji = faker.internet.emoji({ types: INCLUDED_TYPES }) | ||
} | ||
return emoji | ||
} | ||
const getPreposition = () => { | ||
let prep: string = '' | ||
while (prep === '' || FILTERED_PREPOSITIONS.has(prep)) { | ||
prep = faker.word.preposition({ length: { min: 2, max: 5 } }) | ||
} | ||
return prep | ||
} | ||
|
||
const generatePrepTitle = () => { | ||
const emoji1 = getEmoji() | ||
const prep = getPreposition() | ||
const emoji2 = getEmoji() | ||
return `${emoji1} ${prep} ${emoji2}` | ||
} | ||
|
||
const generateAdjectiveTitle = () => { | ||
const emoji1 = getEmoji() | ||
const adjective = faker.word.adjective({length: { min: 1, max: 5}}) | ||
return _.startCase(`${adjective} ${emoji1}`) | ||
} | ||
|
||
const generateEmojiTitle = () => { | ||
const numberOfEmoji = faker.number.int({ min: 1, max: 3}) | ||
return Array.from({ length: numberOfEmoji }).map( | ||
() => getEmoji() | ||
).join('') | ||
} | ||
|
||
export const generateTitleOptions = (length: number = 6) => { | ||
const options = Array.from({ length }).map((_, i) => { | ||
if (i % 3 === 0) { | ||
return generatePrepTitle() | ||
} else if (i % 2 === 0) { | ||
return generateAdjectiveTitle() | ||
} else { | ||
return generateEmojiTitle() | ||
} | ||
}) | ||
return options | ||
} |