UNPKG

vuestic-ui

Version:
29 lines (28 loc) 1.08 kB
import { r as regexGroupsValues } from "./regex.js"; const dynamicSegmentRegex = /{[^}]*}/g; const dynamicSegmentStringToRegex = (template) => { return template.replace(dynamicSegmentRegex, "(.*)"); }; const dynamicSegmentsNames = (template) => { return (template.match(dynamicSegmentRegex) || []).map((g) => g.replace(/{|}/g, "")); }; const dynamicSegmentsValues = (str, template) => { return regexGroupsValues(str, dynamicSegmentStringToRegex(template)); }; const dynamicSegments = (str, template) => { const params = dynamicSegmentsNames(template); const values = dynamicSegmentsValues(str, template); return params.reduce((acc, paramValue, i) => ({ ...acc, [paramValue]: values[i] }), {}); }; const strictMatch = (str, regex) => { return (str.match(regex) || [])[0] === str; }; const isMatchDynamicSegments = (str, template) => { const templateRegex = dynamicSegmentStringToRegex(template); return strictMatch(str, new RegExp(templateRegex)); }; export { dynamicSegments as d, isMatchDynamicSegments as i }; //# sourceMappingURL=dynamic-segment.js.map