Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: allow using the source text as a keygen strategy #794

Merged
merged 2 commits into from
Aug 27, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -1132,7 +1132,8 @@
"enum": [
"slug",
"random",
"empty"
"empty",
"source"
],
"description": "%config.keygen_strategy%"
},
Expand Down
5 changes: 4 additions & 1 deletion src/core/Extract.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,14 +26,17 @@ export function generateKeyFromText(text: string, filepath?: string, reuseExisti
else if (keygenStrategy === 'empty') {
key = ''
}
else if (keygenStrategy === 'source') {
key = text
}
else {
text = text.replace(/\$/g, '')
key = limax(text, { separator: Config.preferredDelimiter, tone: false })
.slice(0, Config.extractKeyMaxLength ?? Infinity)
}

const keyPrefix = Config.keyPrefix
if (keyPrefix && keygenStrategy !== 'empty')
if (keyPrefix && keygenStrategy !== 'empty' && keygenStrategy !== 'source')
key = keyPrefix + key

if (filepath && key.includes('fileName')) {
Expand Down