How to use the @jupyterlab/coreutils.uuid 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 / codemirror / src / editor.ts View on Github external
constructor(options: CodeMirrorEditor.IOptions) {
    let host = this.host = options.host;
    host.classList.add(EDITOR_CLASS);
    host.classList.add('jp-Editor');
    host.addEventListener('focus', this, true);
    host.addEventListener('scroll', this, true);

    this._uuid = options.uuid || uuid();

    // Handle selection style.
    let style = options.selectionStyle || {};
    this._selectionStyle = {
        ...CodeEditor.defaultSelectionStyle,
        ...style as CodeEditor.ISelectionStyle
    };

    let model = this._model = options.model;
    let editor = this._editor = CodeMirror(host, {});
    Private.handleConfig(editor, options.config || {});

    let doc = editor.getDoc();

    // Handle initial values for text, mimetype, and selections.
    doc.setValue(model.value.text);
github jupyterlab / jupyterlab / packages / docmanager / src / actions.ts View on Github external
function overwrite(manager: IServiceManager, oldPath: string, newPath: string, basePath = ''): Promise {
    // Cleanly overwrite the file by moving it, making sure the original
    // does not exist, and then renaming to the new path.
    const tempPath = `${newPath}.${uuid()}`;
    const cb = () => rename(manager, tempPath, newPath, basePath);
    return rename(manager, oldPath, tempPath, basePath).then(() => {
      return deleteFile(manager, newPath);
    }).then(cb, cb);
  }
github jupyterlab / jupyterlab / tests / test-coreutils / src / uuid.spec.ts View on Github external
it('should accept a length', () => {
      let id0 = uuid(10);
      let id1 = uuid(10);
      expect(id0.length).to.equal(10);
      expect(id1.length).to.equal(10);
      expect(id0).to.not.equal(id1);
    });
  });
github jupyterlab / jupyterlab / tests / test-coreutils / src / uuid.spec.ts View on Github external
it('should generate a random 32 character hex string', () => {
      let id0 = uuid();
      let id1 = uuid();
      expect(id0.length).to.equal(32);
      expect(id1.length).to.equal(32);
      expect(id0).to.not.equal(id1);
    });
github jupyterlab / jupyterlab / tests / test-coreutils / src / uuid.spec.ts View on Github external
it('should generate a random 32 character hex string', () => {
      let id0 = uuid();
      let id1 = uuid();
      expect(id0.length).to.equal(32);
      expect(id1.length).to.equal(32);
      expect(id0).to.not.equal(id1);
    });
github jupyterlab / jupyterlab / tests / test-docregistry / src / registry.spec.ts View on Github external
function createFactory(modelName?: string) {
  return new WidgetFactory({
    name: uuid(),
    modelName: modelName || 'text',
    fileTypes: ['text', 'foobar'],
    defaultFor: ['text', 'foobar']
  });
}
github jupyterlab / jupyterlab-google-drive / test / src / panel.spec.ts View on Github external
import { Context, DocumentRegistry } from '@jupyterlab/docregistry';

import { ServiceManager, Contents } from '@jupyterlab/services';

import { uuid } from '@jupyterlab/coreutils';

import { Chatbox, ChatboxPanel, ChatboxDocumentInfo } from '../../lib/chatbox';

import { createFileContext, defaultRenderMime } from './util';

/**
 * The common file model.
 */
const FILE: Partial = {
  path: uuid() + '.txt',
  type: 'file',
  mimetype: 'text/plain',
  content: 'Hello, world',
  format: 'text'
};

/**
 * Factory stuff.
 */
const editorFactory = editorServices.factoryService.newInlineEditor.bind(
  editorServices.factoryService
);
const contentFactory = new ChatboxPanel.ContentFactory({ editorFactory });
const rendermime = defaultRenderMime();

describe('chatbox/panel', () => {
github jupyterlab / jupyterlab / packages / services / src / kernel / default.ts View on Github external
constructor(options: Kernel.IOptions, id: string) {
    this._name = options.name;
    this._id = id;
    this.serverSettings = options.serverSettings || ServerConnection.makeSettings();
    this._clientId = options.clientId || uuid();
    this._username = options.username || '';
    this._futures = new Map();
    this._commPromises = new Map>();
    this._comms = new Map();
    this._createSocket();
    this.terminated = new Signal(this);
    Private.runningKernels.push(this);
  }
github yuvipanda / simplest-notebook / packages / cells / src / model.ts View on Github external
constructor(options: CellModel.IOptions) {
    super({modelDB: options.modelDB});

    this.id = options.id || uuid();

    this.value.changed.connect(this.onGenericChange, this);

    let cellType = this.modelDB.createValue('type');
    cellType.set(this.type);

    let observableMetadata = this.modelDB.createMap('metadata');
    observableMetadata.changed.connect(this.onGenericChange, this);

    let cell = options.cell;
    let trusted = this.modelDB.createValue('trusted');
    trusted.changed.connect(this.onTrustedChanged, this);

    if (!cell) {
      trusted.set(false);
      return;
github jupyterlab / jupyterlab / packages / services / src / kernel / default.ts View on Github external
connectToComm(targetName: string, commId?: string): Kernel.IComm {
    if (commId === void 0) {
      commId = uuid();
    }
    let comm = this._comms.get(commId);
    if (!comm) {
      comm = new CommHandler(
        targetName,
        commId,
        this,
        () => { this._unregisterComm(commId); }
      );
      this._comms.set(commId, comm);
    }
    return comm;
  }