summaryrefslogtreecommitdiff
path: root/src/node_modules/validator/es/lib/isFQDN.js
diff options
context:
space:
mode:
authorMinteck <contact@minteck.org>2021-12-21 16:52:28 +0100
committerMinteck <contact@minteck.org>2021-12-21 16:52:28 +0100
commit46e43f4bde4a35785b4997b81e86cd19f046b69b (patch)
treec53c2f826f777f9d6b2d249dab556feb72a6c3a6 /src/node_modules/validator/es/lib/isFQDN.js
downloadlangdetect-46e43f4bde4a35785b4997b81e86cd19f046b69b.tar.gz
langdetect-46e43f4bde4a35785b4997b81e86cd19f046b69b.tar.bz2
langdetect-46e43f4bde4a35785b4997b81e86cd19f046b69b.zip
Commit
Diffstat (limited to 'src/node_modules/validator/es/lib/isFQDN.js')
-rw-r--r--src/node_modules/validator/es/lib/isFQDN.js60
1 files changed, 60 insertions, 0 deletions
diff --git a/src/node_modules/validator/es/lib/isFQDN.js b/src/node_modules/validator/es/lib/isFQDN.js
new file mode 100644
index 0000000..8a64bf2
--- /dev/null
+++ b/src/node_modules/validator/es/lib/isFQDN.js
@@ -0,0 +1,60 @@
+import assertString from './util/assertString';
+import merge from './util/merge';
+var default_fqdn_options = {
+ require_tld: true,
+ allow_underscores: false,
+ allow_trailing_dot: false
+};
+export default function isFQDN(str, options) {
+ assertString(str);
+ options = merge(options, default_fqdn_options);
+ /* Remove the optional trailing dot before checking validity */
+
+ if (options.allow_trailing_dot && str[str.length - 1] === '.') {
+ str = str.substring(0, str.length - 1);
+ }
+
+ var parts = str.split('.');
+
+ for (var i = 0; i < parts.length; i++) {
+ if (parts[i].length > 63) {
+ return false;
+ }
+ }
+
+ if (options.require_tld) {
+ var tld = parts.pop();
+
+ if (!parts.length || !/^([a-z\u00a1-\uffff]{2,}|xn[a-z0-9-]{2,})$/i.test(tld)) {
+ return false;
+ } // disallow spaces
+
+
+ if (/[\s\u2002-\u200B\u202F\u205F\u3000\uFEFF\uDB40\uDC20]/.test(tld)) {
+ return false;
+ }
+ }
+
+ for (var part, _i = 0; _i < parts.length; _i++) {
+ part = parts[_i];
+
+ if (options.allow_underscores) {
+ part = part.replace(/_/g, '');
+ }
+
+ if (!/^[a-z\u00a1-\uffff0-9-]+$/i.test(part)) {
+ return false;
+ } // disallow full-width chars
+
+
+ if (/[\uff01-\uff5e]/.test(part)) {
+ return false;
+ }
+
+ if (part[0] === '-' || part[part.length - 1] === '-') {
+ return false;
+ }
+ }
+
+ return true;
+} \ No newline at end of file