How to use the @jupyterlab/coreutils.PathExt.basename function in @jupyterlab/coreutils

To help you get started, we’ve selected a few @jupyterlab/coreutils examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github jupyterlab / jupyterlab / packages / docregistry / src / registry.ts View on Github external
preferredWidgetFactories(path: string): DocumentRegistry.WidgetFactory[] {
    let factories = new Set();

    // Get the ordered matching file types.
    let fts = this.getFileTypesForPath(PathExt.basename(path));

    // Start with any user overrides for the defaults.
    fts.forEach(ft => {
      if (ft.name in this._defaultWidgetFactoryOverrides) {
        factories.add(this._defaultWidgetFactoryOverrides[ft.name]);
      }
    });

    // Next add the file type default factories.
    fts.forEach(ft => {
      if (ft.name in this._defaultWidgetFactories) {
        factories.add(this._defaultWidgetFactories[ft.name]);
      }
    });

    // Add the file type default rendered factories.
github jupyterlab / jupyterlab-data-explorer / jupyterlab / packages / docregistry / src / registry.ts View on Github external
preferredWidgetFactories(path: string): DocumentRegistry.WidgetFactory[] {
    let factories = new Set();

    // Get the ordered matching file types.
    let fts = this.getFileTypesForPath(PathExt.basename(path));

    // Start with the file type default factories.
    fts.forEach(ft => {
      if (ft.name in this._defaultWidgetFactories) {
        factories.add(this._defaultWidgetFactories[ft.name]);
      }
    });

    // Add the file type default rendered factories.
    fts.forEach(ft => {
      if (ft.name in this._defaultRenderedWidgetFactories) {
        factories.add(this._defaultRenderedWidgetFactories[ft.name]);
      }
    });

    // Add the global default factory.
github jupyterlab / jupyterlab / packages / filebrowser / src / listing.ts View on Github external
basePath = PathExt.join(basePath, items[index].name);
    }
    const manager = this._manager;

    // Handle the items.
    const promises: Promise[] = [];
    const paths = event.mimeData.getData(CONTENTS_MIME) as string[];

    if (event.ctrlKey && event.proposedAction === 'move') {
      event.dropAction = 'copy';
    } else {
      event.dropAction = event.proposedAction;
    }
    for (let path of paths) {
      let localPath = manager.services.contents.localPath(path);
      let name = PathExt.basename(localPath);
      let newPath = PathExt.join(basePath, name);
      // Skip files that are not moving.
      if (newPath === path) {
        continue;
      }

      if (event.dropAction === 'copy') {
        promises.push(manager.copy(path, basePath));
      } else {
        promises.push(renameFile(manager, path, newPath));
      }
    }
    Promise.all(promises).catch(error => {
      void showErrorMessage('Error while copying/moving files', error);
    });
  }
github jupyterlab / jupyterlab / packages / docregistry / src / registry.ts View on Github external
getFileTypesForPath(path: string): DocumentRegistry.IFileType[] {
    let fts: DocumentRegistry.IFileType[] = [];
    let name = PathExt.basename(path);

    // Look for a pattern match first.
    let ft = find(this._fileTypes, ft => {
      return ft.pattern && ft.pattern.match(name) !== null;
    });
    if (ft) {
      fts.push(ft);
    }

    // Then look by extension name, starting with the longest
    let ext = Private.extname(name);
    while (ext.length > 1) {
      ft = find(this._fileTypes, ft => ft.extensions.indexOf(ext) !== -1);
      if (ft) {
        fts.push(ft);
      }
github jupyterlab / jupyterlab-data-explorer / jupyterlab / packages / docregistry / src / registry.ts View on Github external
getFileTypesForPath(path: string): DocumentRegistry.IFileType[] {
    let fts: DocumentRegistry.IFileType[] = [];
    let name = PathExt.basename(path);

    // Look for a pattern match first.
    let ft = find(this._fileTypes, ft => {
      return ft.pattern && ft.pattern.match(name) !== null;
    });
    if (ft) {
      fts.push(ft);
    }

    // Then look by extension name, starting with the longest
    let ext = Private.extname(name);
    while (ext.length > 1) {
      ft = find(this._fileTypes, ft => ft.extensions.indexOf(ext) !== -1);
      if (ft) {
        fts.push(ft);
      }
github jupyterlab / jupyterlab / tests / test-coreutils / src / path.spec.ts View on Github external
it('should return the last portion of a path', () => {
        expect(PathExt.basename(TESTPATH)).to.equal('test-path.js');
      });
    });
github jupyterlab / jupyterlab / packages / docregistry / src / registry.ts View on Github external
export function extname(path: string): string {
    let parts = PathExt.basename(path).split('.');
    parts.shift();
    let ext = '.' + parts.join('.');
    return ext.toLowerCase();
  }
  /**
github jupyterlab / jupyterlab / packages / docmanager / src / pathstatus.tsx View on Github external
private _onPathChange = (
      _documentModel: DocumentRegistry.IContext,
      newPath: string
    ) => {
      const oldState = this._getAllState();
      this._path = newPath;
      this._name = PathExt.basename(newPath);

      this._triggerChange(oldState, this._getAllState());
    };
github jupyterlab / jupyterlab / packages / docregistry / src / registry.ts View on Github external
getKernelPreference(
    path: string,
    widgetName: string,
    kernel?: Partial
  ): IClientSession.IKernelPreference | undefined {
    widgetName = widgetName.toLowerCase();
    let widgetFactory = this._widgetFactories[widgetName];
    if (!widgetFactory) {
      return void 0;
    }
    let modelFactory = this.getModelFactory(widgetFactory.modelName || 'text');
    if (!modelFactory) {
      return void 0;
    }
    let language = modelFactory.preferredLanguage(PathExt.basename(path));
    let name = kernel && kernel.name;
    let id = kernel && kernel.id;
    return {
      id,
      name,
      language,
      shouldStart: widgetFactory.preferKernel,
      canStart: widgetFactory.canStartKernel,
      shutdownOnClose: widgetFactory.shutdownOnClose
    };
  }
github jupyterlab / jupyterlab / packages / filebrowser / src / model.ts View on Github external
constructor(options: FileBrowserModel.IOptions) {
    this.manager = options.manager;
    this._driveName = options.driveName || '';
    let rootPath = this._driveName ? this._driveName + ':' : '';
    this._model = {
      path: rootPath,
      name: PathExt.basename(rootPath),
      type: 'directory',
      content: undefined,
      writable: false,
      created: 'unknown',
      last_modified: 'unknown',
      mimetype: 'text/plain',
      format: 'text'
    };
    this._state = options.state || null;

    const { services } = options.manager;
    services.contents.fileChanged.connect(this._onFileChanged, this);
    services.sessions.runningChanged.connect(this._onRunningChanged, this);

    this._scheduleUpdate();
    this._startTimer();