Skip to content

Commit dac219c

Browse files
committed
Use named parameters
1 parent 5b5edb7 commit dac219c

10 files changed

Lines changed: 25 additions & 26 deletions

example/main.dart

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
import 'package:hashids2/hashids2.dart';
2+
3+
void main() {
4+
final hashids = HashIds(
5+
salt: 'this is my salt',
6+
minHashLength: 8,
7+
alphabet: 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890',
8+
);
9+
final id = hashids.encode([1, 2, 3]);
10+
final numbers = hashids.decode(id);
11+
print(numbers);
12+
}

lib/hashids2.dart

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@ import 'dart:core';
22

33
class HashIds {
44
HashIds(
5-
[String salt = DEFAULT_SALT,
5+
{String salt = DEFAULT_SALT,
66
int minHashLength = DEFAULT_MIN_HASH_LENGTH,
7-
String alphabet = DEFAULT_ALPHABET]) {
7+
String alphabet = DEFAULT_ALPHABET}) {
88
this.salt = salt != null ? salt : DEFAULT_SALT;
99
this.minHashLength =
1010
minHashLength > 0 ? minHashLength : DEFAULT_MIN_HASH_LENGTH;

test/all_test.dart

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,8 @@ import 'custom_salt.dart';
66
import 'default_params.dart';
77
import 'default_params_hex.dart';
88
import 'encode_types.dart';
9-
import 'sample.dart';
109

1110
void main() {
12-
sampleTest();
1311
badInputTest();
1412
customSaltTest();
1513
customAlphabetTest();

test/bad_input.dart

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,15 @@ void badInputTest() {
55
group('bad input', () {
66
test('should throw an error when small alphabet', () {
77
try {
8-
HashIds('', 0, '1234567890');
8+
HashIds(alphabet: '1234567890');
99
} catch (e) {
1010
expect(1, 1);
1111
}
1212
});
1313

1414
test('should throw an error when alphabet has spaces', () {
1515
try {
16-
HashIds('', 0, 'a cdefghijklmnopqrstuvwxyz');
16+
HashIds(alphabet: 'a cdefghijklmnopqrstuvwxyz');
1717
} catch (e) {
1818
expect(1, 1);
1919
}

test/custom_alphabet.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import 'package:test/test.dart';
33

44
void customAlphabetTest() {
55
final testAlphabet = (String alphabet) {
6-
final hashids = HashIds('', 0, alphabet);
6+
final hashids = HashIds(alphabet: alphabet);
77
final numbers = [1, 2, 3];
88

99
final id = hashids.encode(numbers);

test/custom_params.dart

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,9 @@ import 'package:test/test.dart';
44
void customParamsTest() {
55
const minLength = 30;
66
final hashids = HashIds(
7-
'this is my salt', minLength, 'xzal86grmb4jhysfoqp3we7291kuct5iv0nd');
7+
salt: 'this is my salt',
8+
minHashLength: minLength,
9+
alphabet: 'xzal86grmb4jhysfoqp3we7291kuct5iv0nd');
810

911
final map = {
1012
'nej1m3d5a6yn875e7gr9kbwpqol02q': [0],

test/custom_params_hex.dart

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,9 @@ import 'package:test/test.dart';
44
void customParamsHexTest() {
55
const minLength = 30;
66
final hashids = HashIds(
7-
'this is my salt', minLength, 'xzal86grmb4jhysfoqp3we7291kuct5iv0nd');
7+
salt: 'this is my salt',
8+
minHashLength: minLength,
9+
alphabet: 'xzal86grmb4jhysfoqp3we7291kuct5iv0nd');
810

911
final map = {
1012
'0dbq3jwa8p4b3gk6gb8bv21goerm96': 'deadbeef',

test/custom_salt.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import 'package:test/test.dart';
33

44
void customSaltTest() {
55
final testSalt = (String salt) {
6-
final hashIds = HashIds(salt);
6+
final hashIds = HashIds(salt: salt);
77
final numbers = [1, 2, 3];
88

99
final id = hashIds.encode(numbers);

test/min_length.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import 'package:test/test.dart';
44
void minLengthTest() {
55
group('min length', () {
66
final testMinLength = (int minLength) {
7-
final hashids = HashIds('', minLength);
7+
final hashids = HashIds(minHashLength: minLength);
88
final numbers = [1, 2, 3];
99

1010
final id = hashids.encode(numbers);

test/sample.dart

Lines changed: 0 additions & 15 deletions
This file was deleted.

0 commit comments

Comments
 (0)