Closed RussBrown00 closed 8 years ago
This doesn't pass tests because of the type returned. Maybe it doesn't make sense to have this a prototyped feature? I'm no longer happy with this after trying to get the test scripts to pass.
Sorry I have no time at the moment. In two weeks I'll be happy to help, but to whole prototype thing looks a little bit hacky to me. ^^ Btw: Aren't there already any standards for formatting strings. Something like the conventions for printf. We should definitely try to be consistent with already existing and popular formats…
E.g. this could be good reference for formatting dates: http://momentjs.com/docs/#/displaying/format/ (And in the best case the fakesome formatting module should be able to format any of the fundamental generators of fakesome in the end…)
It was feeling hacky to me as well and I've decided to pull the method out on my own side and just wrap the results in a format. Trying to return a type that had a format method in it turned a little dirty. I looked for an existing formatting library, but did not find anything like moment for numbers that I was happy with. I'd say keep my code around for reference if you want but just kill the pull request.
I'm going to make my local format method a little beefier so that I can do things like format strings into UUIDs and SKUS for a current project I'm working on...
I took a stab at enabling an inline format feature. I think it's fairly robust yet lightweight, but let me know what you think. I tested it on a number of formats. It works with any string as long as you include the numbers mask. At a minimum you will need to enter a "0" or if you want to mast decimal places as well the minimum required is "0.0".
Some Examples: "0.00" will convert 55.123456 to "55.12" "000.000" will convert 55.123456 to "055.123" "$0.00" will convert 55.123456 to "$55.12"
I'm returning a custom type based on Number with a new format fnc. I did not want to mess with the base Number class. The fakesome.integer(10,100) returns a NumberFS object that prints out a regular number when used. However you can now call fakesome.integer(10,100).format("$0.00") to mask/format the value that is returned.
I ran the two jake commands for fakesome.js and fakesome.min.js but the changes were greater than expected. You might want to just merge my change from src and run the pre-processor tasks the right way.