1
0
Fork 0
management/front/dkha-web-sz-main/node_modules/@hapi/address/lib/index.js

85 lines
1.9 KiB
JavaScript
Raw Permalink Normal View History

2023-12-18 13:12:25 +08:00
'use strict';
2024-01-16 21:26:16 +08:00
const Domain = require('./domain');
const Email = require('./email');
2023-12-18 13:12:25 +08:00
const Tlds = require('./tlds');
const internals = {
defaultTlds: { allow: Tlds, deny: null }
};
module.exports = {
2024-01-16 21:26:16 +08:00
domain: {
analyze(domain, options) {
2023-12-18 13:12:25 +08:00
2024-01-16 21:26:16 +08:00
options = internals.options(options);
return Domain.analyze(domain, options);
2023-12-18 13:12:25 +08:00
},
2024-01-16 21:26:16 +08:00
isValid(domain, options) {
options = internals.options(options);
return Domain.isValid(domain, options);
2023-12-18 13:12:25 +08:00
}
},
2024-01-16 21:26:16 +08:00
email: {
analyze(email, options) {
2023-12-18 13:12:25 +08:00
2024-01-16 21:26:16 +08:00
options = internals.options(options);
return Email.analyze(email, options);
2023-12-18 13:12:25 +08:00
},
2024-01-16 21:26:16 +08:00
isValid(email, options) {
2023-12-18 13:12:25 +08:00
2024-01-16 21:26:16 +08:00
options = internals.options(options);
return Email.isValid(email, options);
2023-12-18 13:12:25 +08:00
}
}
};
2024-01-16 21:26:16 +08:00
internals.options = function (options) {
2023-12-18 13:12:25 +08:00
2024-01-16 21:26:16 +08:00
if (!options) {
return { tlds: internals.defaultTlds };
2023-12-18 13:12:25 +08:00
}
2024-01-16 21:26:16 +08:00
if (options.tlds === false) { // Defaults to true
return options;
2023-12-18 13:12:25 +08:00
}
2024-01-16 21:26:16 +08:00
if (!options.tlds ||
options.tlds === true) {
2023-12-18 13:12:25 +08:00
2024-01-16 21:26:16 +08:00
return Object.assign({}, options, { tlds: internals.defaultTlds });
2023-12-18 13:12:25 +08:00
}
2024-01-16 21:26:16 +08:00
if (typeof options.tlds !== 'object') {
throw new Error('Invalid options: tlds must be a boolean or an object');
2023-12-18 13:12:25 +08:00
}
2024-01-16 21:26:16 +08:00
if (options.tlds.deny) {
if (options.tlds.deny instanceof Set === false) {
throw new Error('Invalid options: tlds.deny must be a Set object');
2023-12-18 13:12:25 +08:00
}
2024-01-16 21:26:16 +08:00
if (options.tlds.allow) {
throw new Error('Invalid options: cannot specify both tlds.allow and tlds.deny lists');
2023-12-18 13:12:25 +08:00
}
2024-01-16 21:26:16 +08:00
return options;
2023-12-18 13:12:25 +08:00
}
2024-01-16 21:26:16 +08:00
if (options.tlds.allow === true) {
return Object.assign({}, options, { tlds: internals.defaultTlds });
2023-12-18 13:12:25 +08:00
}
2024-01-16 21:26:16 +08:00
if (options.tlds.allow instanceof Set === false) {
throw new Error('Invalid options: tlds.allow must be a Set object or true');
2023-12-18 13:12:25 +08:00
}
2024-01-16 21:26:16 +08:00
return options;
2023-12-18 13:12:25 +08:00
};