tink_stringly


https://github.com/haxetink/tink_stringly/

To install, run:

haxelib install tink_stringly 0.2.0 

See using Haxelib in Haxelib documentation for more information.

README.md

Tinkerbell ~~Stringly Mess~~ Stringliness

A harsh and inescapable truth of contemporary programming reality is that there's a lot of stringliness going on everywhere. Numeric values just get passed around as their string representation and you somehow have to deal with it. Be it command line parameters, query string parameters or XML / HTML attributes.

Some dynamically typed languages (most notably JavaScript) solve this by trying to make sense of numerical operations on strings at runtime. This becomes particularly delightful if the operation is + and one of the operands suddenly happens to be a string. Let's learn from that design flaw!

This library proposes tackling the issue by use of the following type:

abstract Stringly(String) from String to String {
  
  @:to public function toBool():Bool;
  @:to public function parseFloat():Outcome<Float, Error>;  
  @:to function toFloat():Float;
  @:to public function parseInt():Outcome<Int, Error>;
  @:to function toInt():Int;
  @:to public function parseDate():Outcome<Date, Error>;
  @:to function toDate():Date;
      
  @:from static function ofBool(b:Bool):Stringly;
  @:from static function ofInt(i:Int):Stringly;
  @:from static function ofFloat(f:Float):Stringly;
  @:from static function ofDate(d:Date):Stringly;
}  

It is worth noting that parsing numbers is stricter than Std.parseInt or Std.parseFloat in that it requires the whole string to be part of the number. The implicit toFloat and toInt throw exceptions. Since the exception is raised when the value is converted instead of when it is operated on, it is slightly easier to pinpoint the cause of errors.

Contributors
back2dos
Version
0.2.0
Published
1 year ago
License
MIT

All libraries are free

Every month, more than thousand developers use haxelib to find, share, and reuse code — and assemble it in powerful new ways. Enjoy Haxe; It is great!

Explore Haxe

Haxe Manual

Haxe Code Cookbook

Haxe API documentation

You can try Haxe in the browser! try.haxe.org

Join us on Github!

Haxe is being developed on GitHub. Feel free to contribute or report issues to our projects.

Haxe on Github