MCPcopy Index your code
hub / github.com/angular/angular / elementText

Function elementText

packages/private/testing/matchers/index.ts:194–227  ·  view source on GitHub ↗
(n: any)

Source from the content-addressed store, hash-verified

192});
193
194function elementText(n: any): string {
195 const hasNodes = (n: any) => {
196 const children = n.childNodes;
197 return children && children.length > 0;
198 };
199
200 if (n instanceof Array) {
201 return n.map(elementText).join('');
202 }
203
204 if (isCommentNode(n)) {
205 return '';
206 }
207
208 if (getDOM().isElementNode(n)) {
209 const tagName = (n as Element).tagName;
210
211 if (tagName === 'CONTENT') {
212 return elementText(Array.prototype.slice.apply((<any>n).getDistributedNodes()));
213 } else if (tagName === 'SLOT') {
214 return elementText(Array.prototype.slice.apply((<any>n).assignedNodes()));
215 }
216 }
217
218 if (hasShadowRoot(n)) {
219 return elementText(childNodesAsList((<any>n).shadowRoot));
220 }
221
222 if (hasNodes(n)) {
223 return elementText(childNodesAsList(n));
224 }
225
226 return (n as any).textContent;
227}
228
229function hasShadowRoot(node: any): boolean {
230 return node.shadowRoot != null && node instanceof HTMLElement;

Callers 1

index.tsFile · 0.85

Calls 9

isCommentNodeFunction · 0.90
childNodesAsListFunction · 0.90
getDOMFunction · 0.85
hasShadowRootFunction · 0.85
hasNodesFunction · 0.85
mapMethod · 0.80
joinMethod · 0.65
applyMethod · 0.65
isElementNodeMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…