Skip to content

Commit

Permalink
Convert DataUnit, Prefix to enums
Browse files Browse the repository at this point in the history
  • Loading branch information
JonasWanke committed Feb 7, 2024
1 parent 118220e commit f34e134
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 24 deletions.
18 changes: 6 additions & 12 deletions lib/src/prefix.dart
Original file line number Diff line number Diff line change
@@ -1,21 +1,15 @@
import 'package:meta/meta.dart';

@immutable
class Prefix {
const Prefix._({
required this.divider,
required this.prefixes,
});

static const decimal = Prefix._(
enum Prefix {
decimal(
divider: 1000,
prefixes: ['', 'k', 'M', 'G', 'T', 'P', 'E', 'Z', 'Y', 'R', 'Q'],
);
static const binary = Prefix._(
),
binary(
divider: 1024,
prefixes: ['', 'Ki', 'Mi', 'Gi', 'Ti', 'Pi', 'Ei', 'Zi', 'Yi'],
);

const Prefix({required this.divider, required this.prefixes});

/// Narrow No-Break Space, used for combining numbers and unit symbols in
/// general.
///
Expand Down
13 changes: 4 additions & 9 deletions lib/src/unit.dart
Original file line number Diff line number Diff line change
@@ -1,15 +1,10 @@
import 'package:meta/meta.dart';

import 'prefix.dart';

@immutable
class DataUnit {
const DataUnit._({
required this.shortString,
});
enum DataUnit {
bit('b'),
byte('B');

static const bit = DataUnit._(shortString: 'b');
static const byte = DataUnit._(shortString: 'B');
const DataUnit(this.shortString);

final String shortString;

Expand Down
3 changes: 0 additions & 3 deletions pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,6 @@ version: 0.2.0
homepage: https://github.com/JonasWanke/data_size

environment:

dependencies:
meta: ^1.3.0
sdk: '>=3.0.0 <4.0.0'

dev_dependencies:
Expand Down

0 comments on commit f34e134

Please sign in to comment.