You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
tailchat/client/shared/utils/string-helper.ts

58 lines
1.2 KiB
TypeScript

import _isString from 'lodash/isString';
import urlRegex from 'url-regex';
/**
* ()
* @param str
*/
export function isAvailableString(str: unknown): boolean {
return typeof str === 'string' && str.length > 0;
}
/**
* url
* @param str
*/
export function isUrl(str: string) {
return urlRegex({ exact: true }).test(str);
}
/**
* blobUrl
* @param str url
*/
export const isBlobUrl = (str: string) => {
return _isString(str) && str.startsWith('blob:');
};
/**
* url
* @param str
*/
export const getUrls = (str: string): string[] => {
return str.match(urlRegex()) ?? [];
};
/**
*
*/
export function is(it: string) {
return !!it && it !== '0' && it !== 'false';
}
/**
*
*
*/
export function isValidStr(str: unknown): str is string {
return typeof str == 'string' && str !== '';
}
export function isLocalMessageId(str: unknown): str is string {
if (typeof str !== 'string') {
return false;
}
return str.startsWith('localMessage_');
}