]>
Commit | Line | Data |
---|---|---|
4d4e5cd4 | 1 | import * as validator from 'validator' |
d57d6f26 | 2 | |
69818c93 | 3 | import { isArray, exists } from './misc' |
67bf9b96 | 4 | |
69818c93 C |
5 | function isHostValid (host: string) { |
6 | return exists(host) && validator.isURL(host) && host.split('://').length === 1 | |
d57d6f26 C |
7 | } |
8 | ||
69818c93 | 9 | function isEachUniqueHostValid (hosts: string[]) { |
65fcc311 | 10 | return isArray(hosts) && |
49abbbbe C |
11 | hosts.length !== 0 && |
12 | hosts.every(function (host) { | |
67bf9b96 | 13 | return isHostValid(host) && hosts.indexOf(host) === hosts.lastIndexOf(host) |
d57d6f26 C |
14 | }) |
15 | } | |
16 | ||
17 | // --------------------------------------------------------------------------- | |
18 | ||
65fcc311 C |
19 | export { |
20 | isEachUniqueHostValid, | |
21 | isHostValid | |
22 | } | |
69818c93 C |
23 | |
24 | declare global { | |
25 | namespace ExpressValidator { | |
26 | export interface Validator { | |
27 | isEachUniqueHostValid | |
28 | isHostValid | |
29 | } | |
30 | } | |
31 | } |