hashids2 1.0.2

  • Readme
  • Changelog
  • Example
  • Installing
  • 84

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

dependencies:y
    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

example/main.dart

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);
  print(numbers);
}

Use this package as a library

1. Depend on it

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


dependencies:
  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';
  
Popularity:
Describes how popular the package is relative to other packages. [more]
68
Health:
Code health derived from static analysis. [more]
100
Maintenance:
Reflects how tidy and up-to-date the package is. [more]
100
Overall:
Weighted score of the above. [more]
84
Learn more about scoring.

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

  • Dart: 2.6.0
  • pana: 0.12.21

Platforms

Detected platforms: Flutter, web, other

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

Dependencies

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