1
0
Fork 1
mirror of https://github.com/SomboChea/ui synced 2024-06-01 17:15:06 +07:00
verdaccio-ui/src/utils/url.ts
2019-07-13 07:53:23 +01:00

29 lines
869 B
TypeScript

import isURLValidator from 'validator/lib/isURL';
import isEmailValidator from 'validator/lib/isEmail';
import '../../types';
export function isURL(url: string): boolean {
return isURLValidator(url || '', {
protocols: ['http', 'https', 'git+https'],
require_protocol: true,
require_tld: false,
});
}
export function isEmail(email): boolean {
return isEmailValidator(email || '');
}
export function getRegistryURL(): string {
// Don't add slash if it's not a sub directory
return `${location.origin}${location.pathname === '/' ? '' : location.pathname}`;
}
export function getBaseNamePath(): string {
return window.__VERDACCIO_BASENAME_UI_OPTIONS && window.__VERDACCIO_BASENAME_UI_OPTIONS.url_prefix;
}
export function getRootPath(): string {
return window.__VERDACCIO_BASENAME_UI_OPTIONS && window.__VERDACCIO_BASENAME_UI_OPTIONS.base;
}