Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,19 @@ const rules = {

/* eslint-enable no-control-regex */

/**
* Ensure the value is a string.
* @private
* @param s {any} the value to be checked
* @throws {TypeError} if the value is not a string
*/
const assertString = (s) => {
const t = typeof s;
if (t !== 'string') {
throw new TypeError('Value must be a string');
}
};

/**
* Minimal, RFC 6749, compliant unicode validator.
* @see https://datatracker.ietf.org/doc/html/rfc6749#appendix-A
Expand All @@ -33,6 +46,7 @@ const isFormat = {
*/

nchar: function(value) {
assertString(value);
return rules.NCHAR.test(value);
},

Expand All @@ -45,6 +59,7 @@ const isFormat = {
*/

nqchar: function(value) {
assertString(value);
return rules.NQCHAR.test(value);
},

Expand All @@ -57,6 +72,7 @@ const isFormat = {
*/

nqschar: function(value) {
assertString(value);
return rules.NQSCHAR.test(value);
},

Expand All @@ -70,6 +86,7 @@ const isFormat = {
*/

uchar: function(value) {
assertString(value);
// manually test \u10000-\u10FFFF
if (rules.UNICODECHARNOCRLF.test(value)) {
return true;
Expand All @@ -86,6 +103,7 @@ const isFormat = {
* @return {boolean} true, if valid, otherwise false
*/
uri: function(value) {
assertString(value);
return rules.URI.test(value);
},

Expand All @@ -98,6 +116,7 @@ const isFormat = {
*/

vschar: function(value) {
assertString(value);
return rules.VSCHAR.test(value);
}
};
Expand Down
Loading