platform/packages/relations/lib/src/plural.dart

24 lines
568 B
Dart
Raw Normal View History

2017-01-30 02:39:11 +00:00
String singular(String path) {
var str = path.trim().split('/').where((str) => str.isNotEmpty).last;
2021-06-20 12:37:20 +00:00
if (str.endsWith('ies')) {
2017-01-30 02:39:11 +00:00
return str.substring(0, str.length - 3) + 'y';
2021-06-20 12:37:20 +00:00
} else if (str.endsWith('s')) {
2017-01-30 02:39:11 +00:00
return str.substring(0, str.length - 1);
2021-06-20 12:37:20 +00:00
} else {
2017-01-30 02:39:11 +00:00
return str;
2021-06-20 12:37:20 +00:00
}
2017-01-30 02:39:11 +00:00
}
String plural(String path) {
var str = path.trim().split('/').where((str) => str.isNotEmpty).last;
2021-06-20 12:37:20 +00:00
if (str.endsWith('y')) {
2017-01-30 02:39:11 +00:00
return str.substring(0, str.length - 1) + 'ies';
2021-06-20 12:37:20 +00:00
} else if (str.endsWith('s')) {
2017-01-30 02:39:11 +00:00
return str;
2021-06-20 12:37:20 +00:00
} else {
2017-01-30 02:39:11 +00:00
return str + 's';
2021-06-20 12:37:20 +00:00
}
2017-01-30 02:39:11 +00:00
}