MCPcopy
hub / github.com/vercel/next.js / serializeAttrs

Method serializeAttrs

packages/next-codemod/transforms/cra-to-next.ts:210–230  ·  view source on GitHub ↗
(attrs: CheerioElement['attribs'])

Source from the content-addressed store, hash-verified

208 }
209
210 const serializeAttrs = (attrs: CheerioElement['attribs']) => {
211 const attrStr = Object.keys(attrs || {})
212 .map((name) => {
213 const reactName = htmlToReactAttributes[name] || name
214 const value = attrs[name]
215
216 // allow process.env access to work dynamically still
217 if (value.match(/%([a-zA-Z0-9_]{0,})%/)) {
218 return `${reactName}={\`${value.replace(
219 /%([a-zA-Z0-9_]{0,})%/g,
220 (subStr) => {
221 return `\${process.env.${subStr.slice(1, -1)}}`
222 }
223 )}\`}`
224 }
225 return `${reactName}="${value}"`
226 })
227 .join(' ')
228
229 return attrStr.length > 0 ? ` ${attrStr}` : ''
230 }
231 const serializedHeadTags: string[] = []
232 const serializedBodyTags: string[] = []
233

Callers

nothing calls this directly

Calls 6

keysMethod · 0.65
matchMethod · 0.65
replaceMethod · 0.65
joinMethod · 0.45
mapMethod · 0.45
sliceMethod · 0.45

Tested by

no test coverage detected