MCPcopy Create free account
hub / github.com/Effect-TS/effect / declare

Function declare

packages/effect/src/encoding/Xml.ts:2330–2344  ·  view source on GitHub ↗
(
  parent: Namespaces | undefined,
  attributes: Readonly<Record<string, string>>
)

Source from the content-addressed store, hash-verified

2328
2329// Declarations are copied, as they can outlive the chunk of their tag
2330const declare = (
2331 parent: Namespaces | undefined,
2332 attributes: Readonly<Record<string, string>>
2333): Namespaces | undefined => {
2334 let declarations: Record<string, string> | undefined
2335 for (const name in attributes) {
2336 if (!Object.hasOwn(attributes, name)) continue
2337 const prefix = name === "xmlns" ? "" : name.startsWith("xmlns:") ? name.slice(6) : undefined
2338 // Omit the reserved xml and xmlns prefixes
2339 if (prefix === undefined || prefix === "xml" || prefix === "xmlns") continue
2340 declarations ??= new Attributes()
2341 declarations[copyString(prefix)] = copyString(attributes[name])
2342 }
2343 return declarations === undefined ? parent : { declarations, parent }
2344}
2345
2346// `string` is "*" or a literal name; `namespace: undefined` matches any namespace
2347type Segment = string | { readonly namespace: string | undefined; readonly localName: string }

Callers 1

pushMethod · 0.70

Calls 2

copyStringFunction · 0.85
sliceMethod · 0.80

Tested by

no test coverage detected