How to use the hashids function in hashids

To help you get started, we’ve selected a few hashids 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 expo / expo-cli / packages / xdl / src / Project.ts View on Github external
path.join(outputDir, 'assetmap.json'),
      JSON.stringify(assetmap)
    );
  }

  // Delete keys that are normally deleted in the publish process
  delete exp.hooks;

  // Add assetUrl to manifest
  exp.assetUrlOverride = assetUrl;

  exp.publishedTime = new Date().toISOString();
  exp.commitTime = new Date().toISOString();

  // generate revisionId and id the same way www does
  const hashIds = new HashIds(uuid.v1(), 10);
  exp.revisionId = hashIds.encode(Date.now());

  if (options.isDev) {
    exp.developer = {
      tool: 'exp',
    };
  }

  if (!exp.slug) {
    throw new XDLError('INVALID_MANIFEST', 'Must provide a slug field in the app.json manifest.');
  }
  let username = await UserManager.getCurrentUsernameAsync();
  if (!username) {
    username = ANONYMOUS_USERNAME;
  }
  exp.id = `@${username}/${exp.slug}`;
github expo / expo-cli / packages / xdl / src / Project.js View on Github external
path.join(outputDir, 'assetmap.json'),
      JSON.stringify(assetmap)
    );
  }

  // Delete keys that are normally deleted in the publish process
  delete exp.hooks;

  // Add assetUrl to manifest
  exp.assetUrlOverride = assetUrl;

  exp.publishedTime = new Date().toISOString();
  exp.commitTime = new Date().toISOString();

  // generate revisionId and id the same way www does
  const hashIds = new HashIds(uuid.v1(), 10);
  exp.revisionId = hashIds.encode(Date.now());

  if (options.isDev) {
    exp.developer = {
      tool: 'exp',
    };
  }

  if (!exp.slug) {
    throw new XDLError(
      ErrorCode.INVALID_MANIFEST,
      'Must provide a slug field in the app.json manifest.'
    );
  }
  let username = await UserManager.getCurrentUsernameAsync();
  if (!username) {
github rinvex / cortex / resources / js / app.js View on Github external
import './vendor/bootstrap-popover-picker';

// Misc
import 'select2';
import './vendor/slugify';
import Hashids from 'hashids';
import Dropzone from 'dropzone';
import './vendor/jquery-validation';
import 'expose-loader?moment!moment';
import 'expose-loader?implicitForms!./vendor/jquery-implicitforms';

// Translations
import Lang from './vendor/lang';
import messages from '../../public/js/messages';
window.Lang = new Lang({ messages, fallback: 'en' });
window.hashids = new Hashids(
    process.env.MIX_HASHIDS_KEY,
    Number(process.env.MIX_HASHIDS_LENGTH),
    process.env.MIX_HASHIDS_ALPHABET
);

import Echo from 'laravel-echo';

window.Pusher = require('pusher-js');

window.Echo = new Echo({
    broadcaster: 'pusher',
    key: process.env.MIX_PUSHER_APP_KEY,
    cluster: process.env.MIX_PUSHER_APP_CLUSTER,
    forceTLS: true
});
github atomicptr / dauntless-builder / src / models / BuildModel.jsx View on Github external
import Hashids from "hashids";
import DataUtility from "../utility/DataUtility";
import ItemUtility from "../utility/ItemUtility";

const hashids = new Hashids("spicy");

export default class BuildModel {
    constructor(data) {
        // set default parameter values
        this.__version = 3;
        this.weapon_name = "";
        this.weapon_level = 0;
        this.weapon_part1_name = "";
        this.weapon_part2_name = "";
        this.weapon_part3_name = "";
        this.weapon_part4_name = "";
        this.bond_weapon_name = "";
        this.weapon_part6_name = "";
        this.weapon_cell0 = "";
        this.weapon_cell1 = "";
        this.torso_name = "";
github Xetera / hifumi / events / resizer.ts View on Github external
import fetch from "node-fetch";
import sharp, { Metadata } from "sharp";
import { S3 } from "aws-sdk";
import gm, { State } from "gm";
import mime from "mime-types";
import Hashids from "hashids";

// please don't look at this salt to try to reverse engineer the
// ids of images, I trust that you're all good boys.
const SALT = "hifumi";
const hash = new Hashids(SALT);

const s3 = new S3();

const img = gm.subClass({ imageMagick: true });

const RESIZE_WIDTH = 300;
const { EVENTS_BUCKET_NAME } = process.env;

interface DownloadedImage {
  readonly image: Buffer;
  readonly meta: Metadata;
}

const convertCallbacks = (res, rej) => (e, data) => {
  if (e) return rej(e);
  res(data);
github Xetera / hifumi / events / src / resizer.ts View on Github external
import { Metadata, metadata, img, toBuffer, bufferSize } from "./magick";
import mime from "mime-types";
import Hashids from "hashids";
import { updateImage } from "./gql";
import { State } from "gm";
import { PromiseResult } from "aws-sdk/lib/request";

// please don't look at this salt to try to reverse engineer the
// ids of images, I trust that you're all good boys.
const SALT = "hifumi";
const COMPRESSION_TYPE = "LZMA";
const RESIZE_WIDTH = 300;

const noopAsync = (): Promise => Promise.resolve();
const s3 = new S3();
const hash = new Hashids(SALT);
const { EVENTS_BUCKET_NAME, EVENTS_CDN_ROOT } = process.env;

type DownloadedImage = Readonly<{
  image: Buffer;
  state: State;
  meta: Metadata;
}>;

const getBuffer = (url: string): Promise =>
  fetch(url).then(r => r.buffer());

const resizeImage = (state: State) =>
  state.resize(RESIZE_WIDTH).compress(COMPRESSION_TYPE);

const compress = (state: State) => state.compress(COMPRESSION_TYPE);
github birkir / prime / packages / prime-core / src / models / ContentEntry.ts View on Github external
Column,
  CreatedAt,
  DataType,
  Default,
  DeletedAt,
  ForeignKey,
  Model,
  PrimaryKey,
  Table,
  UpdatedAt,
} from 'sequelize-typescript';
import { ContentRelease } from './ContentRelease';
import { ContentType } from './ContentType';
import { User } from './User';

const hashid = new hashids('SaltingTheHash', 10);

@Table
export class ContentEntry extends Model {
  // --- Static methods

  @BeforeCreate
  public static async SET_ENTRY_ID(instance: ContentEntry) {
    if (!instance.entryId) {
      instance.entryId = await ContentEntry.GET_RANDOM_ID();
    }
  }

  public static async GET_RANDOM_ID() {
    const entryId = hashid.encode(+new Date());
    const count = await ContentEntry.count({
      where: {
github electron-userland / electron-remote / src / execute-js-func.js View on Github external
const requestChannel = 'execute-javascript-request';
const responseChannel = 'execute-javascript-response';
const rootEvalProxyName = 'electron-remote-eval-proxy';
const requireElectronModule = '__requireElectronModule__';

const electron = require('electron');
const isBrowser = (process.type === 'browser');
const ipc = electron[isBrowser ? 'ipcMain' : 'ipcRenderer'];

const d = require('debug')('electron-remote:execute-js-func');
const webContents = isBrowser ?
  electron.webContents :
  electron.remote.webContents;

let nextId = 1;
const hashIds = new Hashids();

function getNextId() {
  return hashIds.encode(process.pid, nextId++);
}

/**
 * Determines the identifier for the current process (i.e. the thing we can use
 * to route messages to it)
 *
 * @return {object} An object with either a `guestInstanceId` or a `webContentsId`
 */
export function getSenderIdentifier() {
  if (isBrowser) return {};

  if (process.guestInstanceId) {
    return { guestInstanceId: process.guestInstanceId };

hashids

Generate YouTube-like ids from numbers. Use Hashids when you do not want to expose your database ids to the user.

MIT
Latest version published 11 months ago

Package Health Score

77 / 100
Full package analysis

Popular hashids functions