How to use the shortid.generate function in shortid

To help you get started, we’ve selected a few shortid 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 vinz243 / cassette / src / server / features / jobs / JobTorrent.js View on Github external
constructor (props) {
    this.props = Object.assign({}, this.defaultProps, props);
    assert(/^(\d|[a-f]){40}$/i.test(this.props.infoHash));

    if (!this.props._id) {
      this.props._id = shortid.generate();
    }
  }
  getData() {
github cam-inc / viron / src / store / mutations / endpoints.js View on Github external
forOwn(endpoints, endpoint => {
      let duplicatedEndpoint = find(modifiedEndpoints, val => {
        return endpoint.url === val.url;
      });

      if (!duplicatedEndpoint) {
        const key = shortid.generate();
        endpoint.key = key;
        modifiedEndpoints[key] = endpoint;
      } else {
        ObjectAssign(duplicatedEndpoint, endpoint);
      }
    });
github bitfocus / companion / lib / update.js View on Github external
update.prototype.uuid = function() {
	var self = this;
	var uuid = shortid.generate();

	if (fs.existsSync(self.cfgdir + 'machid')) {
		var text = "";
		try {
			text = fs.readFileSync(self.cfgdir + 'machid');
			if (text) {
				uuid = text.toString();
				debug('read uuid', uuid);
			}
		} catch(e) {
			debug('error reading uuid-file', e);
		}
	}
	else {
		debug('creating uuid file');
		fs.writeFileSync(self.cfgdir + 'machid', uuid);
github LiveHelperChat / livehelperchat / lhc_web / design / defaulttheme / js / react / src / components / builder / NodeTriggerActionCollectable.js View on Github external
addField() {
        this.props.addSubelement({id : this.props.id, 'path' : ['content','collectable_fields'], 'default' : {'_id': shortid.generate(), 'type' : 'text', content : {'message' : '', 'name' : '', 'validation' : '', 'field' : ''}}});
    }
github salesforce / design-system-react / components / navigation / index.jsx View on Github external
componentWillMount () {
		this.generatedId = shortid.generate();
	},
github mrdulin / apollo-server-express-starter / src / subscription / demo-1 / server.js View on Github external
const http = require('http');
const bodyParser = require('body-parser');
const { graphqlExpress, graphiqlExpress } = require('apollo-server-express');
const { makeExecutableSchema } = require('graphql-tools');
const { PubSub, withFilter } = require('graphql-subscriptions');
const { SubscriptionServer } = require('subscriptions-transport-ws');
const { execute, subscribe } = require('graphql');
const shortid = require('shortid');
const casual = require('casual');
const cors = require('cors');

const pubsub = new PubSub();

const orgId = shortid.generate();
const locationId1 = shortid.generate();
const locationId2 = shortid.generate();

const db = {
  locations: [{ id: locationId1, orgId, name: casual.address2 }, { id: locationId2, orgId, name: casual.address2 }],
  users: [
    {
      id: shortid.generate(),
      name: casual.name,
      email: casual.email,
      orgId: null,
      locationId: locationId1,
      userType: 'ZELO'
    },
    { id: shortid.generate(), name: casual.name, email: casual.email, orgId, locationId: null, userType: 'ZEWI' },
    { id: shortid.generate(), name: casual.name, email: casual.email, orgId, locationId: null, userType: 'ZOWI' }
  ],
  comments: [
github danielstern / flux-redux / src / tasks.js View on Github external
getInitialState() {
        return {
            tasks: [{
                id: id(),
                content: "Update CSS styles",
                complete: false
            }, {
                id: id(),
                content: "Add unit tests",
                complete: false
            }, {
                id: id(),
                content: "Post to social media",
                complete: false
            },{
                id: id(),
                content: "Install hard drive",
                complete: true
            }],
            showComplete:true
github mrdulin / apollo-server-express-starter / src / n+1 / db.ts View on Github external
function generateData(): IDb {
  const books: IBook[] = [];
  const users: IUser[] = [];

  for (let i: number = 0; i < 2; i++) {
    const user: IUser = { id: shortid.generate(), name: casual.name };
    users.push(user);
  }

  for (let i: number = 0; i < 10; i++) {
    const ranInt: number = getRandomInt(0, users.length - 1);
    const { id: authorId }: { id: string } = users[ranInt];
    const book: IBook = { id: shortid.generate(), title: casual.title, authorId };
    books.push(book);
  }

  return { books, users };
}
github Automattic / component-themes / src / lib / component-builder.js View on Github external
function buildComponentTreeFromConfig( componentConfig, childProps = {} ) {
	const { id, componentType, children, props, partial } = componentConfig;
	if ( partial ) {
		return buildComponentTreeFromConfig( getPartialByType( partial ), childProps );
	}
	const componentId = id || shortid.generate();
	const Component = getComponentByType( componentType );
	const childComponents = children ? children.map( child => buildComponentTreeFromConfig( child, childProps ) ) : null;
	const componentProps = Object.assign(
		{},
		props || {},
		{ childProps },
		{ className: classNames( componentType, componentId ), key: componentId }
	);
	return { Component, componentId, componentProps, childComponents, componentType };
}

shortid

Amazingly short non-sequential url-friendly unique id generator.

MIT
Latest version published 4 years ago

Package Health Score

58 / 100
Full package analysis