MCPcopy
hub / github.com/aykutkardas/regexlearn.com / tagWrapper

Function tagWrapper

src/utils/tagWrapper.ts:3–12  ·  view source on GitHub ↗
({ value, regex, tagName = 'span', attributes = {} }: TagWrapper)

Source from the content-addressed store, hash-verified

1type TagWrapper = { value: string; regex: RegExp; tagName?: string; attributes?: object };
2
3const tagWrapper = ({ value, regex, tagName = 'span', attributes = {} }: TagWrapper): string => {
4 if (typeof value !== 'string') return value;
5
6 const setAttributes = attrs =>
7 Object.entries(attrs)
8 .map(([key, val]) => `${key === 'className' ? 'class' : key}="${val}"`)
9 .join(' ');
10
11 return value.replace(regex, `<${tagName} ${setAttributes(attributes)}>$1</${tagName}>`);
12};
13
14export default tagWrapper;

Callers 3

applyRegexFunction · 0.85
applyRegexFunction · 0.85
HighlightedTextFunction · 0.85

Calls 1

setAttributesFunction · 0.85

Tested by

no test coverage detected