ember-source
Version:
A JavaScript framework for creating ambitious web applications
46 lines (43 loc) • 1.61 kB
JavaScript
let getDebugName;
{
let getFunctionName = fn => {
let functionName = fn.name;
if (functionName === undefined) {
let match = Function.prototype.toString.call(fn).match(/function (\w+)\s*\(/);
functionName = match && match[1] || '';
}
return functionName.replace(/^bound /, '');
};
let getObjectName = obj => {
let name;
let className;
if (obj.constructor && obj.constructor !== Object) {
className = getFunctionName(obj.constructor);
}
if ('toString' in obj && obj.toString !== Object.prototype.toString && obj.toString !== Function.prototype.toString) {
name = obj.toString();
}
// If the class has a decent looking name, and the `toString` is one of the
// default Ember toStrings, replace the constructor portion of the toString
// with the class name. We check the length of the class name to prevent doing
// this when the value is minified.
if (name && name.match(/<.*:ember\d+>/) && className && className[0] !== '_' && className.length > 2 && className !== 'Class') {
return name.replace(/<.*:/, `<${className}:`);
}
return name || className;
};
let getPrimitiveName = value => {
return String(value);
};
getDebugName = value => {
if (typeof value === 'function') {
return getFunctionName(value) || `(unknown function)`;
} else if (typeof value === 'object' && value !== null) {
return getObjectName(value) || `(unknown object)`;
} else {
return getPrimitiveName(value);
}
};
}
const getDebugName$1 = getDebugName;
export { getDebugName$1 as g };