UNPKG

@sap/cds-dk

Version:

Command line client and development toolkit for the SAP Cloud Application Programming Model

33 lines (29 loc) 890 B
const IP_ADDR = /^[1-9][0-9]{0,2}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}$/; const schemaRegex = /^https?:\/\//; const localhostRegex = /^(https?:\/\/)?(localhost|127\.0\.0\.1|\[?::1]?)\b/; const httpSchema = 'http://'; const httpsSchema = 'https://'; function extractSubdomain(url) { const hostname = new URL(url).hostname; if (localhostRegex.test(hostname) || IP_ADDR.test(hostname)) { return undefined; } return hostname.split('.')[0]; } function concatUrls(...parts) { return parts .map((p, i) => i === 0 ? p.replace(/\/$/ /*end slash*/, '') : i === parts.length - 1 ? p.replace(/^\// /*begin slash*/, '') : p.replace(/^\/|\/$/g /*both*/, '')) .join('/'); } module.exports = { schemaRegex, localhostRegex, httpSchema, httpsSchema, extractSubdomain, concatUrls };