feat: add string extension, log level

This commit is contained in:
Hugo Pointcheval 2023-01-21 16:00:39 +01:00
parent fcf31a4a54
commit 908611d32d
Signed by: hugo
GPG Key ID: 3AAC487E131E00BC
6 changed files with 51 additions and 8 deletions

View File

@ -50,7 +50,9 @@ class FileSystemUtils {
} }
} }
} }
Logger.info('Variable ${variable?.name} added in ${file.path}'); Logger.debug(
'Variable `${variable?.name}` replaced in ${file.path}',
);
} }
} }
@ -90,6 +92,9 @@ class FileSystemUtils {
await File(newPath).create(recursive: true); await File(newPath).create(recursive: true);
await file.rename(newPath); await file.rename(newPath);
Logger.debug(
'${file.path} renamed with variable `${variable.name}`',
);
} }
} }
} }

View File

@ -23,6 +23,10 @@ class Logger {
stdout.writeln('${level.prefix} ${message.toString()}'); stdout.writeln('${level.prefix} ${message.toString()}');
} }
static void debug(Object? message) {
log(message, level: LogLevel.debug);
}
static void info(Object? message) { static void info(Object? message) {
log(message); log(message);
} }

View File

@ -80,9 +80,6 @@ description: $description
version: $version version: $version
environment:
mason: ">=0.1.0-dev.26 <0.1.0"
'''; ''';
if (variables?.isNotEmpty ?? false) { if (variables?.isNotEmpty ?? false) {

View File

@ -15,6 +15,7 @@
// along with this program. If not, see <https://www.gnu.org/licenses/>. // along with this program. If not, see <https://www.gnu.org/licenses/>.
enum LogLevel { enum LogLevel {
debug('💡'),
info('🍺'), info('🍺'),
success(''), success(''),
error(''); error('');

View File

@ -25,7 +25,9 @@ enum VariableStringSyntax {
paramCase('param_case', 'paramCase'), paramCase('param_case', 'paramCase'),
sentenceCase('sentence_case', 'sentenceCase'), sentenceCase('sentence_case', 'sentenceCase'),
titleCase('title_case', 'titleCase'), titleCase('title_case', 'titleCase'),
upperCase('upper_case', 'upperCase'); upperCase('upper_case', 'upperCase'),
pathCase('path_case', 'pathCase'),
mustacheCase('mustache_case', 'mustacheCase');
final String mapKey; final String mapKey;
final String id; final String id;

View File

@ -29,6 +29,8 @@ extension StringExtension on String {
'title_case': title(), 'title_case': title(),
'upper_case': upper(), 'upper_case': upper(),
'snake_case': snake(), 'snake_case': snake(),
'mustache_case': mustache(),
'path_case': path(),
}; };
/// ```dart /// ```dart
@ -214,6 +216,30 @@ extension StringExtension on String {
} }
} }
/// ```dart
/// print('Hello World'.path()) // hello/world
/// print('helloWorld'.path()) // hello/world
/// print('long space'.path()) // long/space
/// ```
String path() {
switch (length) {
case 0:
return this;
case 1:
return toLowerCase();
default:
return splitMapJoin(
RegExp('[A-Z]'),
onMatch: (m) => ' ${m[0]}',
onNonMatch: (n) => n,
).trim().splitMapJoin(
_defaultMatcher,
onMatch: (m) => '/',
onNonMatch: (n) => n.toLowerCase(),
);
}
}
/// ```dart /// ```dart
/// print('Hello World'.upper()) // HELLO WORLD /// print('Hello World'.upper()) // HELLO WORLD
/// print('helloWorld'.upper()) // HELLO WORLD /// print('helloWorld'.upper()) // HELLO WORLD
@ -280,4 +306,12 @@ extension StringExtension on String {
onNonMatch: (n) => n, onNonMatch: (n) => n,
); );
} }
/// ```dart
/// print('Hello World'.mustache()) // {{ Hello World }}
/// print('helloWorld'.mustache()) // {{ Hello World }}
/// ```
String mustache() {
return '{{ ${title()} }}';
}
} }