1
0
mirror of https://github.com/flutter/samples.git synced 2026-03-23 12:51:57 +00:00
Files
samples/web/samples_index/lib/src/util.dart
2020-05-13 09:18:26 +10:00

34 lines
826 B
Dart

// Copyright 2020 The Flutter team. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file
import 'dart:convert';
String indent(String content, int spaces) =>
LineSplitter.split(content).join('\n' + ' ' * spaces);
String kebabCase(String input) => _fixCase(input, '-');
String snakeCase(String input) => _fixCase(input, '_');
final _upperCase = RegExp('[A-Z]');
String pascalCase(String input) {
if (input.isEmpty) {
return '';
}
return input[0].toUpperCase() + input.substring(1);
}
String _fixCase(String input, String separator) =>
input.replaceAllMapped(_upperCase, (match) {
var lower = match.group(0).toLowerCase();
if (match.start > 0) {
lower = '$separator$lower';
}
return lower;
});