lexical_sort 1.0.0 copy "lexical_sort: ^1.0.0" to clipboard
lexical_sort: ^1.0.0 copied to clipboard

Lexicographic and natural sort comparators for Dart, ported from the lexical_sort Rust crate.

example/main.dart

// ignore_for_file: avoid_print

import 'package:lexical_sort/lexical_sort.dart';

void main() {
  print(naturalLexicalCmp('50', '100') < 0); // true  — 50 < 100
  print(naturalLexicalCmp('ß', 'world') < 0); // true  — ß → ss, before world
  print(naturalLexicalCmp('é', 'hello') < 0); // true  — é → e, before hello
  print(naturalLexicalCmp('B!', 'é') < 0); // true  — non-alnum before alnum
  print(naturalLexicalCmp('.', '50') < 0); // true  — non-alnum before alnum

  print(lexicalCmp('aaa', 'AAb') < 0); // true  — case-insensitive
  print(lexicalCmp('äáa', 'aab') < 0); // true  — ä → a, sorts before aab

  print(naturalCmp('T-1', 'T-5') < 0); // true
  print(onlyAlnumCmp('_ad', '_æ') < 0); // true  — non-alnum skipped
  print(naturalLexicalOnlyAlnumCmp('T-27a', 'T27b') < 0); // true

  // naturalLexicalCmp vs Dart's default String.compareTo:
  //
  // input: ['ß', 'é', '100', 'hello', 'world', '50', '.', 'B!']
  //
  // naturalLexicalCmp:  [., 50, 100, B!, é, hello, ß, world]
  // String.compareTo:   [!, 100, 50, B, hello, world, ß, é, .]
  //                      ^                               ^^^^^
  //                      numbers out of order            accents and punct at wrong end
}
0
likes
0
points
5
downloads

Publisher

verified publisherganeshrvel.com

Weekly Downloads

Lexicographic and natural sort comparators for Dart, ported from the lexical_sort Rust crate.

Repository (GitHub)
View/report issues

License

unknown (license)

Dependencies

any_ascii, option_result

More

Packages that depend on lexical_sort