Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
let lastSlashIndex = name.lastIndexOf('/');
let dirname = lastSlashIndex !== -1 ? name.slice(0, lastSlashIndex) : null;
if (type !== 'template' && lastSlashIndex !== -1) {
let parts = name.split('/');
name = parts[parts.length - 1];
let namespaceName = StringUtils.capitalize(parts.slice(0, -1).join('.'));
root = Namespace.byName(namespaceName);
assert(
`You are looking for a ${name} ${type} in the ${namespaceName} namespace, but the namespace could not be found`,
root
);
}
let resolveMethodName = fullNameWithoutType === 'main' ? 'Main' : StringUtils.classify(type);
if (!(name && type)) {
throw new TypeError(`Invalid fullName: \`${fullName}\`, must be of the form \`type:name\` `);
}
return {
fullName,
type,
fullNameWithoutType,
dirname,
name,
root,
resolveMethodName: `resolve${resolveMethodName}`
};
}
resolveOther(parsedName) {
let className = StringUtils.classify(parsedName.name) + StringUtils.classify(parsedName.type);
let factory = get(parsedName.root, className);
return factory;
}
translateToContainerFullname(type, name) {
let suffix = StringUtils.classify(type);
let namePrefix = name.slice(0, suffix.length * -1);
let dasherizedName = StringUtils.dasherize(namePrefix);
return `${type}:${dasherizedName}`;
}
}
resolveModel(parsedName) {
let className = StringUtils.classify(parsedName.name);
let factory = get(parsedName.root, className);
return factory;
}
/**
lookupDescription(fullName) {
let parsedName = this.parseName(fullName);
let description;
if (parsedName.type === 'template') {
return `template at ${parsedName.fullNameWithoutType.replace(/\./g, '/')}`;
}
description = `${parsedName.root}.${StringUtils.classify(parsedName.name).replace(/\./g, '')}`;
if (parsedName.type !== 'model') {
description += StringUtils.classify(parsedName.type);
}
return description;
}