ralflorent/namefully-dart

How about the name with 4 or more section?

Closed this issue · 2 comments

The name consisted of 4 parts like 'Nguyễn Văn Tuấn Anh' which is very common in Asian countries, by default settings it was stripped to V.T.Anh when I used the zip() function. What I want is N.V.T.Anh in the result, is there any settings for that?

Hi 👋🏼 @ducquynhnguyeninfo!

Thanks for the question. Yes, there's an actual way to handle names that contain more than 3 sections, or what I like to call "non-standard cases." One way to achieve the desired result is by using additional predefined class helpers such as Name, FirstName, or LastName and the named constructor of.

import 'package:namefully/namefully.dart';

void main() {
 var name = Namefully.of([
   FirstName('Nguyễn'),
   Name('Văn', Namon.middleName),
   Name('Tuấn', Namon.middleName),
   LastName('Anh'),
 ]);

 print(name.zip(by: Flat.firstMid)); // N. V. T. Anh
}

Also, keep in mind that the method zip() is a shorter version of flatten(). If you're looking to have more control, you might wanna have a look at that method.

Spoiler alerts:
I've been slowly working on a more elegant way to instantiate Namefully for non-standard cases in order to improve the development experience. Stay tuned as a new release is coming soon. To learn more about it, check out the release/next branch.

Happy name handling 😊!

Other alternatives with the 0.1.8 release are:

Option 1:

Namefully.fromJson({
  'firstName': 'Nguyễn',
  'middleName': 'Văn Tuấn',
  'lastName': 'Anh',
});

Option 2:

Namefully.only(
  firstName: 'Nguyễn',
  middleName: ['Văn', 'Tuấn'],
  lastName: 'Anh',
);

Option 3:

Namefully.of([
  FirstName('Nguyễn'),
  Name.middle('Văn'),
  Name.middle('Tuấn'),
  LastName('Anh'),
]);

Option 4:

Namefully.tryParse('Nguyễn Văn Tuấn Anh');