How to use the nanoid/non-secure function in nanoid

To help you get started, we’ve selected a few nanoid 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 pieterbeulque / anonymous-analytics / index.js View on Github external
const getClientId = () => {
	const existing = store.get(ANONYMOUS_ANALYTICS_CLIENT_ID);

	if (existing) {
		return existing;
	}

	try {
		return nanoid();
	} catch (error) {
		// The Web Crypto API is probably not supported
		// Return a LEGACY-TIMESTAMP id
		return `LEGACY-${(new Date()).getTime()}`;
	}
};
github xaviergonz / mobx-keystone / packages / lib / src / snapshot / fixSnapshotIds.ts View on Github external
ctx: FixSnapshotIdsContext
): AnyModel {
  const { type, id } = sn[modelMetadataKey]

  if (!id) {
    throw failure(
      `a model a snapshot must contain an id (${modelMetadataKey}.id) key, but none was found`
    )
  }

  const modelInfo = getModelInfoForName(type)
  if (!modelInfo) {
    throw failure(`model with name "${type}" not found in the registry`)
  }

  const newId = nanoid()
  ctx.idMap.set(id, newId)

  const modelSn: any = {
    [modelMetadataKey]: {
      id: newId,
      type,
    },
  }

  const snKeys = Object.keys(sn)
  const snKeysLen = snKeys.length
  for (let i = 0; i < snKeysLen; i++) {
    const k = snKeys[i]
    if (!isReservedModelKey(k)) {
      const v = sn[k]
      modelSn[k] = internalFixSnapshotIds(v, ctx)
github Justineo / vue-awesome / src / components / Icon.vue View on Github external
function getId (prefix = '') {
  return prefix + nanoid(7)
}

nanoid

A tiny (118 bytes), secure URL-friendly unique string ID generator

MIT
Latest version published 26 days ago

Package Health Score

91 / 100
Full package analysis