1
0
Fork 1
mirror of https://github.com/SomboChea/ui synced 2024-05-21 10:51:38 +07:00
verdaccio-ui/src/utils/cli-utils.ts
2020-05-05 09:17:33 +02:00

35 lines
1.2 KiB
TypeScript

import { SyntheticEvent } from 'react';
export const copyToClipBoardUtility = (str: string): ((e: SyntheticEvent<HTMLElement>) => void) => (
event: SyntheticEvent<HTMLElement>
): void => {
event.preventDefault();
const node = document.createElement('div');
node.innerText = str;
if (document.body) {
document.body.appendChild(node);
const range = document.createRange();
const selection = window.getSelection() as Selection;
range.selectNodeContents(node);
selection.removeAllRanges();
selection.addRange(range);
document.execCommand('copy');
document.body.removeChild(node);
}
};
export function getCLISetConfigRegistry(command: string, scope: string, registryUrl: string): string {
// if there is a scope defined there needs to be a ":" separator between the scope and the registry
return `${command} ${scope}${scope !== '' ? ':' : ''}registry ${registryUrl}`;
}
export function getCLISetRegistry(command: string, registryUrl: string): string {
return `${command} --registry ${registryUrl}`;
}
export function getCLIChangePassword(command: string, registryUrl: string): string {
return `${command} profile set password --registry ${registryUrl}`;
}