How to use the nanoid/generate 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 shesek / spark-wallet / src / auth.js View on Github external
module.exports = (app, cookieFile, login) => {
  let username, password, accessKey

  const hasFile = cookieFile && fs.existsSync(cookieFile)

  if (login) { // provided via --login (or LOGIN)
    ;[ username, password, accessKey ] = login.split(':', 3)
    assert(password, `Invalid login format, expecting "username:pwd"`)
  } else if (hasFile) {
    console.log(`Loading login credentials from ${cookieFile}`)
    ;[ username, password, accessKey ] = fs.readFileSync(cookieFile).toString('utf-8').trim().split(':')
    assert(password, `Invalid login file at ${cookieFile}, expecting "username:pwd[:access-key]"`)
  } else { // generate random
    username = nanogen('abcdefghijklmnopqrstuvwxyz', 5)
    password = nanoid(15)
    accessKey = hmacStr(`${username}:${password}`, 'access-key')
    console.log(`No LOGIN or --login specified, picked username "${username}" with password "${password}"`)

    if (cookieFile) {
      console.log(`Writing login credentials to ${cookieFile}`)
      !fs.existsSync(path.dirname(cookieFile)) && mkdirp.sync(path.dirname(cookieFile))
      fs.writeFileSync(cookieFile, [ username, password, accessKey ].join(':'))
    }
  }

  // HMAC derive the access key from the user/pwd combo, if not explicitly defined
  accessKey || (accessKey = hmacStr(`${username}:${password}`, 'access-key'))

  const manifestKey = hmacStr(accessKey, 'manifest-key').substr(0, 10)
      , manifestRe  = new RegExp(`^/manifest-${manifestKey}/`)
github getholo / dashboard / src / types / apps.ts View on Github external
Cat extends Category,
  Variables extends { [key: string]: string },
  Functions extends {
    [key: string]: (arg: any) => MaybePromise
  },
  Dest extends string,
  > {
  constructor(public config: Config) {
    // who the f needs a constructor anyways?
  }

  public functions = this.config.functions;
  public postInstall: (app: this) => any

  public readonly id: appName | string = process.env.NODE_ENV === 'test'
    ? `${this.config.name}-${nanoid('0123456789abcdefghijklmnopqrstuvwxyz', 20)}`
    : this.config.name

  public category = this.config.category;
  public name = this.config.name;
  public variables = new VariablesBackend(this.id, this.config.variables)

  private appdataToPath() {
    // removed linux platform as /opt/appdata requires extra permissions
    return join(homedir(), '.getholo', 'dashboard', 'containers', this.id);
  }

  public paths: Path[] = this.config.paths.map(
    path => ({
      dest: path.dest,
      src: path.src === 'appdata' ? this.appdataToPath() : path.src,
      readOnly: path.readOnly,
github microsoft / BotFramework-Composer / Composer / packages / lib / shared-menus / src / dialogFactory.ts View on Github external
export const seedNewDialog = (
  $type: string,
  designerAttributes: Partial = {},
  optionalAttributes: object = {}
): object => {
  return {
    $type,
    $designer: {
      id: nanoid('1234567890', 6),
      ...designerAttributes,
    },
    ...(initialDialogShape[$type] || {}),
    ...optionalAttributes,
  };
};
github satoshipay / solar / electron / src / storage.ts View on Github external
export function readInstallationID() {
  if (!mainStore.has("installation-id")) {
    mainStore.set("installation-id", generateID("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789", 8))
  }
  return mainStore.get("installation-id")
}
github ivan-kleshnin / unredux / examples / 8.ddl / common / helpers.js View on Github external
export let makeId = () => generate("0123456789abcdef", 10)
github terascope / teraslice / packages / elasticsearch-store / src / utils / model.ts View on Github external
export async function makeId(len = 12): Promise {
    const id = await nanoid(len);
    const result = badIdRegex.exec(id);
    if (result && result[0].length) {
        const chars = generate('1234567890abcdef', result[0].length);
        return id.replace(badIdRegex, chars);
    }
    return id;
}
github thedevs-network / kutt / server / controllers / linkController.ts View on Github external
const generateId = async () => {
  const address = generate(
    "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890",
    Number(process.env.LINK_LENGTH) || 6
  );
  const link = await findLink({ address });
  if (!link) return address;
  return generateId();
};
github freeCodeCamp / freeCodeCamp / api-server / common / models / user.js View on Github external
: user.email;

  if (!user.progressTimestamps) {
    user.progressTimestamps = [];
  }

  if (user.progressTimestamps.length === 0) {
    user.progressTimestamps.push(Date.now());
  }

  if (!user.externalId) {
    user.externalId = uuid();
  }

  if (!user.unsubscribeId) {
    user.unsubscribeId = generate(nanoidCharSet, 20);
  }
  return;
}
github ivan-kleshnin / unredux / examples / 7.2.crud-ssr / common / helpers.js View on Github external
export let makeId = () => generate("0123456789abcdef", 10)
github bugulink / bugu-web / src / utils.js View on Github external
export function genCode(len = 4) {
  return generate('1234567890', len);
}

nanoid

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

MIT
Latest version published 6 days ago

Package Health Score

91 / 100
Full package analysis