Skip to content

Commit

Permalink
refactor: replace RegExp with replaceAll
Browse files Browse the repository at this point in the history
  • Loading branch information
KSXGitHub committed Feb 2, 2024
1 parent accadf0 commit 6bc1a75
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 8 deletions.
4 changes: 2 additions & 2 deletions lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -243,9 +243,9 @@ const log = (args, shell) => {
let lines = args.map(item => completionItem(item, shell)).map(item => {
const { name: rawName, description: rawDescription } = item;

const name = shell === 'zsh' ? rawName?.replace(/:/g, '\\:') : rawName;
const name = shell === 'zsh' ? rawName?.replaceAll(':', '\\:') : rawName;
const description =
shell === 'zsh' ? rawDescription?.replace(/:/g, '\\:') : rawDescription;
shell === 'zsh' ? rawDescription?.replaceAll(':', '\\:') : rawDescription;
let str = name;

if (shell === 'zsh' && description) {
Expand Down
6 changes: 3 additions & 3 deletions lib/installer.js
Original file line number Diff line number Diff line change
Expand Up @@ -247,10 +247,10 @@ const getCompletionScript = async ({ name, completer, shell }) => {
const templatePath = scriptFromShell(shell);
const templateContent = await readFile(templatePath, 'utf8');
const scriptContent = templateContent
.replace(/\{pkgname\}/g, name)
.replace(/{completer}/g, completer)
.replaceAll('{pkgname}', name)
.replaceAll('{completer}', completer)
// on Bash on windows, we need to make sure to remove any \r
.replace(/\r?\n/g, '\n');
.replaceAll(/\r?\n/g, '\n');
return scriptContent
};

Expand Down
6 changes: 3 additions & 3 deletions test/getCompletionScript.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@ describe('getCompletionScript gets the right completion script for', () => {
shell
});
const expected = fs.readFileSync(require.resolve(`../lib/templates/completion.${COMPLETION_FILE_EXT[shell]}`), 'utf8')
.replace(/\{pkgname\}/g, 'foo')
.replace(/{completer}/g, 'foo-complete')
.replace(/\r?\n/g, '\n');
.replaceAll('{pkgname}', 'foo')
.replaceAll('{completer}', 'foo-complete')
.replaceAll(/\r?\n/g, '\n');
assert.equal(received, expected);
});
}
Expand Down

0 comments on commit 6bc1a75

Please sign in to comment.