ref: 63ba7027c492964c0690bf722e6b34748ec8b8a4 bare-js/README.md -rw-r--r-- 1.8 KiB
63ba7027 — Emma Use js BigInt for variable length, and 64 bit integer types 6 months ago


This is a work-in-progress JavaScript/Node.js implementation of BARE.

The idea so far is, that the parser and converter will run with node.js, while the resulting JavaScript classes should be usable in any JavaScript environment.

Have a look at examples.js on how to create type definitions in code for now. Or peek inside the lib-bare.js, where all conversion classes are located. These are to be used directly when defining your own type. Whenever a type takes some sort of arguments, they are static variables right at the top, just make sure to set them correctly since there are, as of now, no integrity checks on them.

###What is still missing

  • The schema to js translator
  • Union and Enum types These are difficult to translate to js, so I'm going to have to think about use cases and how to make them convenient to use
  • Conversion error handling and integrity verification
  • Unit tests, these will come last

###A note about Number and 64 bits Javascript is a wonderful language, and as such it doesn't use an integer type for numbers. Instead, every single number is stored as a double precision float. This limits the usable range of integers to 53 bits, which means the maximum unsigned value is just over 9 quadrillion (10^15). There is the BitInt type that allows arbitrary large integers. But it has limitations; you can't use them in Math functions or beside regular Numbers. Keep this in mind when using the variable length, and the 64 bit integer types, since these return a BigInt by default. The lib provides safeNumber which will convert a BigInt to Number if it fits into 53 bits, or throw an Error if it does not fit if you just need a little more headroom.