Coder Social home page Coder Social logo

jscheiny / safe-units Goto Github PK

View Code? Open in Web Editor NEW
258.0 4.0 13.0 789 KB

Type-safe TypeScript units of measure ๐Ÿ‘ท๐Ÿ“

Home Page: https://jscheiny.github.io/safe-units

License: MIT License

TypeScript 98.94% Shell 0.20% JavaScript 0.85%
typescript typesafe dimensional-analysis units-of-measure units

safe-units's People

Contributors

dependabot[bot] avatar jscheiny avatar rootulp avatar timjb avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

safe-units's Issues

Conversion not working

Hi,
first: thank you for your great work!

Using your library I discovered that:
Measure.of(1, radians.per(seconds)).in(degrees.per(seconds)).toString() returns "1 rad / s"
I expected it to return ~"57 deg / s"
Did I do something wrong?

Best regards
Michael

Measure.of(<value>, bytes) yields value in bits

Hello!

From the readme, I expected:

console.log(Measure.of(72, bytes).toString());

to print 72 B

but, the result is 576 b as the underlying value created by Measure.of is in bits.

This is a bit confusing as other higher order units behave as I would expect them to, e.g.:

console.log(Measure.of(72, kilograms).toString());

yields 72 kg rather than 72000 g.

Using v1.1.0 with Typescript v4.3.5.

Can assign incompatible measures if they have some dimensions in common,

The following, taken from the documentation

const error: Velocity = length.times(time);
// ERROR: A measure of m*s isn't assignable to a measure of m/s.

Gives a compile-time error.

But removing the times operation, making it just

const error: Velocity = length

Does not give a compile-time error, although the measures are clearly incompatible
Am I missing something? I have strict turned on in my tsconfig file.

Thanks otherwise for a fantastic library

value in an unit

Hello!

Would appreciate an escape-hatch to get the value in a particular unit, e.g.

Measure.of(8, furlongs).valueIn(miles) returns numeric 1.

Formatting options

This seams like a very useful library and I've been toying with it a bit.

I was wondering if there are more formatting options, corresponding to toFixed and toPrecision. I was using the lib in a react application and wanted to some simple unit conversion for display, but I got this, which is not really suitable for display.

<span>{distance.in(kilo(meters))}</span> // "29.023945563497445 km"

Is there another way to do this or is it a limitation?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.