Skip to content

Commit

Permalink
Merge pull request #90 from GIHAA/feat-startsWith
Browse files Browse the repository at this point in the history
Feat: added starts_with under the string manipulation
  • Loading branch information
Akalanka47000 authored Jun 30, 2023
2 parents d0a8feb + ac35b25 commit 2900e5f
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 1 deletion.
3 changes: 2 additions & 1 deletion packages/flodash/lib/modules/string/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,6 @@ export 'unescape.dart';
export 'uppercase.dart';
export 'trim_end.dart';
export 'trim_start.dart';
export 'starts_with.dart';
export 'to_lower.dart';
export 'to_upper.dart';
export 'to_upper.dart';
17 changes: 17 additions & 0 deletions packages/flodash/lib/modules/string/starts_with.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
///Checks if string starts with the given target string.
///
/// Arguments
///
/// - string (String): The string to be checked.
/// - target (String): The target string that is expected to be at the beginning of the given string.
/// - position (int): Optional parameter specifying the starting position in the given string to begin the comparison. Defaults to 0
///
/// Returns
///
/// - (Boolean): Returns true if the string starts with the target string at the specified position; otherwise, returns false

@Deprecated('The function startsWith() is deprecated. Use the built-in startsWith() method instead.')
bool startsWith(String string, String target, [int position = 0]) {
return string.startsWith(target, position);
}
24 changes: 24 additions & 0 deletions packages/flodash/test/modules/string/starts_with_test.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import 'package:flutter_test/flutter_test.dart';
import 'package:flodash/flodash.dart' as flodash;

void main() {
test('should return true if the string starts with the target', () {
String string = 'abc';
String target = 'a';
bool result = flodash.startsWith(string, target);
expect(result, true);
});
test('should return false if the string does not start with the target', () {
String string = 'abc';
String target = 'b';
bool result = flodash.startsWith(string, target);
expect(result, false);
});
test('should return true if the string starts with the target at the specified position', () {
String string = 'abc';
String target = 'b';
int position = 1;
bool result = flodash.startsWith(string, target, position);
expect(result, true);
});
}

0 comments on commit 2900e5f

Please sign in to comment.