1"use strict"; 2Object.defineProperty(exports, "__esModule", { value: true }); 3/* 4 * Converts the slug from app configuration to a string that's a valid URI scheme. 5 * From RFC3986 Section 3.1. 6 * scheme = ALPHA *( ALPHA / DIGIT / "+" / "-" / "." ) 7 */ 8function getDefaultScheme(config) { 9 if (typeof config !== 'object') { 10 throw new TypeError('getDefaultScheme: config is not object'); 11 } 12 if (!config.slug || typeof config.slug !== 'string') { 13 throw new TypeError('getDefaultScheme: config missing required property "slug"'); 14 } 15 // Remove unallowed characters. Also remove `-` to keep this shorter. 16 let scheme = config.slug.replace(/[^A-Za-z0-9+\-.]/g, ''); 17 // Edge case: if the slug didn't include any allowed characters we may end up with an empty string. 18 if (scheme.length === 0) { 19 throw new Error('Could not autogenerate a scheme. Please make sure the "slug" property in app config consists of URL friendly characters.'); 20 } 21 // Lowercasing might not be strictly necessary, but let's do it for stylistic purposes. 22 scheme = scheme.toLowerCase(); 23 // Add a prefix to avoid leading digits and to distinguish from user-defined schemes. 24 return `exp+${scheme}`; 25} 26exports.default = getDefaultScheme; 27