MCPcopy Create free account
hub / github.com/OpenEndedGroup/Field2 / formatProperty

Function formatProperty

lib/web/jshint.js:1167–1223  ·  view source on GitHub ↗
(ctx, value, recurseTimes, visibleKeys, key, array)

Source from the content-addressed store, hash-verified

1165
1166
1167function formatProperty(ctx, value, recurseTimes, visibleKeys, key, array) {
1168 var name, str, desc;
1169 desc = Object.getOwnPropertyDescriptor(value, key) || { value: value[key] };
1170 if (desc.get) {
1171 if (desc.set) {
1172 str = ctx.stylize('[Getter/Setter]', 'special');
1173 } else {
1174 str = ctx.stylize('[Getter]', 'special');
1175 }
1176 } else {
1177 if (desc.set) {
1178 str = ctx.stylize('[Setter]', 'special');
1179 }
1180 }
1181 if (!hasOwnProperty(visibleKeys, key)) {
1182 name = '[' + key + ']';
1183 }
1184 if (!str) {
1185 if (ctx.seen.indexOf(desc.value) < 0) {
1186 if (isNull(recurseTimes)) {
1187 str = formatValue(ctx, desc.value, null);
1188 } else {
1189 str = formatValue(ctx, desc.value, recurseTimes - 1);
1190 }
1191 if (str.indexOf('\n') > -1) {
1192 if (array) {
1193 str = str.split('\n').map(function(line) {
1194 return ' ' + line;
1195 }).join('\n').substr(2);
1196 } else {
1197 str = '\n' + str.split('\n').map(function(line) {
1198 return ' ' + line;
1199 }).join('\n');
1200 }
1201 }
1202 } else {
1203 str = ctx.stylize('[Circular]', 'special');
1204 }
1205 }
1206 if (isUndefined(name)) {
1207 if (array && key.match(/^\d+$/)) {
1208 return str;
1209 }
1210 name = JSON.stringify('' + key);
1211 if (name.match(/^"([a-zA-Z_][a-zA-Z_0-9]*)"$/)) {
1212 name = name.substr(1, name.length - 2);
1213 name = ctx.stylize(name, 'name');
1214 } else {
1215 name = name.replace(/'/g, "\\'")
1216 .replace(/\\"/g, '"')
1217 .replace(/(^"|"$)/g, "'");
1218 name = ctx.stylize(name, 'string');
1219 }
1220 }
1221
1222 return name + ': ' + str;
1223}
1224

Callers 2

formatValueFunction · 0.85
formatArrayFunction · 0.85

Calls 9

hasOwnPropertyFunction · 0.85
isNullFunction · 0.85
formatValueFunction · 0.85
isUndefinedFunction · 0.85
indexOfMethod · 0.80
replaceMethod · 0.80
mapMethod · 0.45
splitMethod · 0.45
matchMethod · 0.45

Tested by

no test coverage detected