How to use hashids - 10 common examples

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 staart / api / src / helpers / utils.ts View on Github external
import dns from "dns";
import Joi from "@hapi/joi";
import { getOrganizationIdFromUsername } from "../crud/organization";
import { Request, Response } from "express";
import slugify from "slugify";
import cryptoRandomString from "crypto-random-string";
import { Tokens } from "../interfaces/enum";
import { ApiKeyResponse } from "./jwt";
import { isMatch } from "matcher";
import Hashids from "hashids/cjs";
import { getUserIdFromUsername } from "../crud/user";
import { HASH_IDS, HASH_ID_PREFIX } from "../config";
import systemInfo from "systeminformation";
import pkg from "../../package.json";

const hashIds = new Hashids(
  HASH_IDS,
  10,
  "abcdefghijklmnopqrstuvwxyz1234567890"
);

/**
 * Capitalize each first letter in a string
 */
export const capitalizeEachFirstLetter = (string: string) =>
  (string = string
    .toLowerCase()
    .split(" ")
    .map(s => s.charAt(0).toUpperCase() + s.toLowerCase().substring(1))
    .join(" "));

/**
github staart / api / src / helpers / utils.ts View on Github external
import anonymize from "ip-anonymize";
import { User } from "../interfaces/tables/user";
import dns from "dns";
import Joi from "@hapi/joi";
import { getOrganizationIdFromUsername } from "../crud/organization";
import { Request, Response } from "express";
import slugify from "slugify";
import cryptoRandomString from "crypto-random-string";
import { Tokens } from "../interfaces/enum";
import { ApiKeyResponse } from "./jwt";
import { isMatch } from "matcher";
import Hashids from "hashids/cjs";
import { getUserIdFromUsername } from "../crud/user";
import { HASH_IDS, HASH_ID_PREFIX } from "../config";

const hashIds = new Hashids(
  HASH_IDS,
  10,
  "abcdefghijklmnopqrstuvwxyz1234567890"
);

/**
 * Capitalize each first letter in a string
 */
export const capitalizeEachFirstLetter = (string: string) =>
  (string = string
    .toLowerCase()
    .split(" ")
    .map(s => s.charAt(0).toUpperCase() + s.toLowerCase().substring(1))
    .join(" "));

/**
github dessalines / simple-vote / ui / src / app / shared / tools.class.ts View on Github external
static decodeHashId(hashId: string): DecodedHashId {
		let hashids = new Hashids("");
		if (hashId.startsWith(this.hashIdReadOnlyPrefix)) {
			return {
				id: hashids.decode(hashId.split(this.hashIdReadOnlyPrefix)[1])[0],
				readOnly: true
			}
		} else {
			return {
				id: hashids.decode(hashId)[0],
				readOnly: false
			}
		}
	}

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 1 year ago

Package Health Score

62 / 100
Full package analysis

Popular hashids functions