jonplussed / purescript-number-format Goto Github PK
View Code? Open in Web Editor NEWNumber-to-String formatting functions for PureScript
Number-to-String formatting functions for PureScript
Re #1
What are your thoughts for providing some safe versions that aren't wrapped in a Maybe
or in an Eff
? Only for the more common choices. Stuff like toBinString :: Number -> String
or toHexString :: Number -> String
would be pretty nice to have.
Pretty easy to implement as well:
toBinString :: Number -> String
toBinString = fromJust <<< toString "2"
toHexString :: Number -> String
toHexString = fromJust <<< toString "16"
These modules are unsafe from a compilation standpoint. For more info see here: https://github.com/purescript/purescript/wiki/FFI-tips#avoid-calling-ps-code-from-within-js-directly
Culprits are lines like: https://github.com/Jonplussed/purescript-number-format/blob/master/src/Number/Format/Maybe.purs#L14
Should be as simple as taking the Just
/Nothing
functions into the ffi and using them there.
Not to rain on your parade, but the reason these don't exist in the core libraries is they're actually a bit tricky to get right. ;)
We did have them at one point, and then later removed them because they only work with certain arguments, and we didn't want to wrap them in an Eff
with an exception or something.
The rules according to MDN:
toExponential
and toFixed
throw a RangeError
if the digits
provided is not between 0 and 20toPrecision
throws a RangeError
if the precision
provided is not between 0 and 100toString
throws a RangeError
if the radix
provided is not between 2 and 36A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.