-
-
Notifications
You must be signed in to change notification settings - Fork 931
/
Copy pathis.js
81 lines (66 loc) · 1.75 KB
/
is.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
'use strict';
/**
* Validation rules.
*/
var rules = {
NCHAR: /^[\u002D|\u002E|\u005F|\w]+$/,
NQCHAR: /^[\u0021|\u0023-\u005B|\u005D-\u007E]+$/,
NQSCHAR: /^[\u0020-\u0021|\u0023-\u005B|\u005D-\u007E]+$/,
UNICODECHARNOCRLF: /^[\u0009|\u0020-\u007E|\u0080-\uD7FF|\uE000-\uFFFD|\u10000-\u10FFFF]+$/,
URI: /^[a-zA-Z][a-zA-Z0-9+.-]+:/,
VSCHAR: /^[\u0020-\u007E]+$/
};
/**
* Export validation functions.
*/
module.exports = {
/**
* Validate if a value matches a unicode character.
*
* @see https://tools.ietf.org/html/rfc6749#appendix-A
*/
nchar: function(value) {
return rules.NCHAR.test(value);
},
/**
* Validate if a value matches a unicode character, including exclamation marks.
*
* @see https://tools.ietf.org/html/rfc6749#appendix-A
*/
nqchar: function(value) {
return rules.NQCHAR.test(value);
},
/**
* Validate if a value matches a unicode character, including exclamation marks and spaces.
*
* @see https://tools.ietf.org/html/rfc6749#appendix-A
*/
nqschar: function(value) {
return rules.NQSCHAR.test(value);
},
/**
* Validate if a value matches a unicode character excluding the carriage
* return and linefeed characters.
*
* @see https://tools.ietf.org/html/rfc6749#appendix-A
*/
uchar: function(value) {
return rules.UNICODECHARNOCRLF.test(value);
},
/**
* Validate if a value matches generic URIs.
*
* @see http://tools.ietf.org/html/rfc3986#section-3
*/
uri: function(value) {
return rules.URI.test(value);
},
/**
* Validate if a value matches against the printable set of unicode characters.
*
* @see https://tools.ietf.org/html/rfc6749#appendix-A
*/
vschar: function(value) {
return rules.VSCHAR.test(value);
}
};