This repository has been archived by the owner on Aug 30, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
94 lines (77 loc) · 2 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
var app = require('../../app');
var util = require('util');
//改行コードをbrタグに変換
exports.nl2br = function(str) {
if (str) {
return str.replace(/\n/g, '<br/>');
}
};
//HTMLエスケープ処理
exports.escHtml = function(str) {
if (str) {
str = str.replace(/&/g, '&');
str = str.replace(/</g, '<');
str = str.replace(/>/g, '>');
str = str.replace(/"/g, '"');
str = str.replace(/\\/g, '¥');
return str;
}
};
// Error
// 404 用のエラー
// リクエストされた URI を受け取ることができる。
function NotFound(path) {
Error.call(this, 'Not Found');
Error.captureStackTrace(this, this.constructor); // スタックトレースの格納
this.name = 'NotFound';
this.path = path;
}
util.inherits(NotFound, Error);
exports.NotFound = NotFound;
// Error
// 401 用のエラー
// リクエストされた URI を受け取ることができる。
function Unauthorized(path) {
Error.call(this, 'Not Found');
Error.captureStackTrace(this, this.constructor); // スタックトレースの格納
this.name = 'Unauthorized';
this.path = path;
}
util.inherits(Unauthorized, Error);
exports.Unauthorized = Unauthorized;
// URLかどうかの判定
function isUrl(text) {
if (text.length == 0) {
return false;
}
text.match(/(http(s)?:\/\/([\w-]+\.)+[\w-]+(\/[\w-.\/?%&=:;_]*)?)/);
if (RegExp.$1 != null && RegExp.$1.length > 0) {
return true;
}
return false;
}
exports.isUrl = isUrl;
// URLの取得
function getUrl(text) {
if (text.length == 0) {
return false;
}
text.match(/(http(s)?:\/\/([\w-]+\.)+[\w-]+(\/[\w-.\/?%&=:;_]*)?)/);
if (RegExp.$1 != null && RegExp.$1.length > 0) {
return RegExp.$1;
}
return false;
}
exports.getUrl = getUrl;
// 画像URLの判定
function isImageUrl(url) {
if (url.length == 0) {
return false;
}
url.match(/(\.(jpg|jpeg|gif|png)$)/i);
if (RegExp.$1 != null && RegExp.$1.length > 0) {
return true;
}
return false;
}
exports.isImageUrl = isImageUrl;