Sharkey/src/server/api/common/text/elements/url.ts

15 lines
227 B
TypeScript
Raw Normal View History

2016-12-29 07:49:51 +09:00
/**
* URL
*/
2017-02-11 02:32:00 +09:00
module.exports = text => {
2017-03-18 01:16:32 +09:00
const match = text.match(/^https?:\/\/[\w\/:%#@\$&\?!\(\)\[\]~\.=\+\-]+/);
2017-02-11 02:32:00 +09:00
if (!match) return null;
2017-03-18 01:16:32 +09:00
const url = match[0];
2017-02-11 02:32:00 +09:00
return {
2017-03-18 01:16:32 +09:00
type: 'url',
content: url,
url: url
2017-02-11 02:32:00 +09:00
};
2016-12-29 07:49:51 +09:00
};