forked from lxm_flutter/icomoon-selection-gen
Error: Not found: 'package:recase/recase.dart',引入本地recase
This commit is contained in:
@@ -3,7 +3,7 @@ import 'dart:convert';
|
|||||||
import 'package:build/build.dart';
|
import 'package:build/build.dart';
|
||||||
import 'package:code_builder/code_builder.dart';
|
import 'package:code_builder/code_builder.dart';
|
||||||
import 'package:dart_style/dart_style.dart';
|
import 'package:dart_style/dart_style.dart';
|
||||||
import 'package:recase/recase.dart';
|
import 'recase4.0.0/recase.dart';
|
||||||
|
|
||||||
import 'models.dart';
|
import 'models.dart';
|
||||||
|
|
||||||
@@ -31,12 +31,12 @@ class GeneratorOptions {
|
|||||||
|
|
||||||
return GeneratorOptions(
|
return GeneratorOptions(
|
||||||
fontName: config['font_name'] as String,
|
fontName: config['font_name'] as String,
|
||||||
selectionJsonPath: config['selection_json_path'] as String,
|
selectionJsonPath: config['selection_json_path'],
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
final String fontName;
|
final String fontName;
|
||||||
final String selectionJsonPath;
|
final String? selectionJsonPath;
|
||||||
}
|
}
|
||||||
|
|
||||||
class IcomoonBuilder implements Builder {
|
class IcomoonBuilder implements Builder {
|
||||||
|
|||||||
134
lib/recase4.0.0/recase.dart
Normal file
134
lib/recase4.0.0/recase.dart
Normal file
@@ -0,0 +1,134 @@
|
|||||||
|
/// An instance of text to be re-cased.
|
||||||
|
class ReCase {
|
||||||
|
final RegExp _upperAlphaRegex = RegExp(r'[A-Z]');
|
||||||
|
|
||||||
|
final symbolSet = {' ', '.', '/', '_', '\\', '-'};
|
||||||
|
|
||||||
|
late String originalText;
|
||||||
|
late List<String> _words;
|
||||||
|
|
||||||
|
ReCase(String text) {
|
||||||
|
this.originalText = text;
|
||||||
|
this._words = _groupIntoWords(text);
|
||||||
|
}
|
||||||
|
|
||||||
|
List<String> _groupIntoWords(String text) {
|
||||||
|
StringBuffer sb = StringBuffer();
|
||||||
|
List<String> words = [];
|
||||||
|
bool isAllCaps = text.toUpperCase() == text;
|
||||||
|
|
||||||
|
for (int i = 0; i < text.length; i++) {
|
||||||
|
String char = text[i];
|
||||||
|
String? nextChar = i + 1 == text.length ? null : text[i + 1];
|
||||||
|
|
||||||
|
if (symbolSet.contains(char)) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
sb.write(char);
|
||||||
|
|
||||||
|
bool isEndOfWord = nextChar == null ||
|
||||||
|
(_upperAlphaRegex.hasMatch(nextChar) && !isAllCaps) ||
|
||||||
|
symbolSet.contains(nextChar);
|
||||||
|
|
||||||
|
if (isEndOfWord) {
|
||||||
|
words.add(sb.toString());
|
||||||
|
sb.clear();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return words;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// camelCase
|
||||||
|
String get camelCase => _getCamelCase();
|
||||||
|
|
||||||
|
/// CONSTANT_CASE
|
||||||
|
String get constantCase => _getConstantCase();
|
||||||
|
|
||||||
|
/// Sentence case
|
||||||
|
String get sentenceCase => _getSentenceCase();
|
||||||
|
|
||||||
|
/// snake_case
|
||||||
|
String get snakeCase => _getSnakeCase();
|
||||||
|
|
||||||
|
/// dot.case
|
||||||
|
String get dotCase => _getSnakeCase(separator: '.');
|
||||||
|
|
||||||
|
/// param-case
|
||||||
|
String get paramCase => _getSnakeCase(separator: '-');
|
||||||
|
|
||||||
|
/// path/case
|
||||||
|
String get pathCase => _getSnakeCase(separator: '/');
|
||||||
|
|
||||||
|
/// PascalCase
|
||||||
|
String get pascalCase => _getPascalCase();
|
||||||
|
|
||||||
|
/// Header-Case
|
||||||
|
String get headerCase => _getPascalCase(separator: '-');
|
||||||
|
|
||||||
|
/// Title Case
|
||||||
|
String get titleCase => _getPascalCase(separator: ' ');
|
||||||
|
|
||||||
|
String _getCamelCase({String separator: ''}) {
|
||||||
|
List<String> words = this._words.map(_upperCaseFirstLetter).toList();
|
||||||
|
if (_words.isNotEmpty) {
|
||||||
|
words[0] = words[0].toLowerCase();
|
||||||
|
}
|
||||||
|
|
||||||
|
return words.join(separator);
|
||||||
|
}
|
||||||
|
|
||||||
|
String _getConstantCase({String separator: '_'}) {
|
||||||
|
List<String> words = this._words.map((word) => word.toUpperCase()).toList();
|
||||||
|
|
||||||
|
return words.join(separator);
|
||||||
|
}
|
||||||
|
|
||||||
|
String _getPascalCase({String separator: ''}) {
|
||||||
|
List<String> words = this._words.map(_upperCaseFirstLetter).toList();
|
||||||
|
|
||||||
|
return words.join(separator);
|
||||||
|
}
|
||||||
|
|
||||||
|
String _getSentenceCase({String separator: ' '}) {
|
||||||
|
List<String> words = this._words.map((word) => word.toLowerCase()).toList();
|
||||||
|
if (_words.isNotEmpty) {
|
||||||
|
words[0] = _upperCaseFirstLetter(words[0]);
|
||||||
|
}
|
||||||
|
|
||||||
|
return words.join(separator);
|
||||||
|
}
|
||||||
|
|
||||||
|
String _getSnakeCase({String separator: '_'}) {
|
||||||
|
List<String> words = this._words.map((word) => word.toLowerCase()).toList();
|
||||||
|
|
||||||
|
return words.join(separator);
|
||||||
|
}
|
||||||
|
|
||||||
|
String _upperCaseFirstLetter(String word) {
|
||||||
|
return '${word.substring(0, 1).toUpperCase()}${word.substring(1).toLowerCase()}';
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
extension StringReCase on String {
|
||||||
|
String get camelCase => ReCase(this).camelCase;
|
||||||
|
|
||||||
|
String get constantCase => ReCase(this).constantCase;
|
||||||
|
|
||||||
|
String get sentenceCase => ReCase(this).sentenceCase;
|
||||||
|
|
||||||
|
String get snakeCase => ReCase(this).snakeCase;
|
||||||
|
|
||||||
|
String get dotCase => ReCase(this).dotCase;
|
||||||
|
|
||||||
|
String get paramCase => ReCase(this).paramCase;
|
||||||
|
|
||||||
|
String get pathCase => ReCase(this).pathCase;
|
||||||
|
|
||||||
|
String get pascalCase => ReCase(this).pascalCase;
|
||||||
|
|
||||||
|
String get headerCase => ReCase(this).headerCase;
|
||||||
|
|
||||||
|
String get titleCase => ReCase(this).titleCase;
|
||||||
|
}
|
||||||
@@ -12,7 +12,7 @@ dependencies:
|
|||||||
build_config: ^1.0.0
|
build_config: ^1.0.0
|
||||||
|
|
||||||
dev_dependencies:
|
dev_dependencies:
|
||||||
recase: ^4.0.0
|
# recase: ^4.0.0
|
||||||
dart_style: ^2.2.3
|
dart_style: ^2.2.3
|
||||||
code_builder: ^4.1.0
|
code_builder: ^4.1.0
|
||||||
build_runner: ^2.1.11
|
build_runner: ^2.1.11
|
||||||
|
|||||||
Reference in New Issue
Block a user