hashids2 1.0.2

  • readme.md
  • Example
  • Installing
  • Versions
  • 64

Hashids2 #

Build Status Coverage Status pub package

A Dart class to generate YouTube-like hashes from one or many numbers.

Ported from javascript hashids.js by Ivan Akimov

What is it? #

Hashids (Hash ID's) creates short, unique, decryptable hashes from unsigned (long) integers.

This algorithm tries to satisfy the following requirements:

  1. Hashes must be unique and decryptable.
  2. They should be able to contain more than one integer (so you can use them in complex or clustered systems).
  3. You should be able to specify minimum hash length.
  4. Hashes should not contain basic English curse words (since they are meant to appear in public places - like the URL).

Instead of showing items as 1, 2, or 3, you could show them as U6dc, u87U, and HMou. You don't have to store these hashes in the database, but can encrypt + decrypt on the fly.

All (long) integers need to be greater than or equal to zero.

Usage #

Import the package #

Add to the pubspec.yaml

    hashids2: ^1.0.1

Encrypting #

final hashids = HashIds();
final fromNumber = hashids.encode(42);
final fromList = hashids.encode([1,2,3]);
final fromString = hashids.encode('42');

Decrypting #

final hashids = HashIds();
final number = hashids.decode(fromNumber); // [42]
final list = hashids.decode(fromList); // [1,2,3]
final string = hashids.decode(fromString); // [42]

License #

See the LICENSE file.

Changelog #

1.0.2 #

  • Docuemntation added
  • Dead code removed
  • More unit tests

1.0.1 #

  • Add basic example
  • Use named parameters

1.0.0 #

  • Ported to Dart 2


import 'package:hashids2/hashids2.dart';

void main() {
  final hashids = HashIds(
    salt: 'this is my salt',
    minHashLength: 8,
    alphabet: 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890',
  final id = hashids.encode([1, 2, 3]);
  final numbers = hashids.decode(id);

Use this package as a library

1. Depend on it

Add this to your package's pubspec.yaml file:

  hashids2: ^1.0.2

2. Install it

You can install packages from the command line:

with pub:

$ pub get

with Flutter:

$ flutter pub get

Alternatively, your editor might support pub get or flutter pub get. Check the docs for your editor to learn more.

3. Import it

Now in your Dart code, you can use:

import 'package:hashids2/hashids2.dart';
Version Uploaded Documentation Archive
1.0.2 Mar 19, 2019 Go to the documentation of hashids2 1.0.2 Download hashids2 1.0.2 archive
1.0.1 Mar 13, 2019 Go to the documentation of hashids2 1.0.1 Download hashids2 1.0.1 archive
1.0.0 Mar 13, 2019 Go to the documentation of hashids2 1.0.0 Download hashids2 1.0.0 archive
Describes how popular the package is relative to other packages. [more]
Code health derived from static analysis. [more]
Reflects how tidy and up-to-date the package is. [more]
Weighted score of the above. [more]
Learn more about scoring.

We analyzed this package on Jun 4, 2019, and provided a score, details, and suggestions below. Analysis was completed with status completed using:

  • Dart: 2.3.1
  • pana: 0.12.17


Detected platforms: Flutter, web, other

No platform restriction found in primary library package:hashids2/hashids2.dart.


Package Constraint Resolved Available
Direct dependencies
Dart SDK >=2.1.0 <3.0.0
Dev dependencies
test >=0.12.42 <2.0.0
test_coverage ^0.2.0