Skip to content

Commit

Permalink
Update README.md
Browse files Browse the repository at this point in the history
  • Loading branch information
ghasemdev committed Nov 23, 2021
1 parent d6020b3 commit f873189
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 3 deletions.
43 changes: 42 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,16 @@ final word = 'abcd'.decapitalize(); // abcd
final anotherWord = 'Abcd'.decapitalize(); // abcd
```

### .title

Return a version of the string where each word is titlecased.
More specifically, words start with uppercased characters and all remaining cased characters have lower case.

```dart
const text = 'welcome to my 2nd world';
print(text.title()); // Welcome To My 2nd World
```

### .isAscii

Returns `true` if the string is ASCII encoded.
Expand Down Expand Up @@ -379,7 +389,38 @@ print('as'.matches(RegExp('^.s\$'))) // true
print('mst'.matches(RegExp('^.s\$'))) // false
```

## Time utils
### .count()

Return the number of non-overlapping occurrences of substring sub in string. Optional arguments start and end are interpreted as in slice notation

```dart
const text = 'I love apples, apple are my favorite fruit';
print(text.count('apple', 0, 20)) // 2
```

### .partition()

Partition the string into three parts using the given separator.

```dart
const text = 'I could eat bananas all day';
print(text.partition('bananas') // ['I could eat ', 'bananas', ' all day']
print(text.partition('apple') // ['I could eat bananas all day', '', '']
```

### .center(), .leftJustify() and .rightJustify()

Return a centered, left-justified and right-justified string of length width.
Padding is done using the specified fill character (default is a space).

```dart
const text = 'banana';
print(text.center(2, '*')); // **banana**
print(text.leftJust(2, '*')); // **banana
print(text.rightJust(2, '*')); // banana**
```

### Time utils

Dartx exports [@jogboms](https://github.com/jogboms) great [⏰ time.dart](https://github.com/jogboms/time.dart) package so you can do the following:

Expand Down
4 changes: 2 additions & 2 deletions test/string_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -326,15 +326,15 @@ void main() {
expect(text.center(2, '*'), '**banana**');
});

test('.leftJust()', () {
test('.leftJustify()', () {
const text = 'banana';
expect(text.leftJustify(1), ' banana');
expect(text.leftJustify(5), ' banana');
expect(text.leftJustify(10), ' banana');
expect(text.leftJustify(2, '*'), '**banana');
});

test('.rightJust()', () {
test('.rightJustify()', () {
const text = 'banana';
expect(text.rightJustify(1), 'banana ');
expect(text.rightJustify(5), 'banana ');
Expand Down

0 comments on commit f873189

Please sign in to comment.