MCPcopy Create free account
hub / github.com/angular/angular / stringify

Function stringify

packages/compiler/src/util.ts:82–114  ·  view source on GitHub ↗
(token: any)

Source from the content-addressed store, hash-verified

80}
81
82export function stringify(token: any): string {
83 if (typeof token === 'string') {
84 return token;
85 }
86
87 if (Array.isArray(token)) {
88 return `[${token.map(stringify).join(', ')}]`;
89 }
90
91 if (token == null) {
92 return '' + token;
93 }
94
95 const name = token.overriddenName || token.name;
96 if (name) {
97 return `${name}`;
98 }
99
100 if (!token.toString) {
101 return 'object';
102 }
103
104 // WARNING: do not try to `JSON.stringify(token)` here
105 // see https://github.com/angular/angular/issues/23440
106 const result = token.toString();
107
108 if (result == null) {
109 return '' + result;
110 }
111
112 const newLineIndex = result.indexOf('\n');
113 return newLineIndex >= 0 ? result.slice(0, newLineIndex) : result;
114}
115
116export class Version {
117 public readonly major: string;

Callers 2

util_spec.tsFile · 0.90
identifierNameFunction · 0.90

Calls 5

isArrayMethod · 0.80
mapMethod · 0.80
indexOfMethod · 0.80
joinMethod · 0.65
toStringMethod · 0.65

Tested by

no test coverage detected