Files
klz-cables.com/.pnpm-store/v10/files/a3/655a4f2f57aaec102d48df88e9ab25fa6dfaeb01cf50a661bd880307265fef1c8330c5506506c482e5fe46d0bb4d93cd32ec8d6f436d2ade6859b49083a97b
Marc Mintel 5397309103
Some checks failed
Build & Deploy / 🔍 Prepare (push) Successful in 20s
Build & Deploy / 🧪 QA (push) Failing after 34s
Build & Deploy / 🏗️ Build (push) Has started running
Build & Deploy / 🚀 Deploy (push) Has been cancelled
Build & Deploy / 🧪 Smoke Test (push) Has been cancelled
Build & Deploy / ⚡ Lighthouse (push) Has been cancelled
Build & Deploy / 🔔 Notify (push) Has been cancelled
fix(products): fix breadcrumbs and product filtering (backport from main)
2026-02-24 16:04:21 +01:00

37 lines
966 B
Plaintext

import { invariant } from "./utils.js";
/**
* Partition a pattern into a list of literals and placeholders
* https://tc39.es/ecma402/#sec-partitionpattern
* @param pattern
*/
export function PartitionPattern(pattern) {
const result = [];
let beginIndex = pattern.indexOf("{");
let endIndex = 0;
let nextIndex = 0;
const length = pattern.length;
while (beginIndex < pattern.length && beginIndex > -1) {
endIndex = pattern.indexOf("}", beginIndex);
invariant(endIndex > beginIndex, `Invalid pattern ${pattern}`);
if (beginIndex > nextIndex) {
result.push({
type: "literal",
value: pattern.substring(nextIndex, beginIndex)
});
}
result.push({
type: pattern.substring(beginIndex + 1, endIndex),
value: undefined
});
nextIndex = endIndex + 1;
beginIndex = pattern.indexOf("{", nextIndex);
}
if (nextIndex < length) {
result.push({
type: "literal",
value: pattern.substring(nextIndex, length)
});
}
return result;
}