UNPKG

@agnostack/next-shopify

Version:

Please contact agnoStack via info@agnostack.com for any questions

53 lines 2.14 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.matchHostname = exports.matchObject = exports.matchArray = exports.isMatch = exports.safeHostname = void 0; const minimatch_1 = require("minimatch"); const display_1 = require("./display"); const safeHostname = (nameable) => { let hostname; try { hostname = (nameable === null || nameable === void 0 ? void 0 : nameable.startsWith('http')) ? new URL(nameable).hostname : nameable; // eslint-disable-next-line no-empty } catch (_ignore) { } return hostname; }; exports.safeHostname = safeHostname; const isMatch = (value, pattern) => ((0, display_1.stringNotEmpty)(value) && (0, display_1.stringNotEmpty)(pattern) && (0, minimatch_1.minimatch)(value, pattern)); exports.isMatch = isMatch; const matchArray = (value, patterns) => { let matched = false; // NOTE: intentionally using for/of loop instead of map so we can break to exit quickly soon as matched // eslint-disable-next-line no-restricted-syntax for (const pattern of (0, display_1.ensureArray)(patterns)) { matched = (0, exports.isMatch)(value, pattern); if (matched) { break; } } return matched; }; exports.matchArray = matchArray; const matchObject = (value, patterns) => { let matched; // NOTE: intentionally using for/of loop instead of map so we can break to exit quickly soon as matched // eslint-disable-next-line no-restricted-syntax for (const [pattern, data] of Object.entries((0, display_1.ensureObject)(patterns))) { if ((0, exports.isMatch)(value, pattern)) { matched = data; break; } } return matched; }; exports.matchObject = matchObject; const matchHostname = (nameable, patterns) => { const hostname = (0, exports.safeHostname)(nameable); return Array.isArray(patterns) || (0, display_1.isType)(patterns, 'string') ? (0, exports.matchArray)(hostname, patterns) : (0, exports.matchObject)(hostname, patterns); }; exports.matchHostname = matchHostname; //# sourceMappingURL=match.js.map