Skip to content

Commit

Permalink
Exported standard alphabets (0.1.1)
Browse files Browse the repository at this point in the history
  • Loading branch information
Bhargav committed Sep 13, 2021
1 parent 2db672f commit 976aabe
Show file tree
Hide file tree
Showing 8 changed files with 120 additions and 11 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
## 0.1.1

- Exported standard alphabets

## 0.1.0

- Initial development release
Expand Down
34 changes: 32 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,25 @@ A Dart library for converting between different bases, e.g., decimal ↔ binary,

See `example/main.dart`

### Decimal (emoji) ↔ Hexadecimal
#### Hexadecimal ↔ Base58
```dart
final BaseConversion hexadecimalToBase58Converter = BaseConversion(
from: '0123456789abcdef',
to: base58,
);
final String base58Value = hexadecimalToBase58Converter('415a59758fb933b6049b050a556dd4d916b7b483f6966615');
// base58Value == '6xZA4Qt9vH7rePWeT5WLaVUZNjB6u6rGc'
final String hexadecimal = hexadecimalToBase58Converter.inverse()('GjWGF6jERR9ymrC1bHcGmsJYkLMDoaySr');
// hexadecimal == 'ac93c8d619c76f823f184110759b278f246cc7cc3cadcac3'
```

#### Decimal (emoji) ↔ Hexadecimal
```dart
final BaseConversion decimalEmojiToHexadecimalConverter = BaseConversion(
from: '0️⃣1️⃣2️⃣3️⃣4️⃣5️⃣6️⃣7️⃣8️⃣9️⃣',
to: '0123456789ABCDEF',
to: base16,
);
final String hexadecimal = decimalEmojiToHexadecimalConverter('5️⃣1️⃣9️⃣6️⃣6️⃣');
Expand All @@ -26,6 +39,23 @@ final String decimalEmoji = decimalEmojiToHexadecimalConverter.inverse()('DEADC0
// decimalEmoji == '3️⃣7️⃣3️⃣5️⃣9️⃣2️⃣9️⃣0️⃣5️⃣4️⃣'
```

### Exported alphabets
- `base2` - `01`
- `base3` - `012`
- `base4` - `0123`
- `base5` - `01234`
- `base6` - `012345`
- `base8` - `01234567`
- `base10` - `0123456789`
- `base12` - `0123456789AB`
- `base16` - `0123456789ABCDEF`
- `base32` - `ABCDEFGHIJKLMNOPQRSTUVWXYZ234567`
- `base32hex` - `0123456789ABCDEFGHIJKLMNOPQRSTUV`
- `base36` - `0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ`
- `base58` - `123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz`
- `base64` - `ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/`
- `base64url` - `ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_`

## Syntax

### *`BaseConversion({required String from, required String to})`*
Expand Down
8 changes: 4 additions & 4 deletions example/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ void decimalAndBinary() {
// Decimal alphabet - 0, 1, 2, 3, 4, 5, 6, 7, 8, 9
// Binary alphabet - 0, 1
final BaseConversion decimalToBinaryConverter = BaseConversion(
from: '0123456789',
to: '01',
from: base10,
to: base2,
);

final String binary = decimalToBinaryConverter('3888');
Expand All @@ -27,7 +27,7 @@ void decimalAndDecimalEmoji() {
// Decimal alphabet - 0, 1, 2, 3, 4, 5, 6, 7, 8, 9
// Decimal emoji alphabet - 0️⃣, 1️⃣, 2️⃣, 3️⃣, 4️⃣, 5️⃣, 6️⃣, 7️⃣, 8️⃣, 9️⃣
final BaseConversion decimalToDecimalEmojiConverter = BaseConversion(
from: '0123456789',
from: base10,
to: '0️⃣1️⃣2️⃣3️⃣4️⃣5️⃣6️⃣7️⃣8️⃣9️⃣',
);

Expand All @@ -46,7 +46,7 @@ void decimalEmojiAndHexadecimal() {
// Hexadecimal alphabet - 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, A, B, C, D, E, F
final BaseConversion decimalEmojiToHexadecimalConverter = BaseConversion(
from: '0️⃣1️⃣2️⃣3️⃣4️⃣5️⃣6️⃣7️⃣8️⃣9️⃣',
to: '0123456789ABCDEF',
to: base16,
);

final String hexadecimal =
Expand Down
2 changes: 1 addition & 1 deletion lib/b.dart
Original file line number Diff line number Diff line change
@@ -1 +1 @@
export 'src/base_conversion.dart' show BaseConversion, Alphabet;
export 'src/base_conversion.dart';
75 changes: 75 additions & 0 deletions lib/src/base_conversion.dart
Original file line number Diff line number Diff line change
Expand Up @@ -179,3 +179,78 @@ class Alphabet {
previousCharacter == _repetendEndCharacter));
}
}

/// Binary numeral system
const String binary = '01';

/// Same as [binary] numeral system
const String base2 = binary;

/// Ternary numeral system
const String ternary = '012';

/// Same as [ternary] numeral system
const String base3 = ternary;

/// Quaternary numeral system
const String quaternary = '0123';

/// Same as [quaternary] numeral system
const String base4 = quaternary;

/// Quinary numeral system
const String quinary = '01234';

/// Same as [quinary] numeral system
const String base5 = quinary;

/// Senary numeral system
const String senary = '012345';

/// Same as [senary] numeral system
const String base6 = senary;

/// Octal numeral system
const String octal = '01234567';

/// Same as [octal] numeral system
const String base8 = octal;

/// Decimal numeral system
const String decimal = '0123456789';

/// Same as [decimal] numeral system
const String base10 = decimal;

/// Duodecimal numeral system
const String duodecimal = '0123456789AB';

/// Same as [duodecimal] numeral system
const String base12 = duodecimal;

/// Hexadecimal numeral system
const String hexadecimal = '0123456789ABCDEF';

/// Same as [hexadecimal] numeral system
const String base16 = hexadecimal;

/// Base32 numeral system
const String base32 = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ234567';

/// Base32 (Extended Hex) numeral system
const String base32hex = '0123456789ABCDEFGHIJKLMNOPQRSTUV';

/// Base36 numeral system
const String base36 = '0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ';

/// Base58 numeral system
const String base58 =
'123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz';

/// Base64 numeral system
const String base64 =
'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/';

/// Base64 (URL and Filename safe) numeral system
const String base64url =
'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_';
2 changes: 1 addition & 1 deletion pubspec.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name: b
version: 0.1.0
version: 0.1.1
description: A Dart library for converting between different bases, e.g., decimal ↔ binary, octal ↔ hexadecimal
repository: https://github.com/dkin-om/b.git
issue_tracker: https://github.com/dkin-om/b/issues
Expand Down
4 changes: 2 additions & 2 deletions test/decimal_to_binary_testcase.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ import 'package:b/b.dart';

final Map<String, dynamic> decimalToBinary = <String, dynamic>{
'instance': BaseConversion(
from: '0123456789',
to: '01',
from: decimal,
to: binary,
),
'testCases': <Map<String, String>>[
<String, String>{'from': '0', 'to': '0'},
Expand Down
2 changes: 1 addition & 1 deletion test/decimal_to_decimal_emoji_testcase.dart
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import 'package:b/b.dart';
final Map<String, dynamic> decimalToDecimalEmoji = <String, dynamic>{
'instance': BaseConversion.alphabet(
from: Alphabet(
'0123456789',
decimal,
radixPoint: '.',
repetendSymbols: '()',
),
Expand Down

0 comments on commit 976aabe

Please sign in to comment.