dividab / uom

Extensible unit of measure conversion with type safety for typescript
MIT License
18 stars 1 forks source link

Unit registry #11

Closed jonaskello closed 5 years ago

jonaskello commented 5 years ago

Today this package comes with a large set of different units. This causes a problem for some applications that wants to limit the number of units available in their application.

To solve this we could let the applications pick which units they want to work with. We could still include all the units in this package, but we need to provide a mechanism to work with a subset of the units.

For example, all units have meta-data which is registered in a global registry and this meta-data can then be used to fill UI drop-downs of available units. All units are automatically registered and available when this package is loaded. If we could disable this auto-registring and require an explicit call to register units that would give more control to applications to register the units they want to use and thus have control over what is displayed in the UI.

In addition we have some applications that use a different unit framework on the server-side and for those applications it is important that the units on the client side is the same as the supported units on the server-side.

jonaskello commented 5 years ago

The registries are:

jonaskello commented 5 years ago

I think we need to somehow make the units.ts module only export pure unit constants, without going through registerUnit() for each export. Instead registration can happen later and is up to each application.

jonaskello commented 5 years ago

One step is to move all exports that are not units away from the units.ts module and into a new modules, something like unit-registry.ts. This is a breaking change. I will make a PR for this.