Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
let baseName = 'Untitled';
let path = '';
let contentType: Contents.ContentType = 'notebook';
let fileType: DocumentRegistry.IFileType;
if (options) {
// Add leading `.` to extension if necessary.
ext = options.ext ? PathExt.normalizeExtension(options.ext) : ext;
// If we are not creating in the root directory.
path = options.path || '';
contentType = options.type || 'notebook';
}
let model: Partial;
if (contentType === 'notebook') {
fileType = DocumentRegistry.defaultNotebookFileType;
ext = ext || fileType.extensions[0];
baseName = 'Untitled';
const modelFactory = this._docRegistry.getModelFactory('Notebook');
if (!modelFactory) {
throw Error('No model factory is registered with the DocRegistry');
}
model = {
type: fileType.contentType,
content: modelFactory.createNew().toJSON(),
mimetype: fileType.mimeTypes[0],
format: fileType.fileFormat
};
} else if (contentType === 'file') {
fileType = DocumentRegistry.defaultTextFileType;
ext = ext || fileType.extensions[0];
baseName = 'untitled';