How to use cuid - 10 common examples

To help you get started, we’ve selected a few cuid 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 keystonejs / keystone / test-projects / basic / cypress / integration / oembed_spec.js View on Github external
const saveValue = value => {
  cy.get(oembedInputSelector).clear();
  if (value) {
    cy.get(oembedInputSelector).type(value, { force: true });
  }
  const alias = cuid.slug();
  // Setup to track XHR requests
  cy.server();
  // Alias the graphql request route
  cy.route('post', '**/admin/api').as(alias);
  // Avoid accidentally mocking routes
  cy.server({ enable: false });
  cy.get('#item-page-save-button').click({ force: true });
  return cy.wait(`@${alias}`);
};
github clay / clay-kiln / test / setupFile.js View on Github external
// global functions to mount vue components
global.mount = mount;
global.shallowMount = shallowMount; // use when you don't want to render child components

// mock logger, so you can check that mockLogger was called
global.mockLogger = jest.fn();
jest.mock('clay-log', () => ({
  init: () => {},
  meta: () => mockLogger
}));

global.window.kiln = { inputs: {} };

// mock cuid because it doesn't like being run in jsdom
jest.mock('cuid');
cuid.default.mockReturnValue('abc');

// add jsdom-compliant quill polyfill for dealing with deltas
jest.mock('quill/dist/quill.min.js');
Quill.mockImplementation(function QuillMock() {
  this.root = { innerHTML: '' };
  this.setContents = function (delta) {
    this.root.innerHTML = convertDeltaToHtml(delta);
  };
  this.imports = {}; // phrase blots
  this.register = function (blotName, blotConfig) {
    this.imports[blotName] = blotConfig;
  };
});
// note: yeah, we're using actual quill deltas here. pretty snazzy eh?
Quill.import.mockImplementation(() => Delta);
github jirokun / survey-designer-js / lib / editor / components / editors / FinisherEditor.js View on Github external
constructor(props) {
    super(props);
    // tinymceがかぶらないようにするためにcuidを生成
    this.cuid = cuid();
  }
github MoonMail / MoonMail / lists-microservice / src / domain / ListModel.js View on Github external
static get createSchema() {
    return Joi.object({
      userId: Joi.string().required(),
      id: Joi.string().default(cuid()),
      createdAt: Joi.number().default(moment().unix()),
      importStatus: Joi.object(),
      isDelete: Joi.string().default(false.toString()),
      name: Joi.string().required(),
      // Not sure if this should be required
      senderId: Joi.string()
    });
  }
github TiE23 / metric-teacher / client / src / components / challenge / ChallengePage.js View on Github external
this.handleQuestionModeStart = () => {
      this.setState({
        questionModeStart: true,
        challengeId: cuid.slug(),
        selectedQuestionIds: [
          // Put question ids here.
          // Run by calling this function with a button click. Ideally in ChallengeKickoff.
        ],
      });
    };
  }
github eventespresso / event-espresso-core / assets / src / data / eventespresso / core / actions / persist-relations-generators.js View on Github external
) {
	modelName = singularModelName( modelName );
	relationName = singularModelName( relationName );
	relationState = yield resolveDispatch(
		CORE_REDUCER_KEY,
		'getRelationState',
		modelName,
		addRelation,
		relationState
	);
	let entityIdChanged = false;
	if ( isEmpty( relationState ) ) {
		return 0;
	}
	// is the entityId a cuid?  If so, then let's persist.
	if ( cuid.isCuid( entityId ) ) {
		entityId = yield resolveDispatch(
			CORE_REDUCER_KEY,
			'persistNewEntityAndRemoveDirtyRelations',
			relationName,
			relationId,
			modelName,
			entityId,
			addRelation,
			[ modelName, entityId ],
		);
		// if entityId is 0 bail because it didn't get persisted so relations
		// can't be persisted either.
		if ( entityId === 0 ) {
			return entityId;
		}
		entityIdChanged = true;
github eventespresso / event-espresso-core / assets / src / data / eventespresso / core / reducers / dirty-relations.js View on Github external
);
			return state.set(
				'add',
				updateRelationState(
					Map( state.get( 'add' ) ),
					action,
					relationMap
				)
			);
		case types.RECEIVE_DIRTY_RELATION_DELETION:
		case types.REMOVE_DIRTY_RELATION_DELETION:
			// if the relation or entity id is a cuid, then we skip this because
			// the relation has never been persisted anyways.
			if (
				cuid.isCuid( action.relationEntityId ) ||
				cuid.isCuid( action.entityId )
			) {
				return state;
			}
			state = state.set(
				'index',
				indexRelations(
					Map( state.get( 'index' ) ),
					action,
					relationMap
				)
			);
			return state.set(
				'delete',
				updateRelationState(
					Map( state.get( 'delete' ) ),
					action,
github eventespresso / event-espresso-core / assets / ZZZ / editor / events / tickets / editor-ticket / edit-form / edit-ticket-form.js View on Github external
prefix,
		updateField,
		touchField
	});
	// entity properties we don't want to be editable
	const exclude = [
		'TKT_ID',
		'sold',
		'reserved',
		'order',
		'parent',
		'wpUser',
		'status'
	];

	const isNewTicket = cuid.isCuid(ticketEntity.TKT_ID);

	if (isNewTicket) {
		exclude.push('deleted');
	}

	const formRows = useEditEntityFormInputs(
		ticketEntity,
		inputConfig,
		prefix,
		currentValues,
		exclude
	);

	return useMemo(() => {
		// edit forms for existing objects must have initial values
		return !(!newObject && isEmpty(initialValues)) ? (
github eventespresso / event-espresso-core / assets / src / editor / events / tickets / editor-ticket / edit-form / edit-ticket-form.js View on Github external
prefix,
		updateField,
		touchField,
	} );
	// entity properties we don't want to be editable
	const exclude = [
		'TKT_ID',
		'sold',
		'reserved',
		'order',
		'parent',
		'wpUser',
		'status',
	];

	const isNewTicket = cuid.isCuid( ticketEntity.TKT_ID );

	if ( isNewTicket ) {
		exclude.push( 'deleted' );
	}

	const formRows = useEditEntityFormInputs(
		ticketEntity,
		inputConfig,
		prefix,
		currentValues,
		exclude
	);

	return useMemo(
		() => {
			// edit forms for existing objects must have initial values
github eventespresso / event-espresso-core / assets / src / data / eventespresso / core / reducers / dirty-relations.js View on Github external
)
			);
			return state.set(
				'add',
				updateRelationState(
					Map( state.get( 'add' ) ),
					action,
					relationMap
				)
			);
		case types.RECEIVE_DIRTY_RELATION_DELETION:
		case types.REMOVE_DIRTY_RELATION_DELETION:
			// if the relation or entity id is a cuid, then we skip this because
			// the relation has never been persisted anyways.
			if (
				cuid.isCuid( action.relationEntityId ) ||
				cuid.isCuid( action.entityId )
			) {
				return state;
			}
			state = state.set(
				'index',
				indexRelations(
					Map( state.get( 'index' ) ),
					action,
					relationMap
				)
			);
			return state.set(
				'delete',
				updateRelationState(
					Map( state.get( 'delete' ) ),

cuid

Collision-resistant ids optimized for horizontal scaling and performance. For node and browsers.

MIT
Latest version published 2 years ago

Package Health Score

61 / 100
Full package analysis