Skip to content

Commit

Permalink
⚡ perf: avoid unnecessary operations
Browse files Browse the repository at this point in the history
  • Loading branch information
Rettend committed Jan 23, 2024
1 parent 2ca9fdf commit 72083b6
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 4 deletions.
3 changes: 1 addition & 2 deletions src/commands/run.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ export default defineCommand({
},
DEBUG: {
type: 'string',
description: 'Debug level (default: 0)',
description: 'Debug level (0-2)',
alias: 'd',
default: '0',
},
Expand Down Expand Up @@ -67,7 +67,6 @@ export default defineCommand({
}
else {
commitMessage = fs.readFileSync(ctx.args.commit_file, 'utf-8')

commitMessage = commitMessage.split('\n')[0] ?? ''

const newCommitMessage = eemojify(commitMessage, config, DEBUG)
Expand Down
7 changes: 5 additions & 2 deletions src/utils/emoji.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ export function eemojify(text: string, config: Config, DEBUG?: number): string {
throw new Error('Invalid commit message.')

let emoji = getEmoji(type, text, config, DEBUG)
consola.log('emoji')

if (DEBUG)
consola.log(`emoji: "${emoji}"`)
Expand All @@ -57,7 +58,8 @@ function getEmoji(type: string, text: string, config: Config, DEBUG?: number): s
if (text.includes('!') && config.emojis.breaking)
return config.emojis.breaking

const emojiKey = Object.keys(config.emojis).find(key => key.split('|').includes(type.toLowerCase().replace(/\(.*\)/, '').trim()))
type = type.toLowerCase().replace(/\(.*\)/, '').trim()
const emojiKey = Object.keys(config.emojis).find(key => key.split('|').includes(type))

if (!emojiKey)
return undefined
Expand All @@ -69,9 +71,10 @@ function getEmoji(type: string, text: string, config: Config, DEBUG?: number): s
consola.log(`nested emoji: ${JSON.stringify(emoji)}`)

const entries = Object.entries(emoji).filter(([key]) => key !== '.')
text = text.toLowerCase()

for (const [key, value] of entries) {
if (key.split('|').some(k => text.toLowerCase().includes(k.toLowerCase())))
if (key.split('|').some(k => text.includes(k.toLowerCase())))
return value
}

Expand Down

0 comments on commit 72083b6

Please sign in to comment.