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

refactor: replace RegExp with replaceAll #25

Closed
wants to merge 1 commit into from
Closed
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
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
Loading