mirror of
https://github.com/sim1222/misskey.git
synced 2025-06-18 01:38:01 +09:00
21 lines
338 B
TypeScript
21 lines
338 B
TypeScript
/**
|
|
* URL
|
|
*/
|
|
|
|
export type TextElementUrl = {
|
|
type: 'url';
|
|
content: string;
|
|
url: string;
|
|
};
|
|
|
|
export default function(text: string) {
|
|
const match = text.match(/^https?:\/\/[\w\/:%#@\$&\?!\(\)\[\]~\.=\+\-]+/);
|
|
if (!match) return null;
|
|
const url = match[0];
|
|
return {
|
|
type: 'url',
|
|
content: url,
|
|
url: url
|
|
} as TextElementUrl;
|
|
}
|