Skip to content

Commit

Permalink
v3.1.1
Browse files Browse the repository at this point in the history
- `parseBool`:
 - Improve possible valid values.
  • Loading branch information
gmpassos committed Apr 26, 2022
1 parent beea451 commit d57256a
Show file tree
Hide file tree
Showing 4 changed files with 47 additions and 2 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
## 3.1.1

- `parseBool`:
- Improve possible valid values.

## 3.1.0

- Migrate to `lints`:
Expand Down
7 changes: 6 additions & 1 deletion lib/src/math.dart
Original file line number Diff line number Diff line change
Expand Up @@ -388,7 +388,7 @@ num? parseNum(Object? v, [num? def]) {
///
/// if [v] is [num]: true when [v > 0]
///
/// if [v] is [String]: true when [v == "true"|"yes"|"ok"|"1"|"y"|"s"|"t"|"+"
/// if [v] is [String]: true when [v == "true"|"yes"|"ok"|"on"|"enabled"|"1"|"y"|"s"|"t"|"+"
///
/// [def] The default value if [v] is invalid.
bool? parseBool(Object? v, [bool? def]) {
Expand All @@ -412,6 +412,11 @@ bool? parseBool(Object? v, [bool? def]) {
return s == 'true' ||
s == 'yes' ||
s == 'ok' ||
s == 'on' ||
s == 'enabled' ||
s == 'active' ||
s == 'activated' ||
s == 'selected' ||
s == '1' ||
s == 'y' ||
s == 's' ||
Expand Down
2 changes: 1 addition & 1 deletion pubspec.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name: swiss_knife
description: Dart Useful Tools - collections, math, date, uri, json, events, resources, regexp, etc...
version: 3.1.0
version: 3.1.1
homepage: https://github.com/gmpassos/swiss_knife

environment:
Expand Down
35 changes: 35 additions & 0 deletions test/swiss_knife_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -347,6 +347,41 @@ void main() {
expect(Math.mean([2, 4]), equals(3));
});

test('parseBool', () {
expect(parseBool(true), isTrue);
expect(parseBool(false), isFalse);

expect(parseBool('true'), isTrue);
expect(parseBool('false'), isFalse);

expect(parseBool(1), isTrue);
expect(parseBool(0), isFalse);

expect(parseBool('1'), isTrue);
expect(parseBool('0'), isFalse);

expect(parseBool('yes'), isTrue);
expect(parseBool('no'), isFalse);

expect(parseBool('ok'), isTrue);
expect(parseBool('no'), isFalse);

expect(parseBool('on'), isTrue);
expect(parseBool('off'), isFalse);

expect(parseBool('On'), isTrue);
expect(parseBool('Off'), isFalse);

expect(parseBool('enabled'), isTrue);
expect(parseBool('disabled'), isFalse);

expect(parseBool('active'), isTrue);
expect(parseBool('disabled'), isFalse);

expect(parseBool('activated'), isTrue);
expect(parseBool('deactivated'), isFalse);
});

test('parseNum', () {
expect(parseNum(0), equals(0));
expect(parseNum(1), equals(1));
Expand Down

0 comments on commit d57256a

Please sign in to comment.