named_mode 1.0.2+1

  • Readme
  • Changelog
  • Example
  • Installing
  • 71

Download #

dependencies:
  named_mode: latest

Import #

import 'package:named_mode/named_mode.dart';

Usage #

This library can help you to solve name-transform problem easily

Now support 5 named mode, using string "an apple" as example

  • an_apple
  • AN_APPLE
  • An_Apple
  • anApple
  • AnApple

Resolve named-mode of a string #

use

NamedMode namedMode = resolveNamedMode(your_string);

or

NamedMode namedMode = NamedMode.parseOn(your_string);

Split a string by named-mode #

use specific named-mode to split string

List<String> segments = NamedMode.an_apple.split(your_string);

or split string by resolving named-mode automatically

List<String> segments = autoSplit(your_string);

you can also specific top-level named-mode to split string recursively

example:

string "an_bigApple_TooBig_ApplePie" can be split recursively to [an, big, Apple, Too, Big, Apple, Pie] by this code

autoSplit("an_bigApple_TooBig_ApplePie", parentNamedMode: NamedMode.AN_APPLE);

if you disable recursive then will get [an, bigApple, TooBig, ApplePie]

Combine the split strings #

use

combineWithNamedMode(your_segments, NamedMode.an_apple);

A simple usage example: #

import 'package:named_mode/named_mode.dart';

main() {
  NamedMode namedMode;

  /// you can get named mode of string
  String s1 = 'HelloWorld';
  namedMode = resolveNamedMode(s1);
  print(namedMode.name); // NamedMode.AnApple
  namedMode = NamedMode.parseOn(s1);
  print(namedMode.name); // NamedMode.AnApple

  String s2 = 'hello_world';
  namedMode = resolveNamedMode(s2);
  print(namedMode.name); // NamedMode.an_apple

  /// you will get unknown when parse incorrect format string
  String s3 = 'apple_Pie';
  namedMode = resolveNamedMode(s3);
  print(namedMode.name); // NameMode.unknown

  /// you can use simple function to translate names.
  print(renameTo__AN_APPLE(s1)); // HELLO_WORLD
  print(renameTo__An_Apple(s1)); // Hello_World
  print(renameTo__an_apple(s1)); // hello_world
  print(renameTo__AnApple(s1)); // HelloWorld
  print(renameTo__anApple(s1)); // helloWorld
  /// or select mode yourself
  print(renameToOtherMode(s1, NamedMode.anApple)); // helloWorld

  /// replace first char to upper/lower case
  print(replaceFirstChar('apple', toUpper: true)); // Apple
  print(replaceFirstChar('Banana', toUpper: false)); // banana

  /// split string by specific named mode
  var result = NamedMode.an_apple.split('this_is_a_book');
  print(result); // [this, is, a, book]
  result = NamedMode.anApple.split('thisIsABook');
  print(result); // [this, is, a, book]
  result = NamedMode.an_apple.split('thisIsABook');
  print(result); // [thisisabook]

  /// combine segments to specific named mode string
  var segments = ['this', 'is', 'a', 'book'];
  print(combineWithNamedMode(segments, NamedMode.an_apple)); // this_is_a_book
  print(combineWithNamedMode(segments, NamedMode.AN_APPLE)); // THIS_IS_A_BOOK
  print(combineWithNamedMode(segments, NamedMode.An_Apple)); // This_Is_A_Book
  print(combineWithNamedMode(segments, NamedMode.anApple)); // thisIsABook
  print(combineWithNamedMode(segments, NamedMode.AnApple)); // ThisIsABook
}

Features and bugs #

-

1.0.0 #

  • Initial version, created by Stagehand

1.0.0+1 #

  • fixed some bugs

1.0.0+2 #

  • fixed some bugs

1.0.1 #

  • new method List<String> autoSplit(String src, {NamedMode parentNamedMode = NamedMode.unknown, bool recursive = true})

  • optimize regex pattern

1.0.2 #

  • update readme

  • optimize code

1.0.2+1 #

  • update readme.md

example/named_mode_example.dart

import 'package:named_mode/named_mode.dart';

main() {
  NamedMode namedMode;

  /// you can get named mode of string
  String s1 = 'HelloWorld';
  namedMode = resolveNamedMode(s1);
  print(namedMode.name); // NamedMode.AnApple
  namedMode = NamedMode.parseOn(s1);
  print(namedMode.name); // NamedMode.AnApple

  String s2 = 'hello_world';
  namedMode = resolveNamedMode(s2);
  print(namedMode.name); // NamedMode.an_apple

  /// you will get unknown when parse incorrect format string
  String s3 = 'apple_Pie';
  namedMode = resolveNamedMode(s3);
  print(namedMode.name); // NameMode.unknown

  /// you can use simple function to translate names.
  print(renameTo__AN_APPLE(s1)); // HELLO_WORLD
  print(renameTo__An_Apple(s1)); // Hello_World
  print(renameTo__an_apple(s1)); // hello_world
  print(renameTo__AnApple(s1)); // HelloWorld
  print(renameTo__anApple(s1)); // helloWorld
  /// or select mode yourself
  print(renameToOtherMode(s1, NamedMode.anApple)); // helloWorld

  /// replace first char to upper/lower case
  print(replaceFirstChar('apple', toUpper: true)); // Apple
  print(replaceFirstChar('Banana', toUpper: false)); // banana

  /// split string by specific named mode
  var result = NamedMode.an_apple.split('this_is_a_book');
  print(result); // [this, is, a, book]
  result = NamedMode.anApple.split('thisIsABook');
  print(result); // [this, is, a, book]
  result = NamedMode.an_apple.split('thisIsABook');
  print(result); // [thisisabook]

  /// combine segments to specific named mode string
  var segments = ['this', 'is', 'a', 'book'];
  print(combineWithNamedMode(segments, NamedMode.an_apple)); // this_is_a_book
  print(combineWithNamedMode(segments, NamedMode.AN_APPLE)); // THIS_IS_A_BOOK
  print(combineWithNamedMode(segments, NamedMode.An_Apple)); // This_Is_A_Book
  print(combineWithNamedMode(segments, NamedMode.anApple)); // thisIsABook
  print(combineWithNamedMode(segments, NamedMode.AnApple)); // ThisIsABook

  var s = "an_bigApple_TooBig_ApplePie";
  print(autoSplit(s, parentNamedMode: NamedMode.AN_APPLE)); // [an, big, Apple, Too, Big, Apple, Pie]
  print(autoSplit(s, parentNamedMode: NamedMode.AN_APPLE, recursive: false)); // [an, bigApple, TooBig, ApplePie]
}

Use this package as a library

1. Depend on it

Add this to your package's pubspec.yaml file:


dependencies:
  named_mode: ^1.0.2+1

2. Install it

You can install packages from the command line:

with pub:


$ pub get

with Flutter:


$ flutter pub get

Alternatively, your editor might support pub get or flutter pub get. Check the docs for your editor to learn more.

3. Import it

Now in your Dart code, you can use:


import 'package:named_mode/named_mode.dart';
  
Popularity:
Describes how popular the package is relative to other packages. [more]
42
Health:
Code health derived from static analysis. [more]
99
Maintenance:
Reflects how tidy and up-to-date the package is. [more]
100
Overall:
Weighted score of the above. [more]
71
Learn more about scoring.

We analyzed this package on Oct 16, 2019, and provided a score, details, and suggestions below. Analysis was completed with status completed using:

  • Dart: 2.5.1
  • pana: 0.12.21

Platforms

Detected platforms: Flutter, web, other

No platform restriction found in primary library package:named_mode/named_mode.dart.

Health issues and suggestions

Document public APIs. (-1 points)

25 out of 25 API elements have no dartdoc comment.Providing good documentation for libraries, classes, functions, and other API elements improves code readability and helps developers find and use your API.

Format lib/named_mode.dart.

Run dartfmt to format lib/named_mode.dart.

Format lib/src/named_mode_base.dart.

Run dartfmt to format lib/src/named_mode_base.dart.

Dependencies

Package Constraint Resolved Available
Direct dependencies
Dart SDK >=2.2.0 <3.0.0
Dev dependencies
pedantic ^1.0.0
test ^1.0.0