UNPKG

@botonic/react

Version:

Build Chatbots using React

68 lines 2.34 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.normalize = exports.isURL = exports.resolveImage = exports.staticAsset = exports.isProd = exports.isDev = void 0; exports.isDev = process.env.NODE_ENV === 'development'; exports.isProd = process.env.NODE_ENV === 'production'; const staticAsset = path => { try { if ((0, exports.isURL)(path)) return path; // Webpack 5 >= fully resolves absolute path to assets const scriptBaseURL = document .querySelector('script[src*="webchat.botonic.js"]') .getAttribute('src'); const scriptName = scriptBaseURL.split('/').pop(); const basePath = scriptBaseURL.replace('/' + scriptName, '/'); const resolvedStaticAssetPath = basePath + path; return resolvedStaticAssetPath; } catch (e) { console.error(`Could not resolve path: '${path}'`); return normalize(path); } }; exports.staticAsset = staticAsset; const resolveImage = src => { if ((0, exports.isURL)(src)) return src; return (0, exports.staticAsset)(src); }; exports.resolveImage = resolveImage; const isURL = urlPath => { // @stephenhay (38 chars) from: https://mathiasbynens.be/demo/url-regex const pattern = new RegExp(/^(blob:)?(https?|ftp):\/\/[^\s/$.?#].[^\s]*$/); return !!pattern.test(urlPath); }; exports.isURL = isURL; function normalize(path) { const isAbsolute = path.charAt(0) === '/'; const trailingSlash = path && path[path.length - 1] === '/'; // Normalize the path path = normalizeArray(path.split('/'), !isAbsolute).join('/'); if (!path && !isAbsolute) path = '.'; if (path && trailingSlash) path += '/'; return (isAbsolute ? '/' : '') + path; } exports.normalize = normalize; function normalizeArray(parts, allowAboveRoot) { const res = []; for (let i = 0; i < parts.length; i++) { const p = parts[i]; if (!p || p === '.') continue; if (p === '..') { if (res.length && res[res.length - 1] !== '..') { res.pop(); } else if (allowAboveRoot) { res.push('..'); } } else { res.push(p); } } return res; } //# sourceMappingURL=environment.js.map