- 20 complete units of measure.
- Parse any programming data type or convert fractions without any errors.
- Ability to create your own custom UnitOf measurements.
- Small (entire suite as little as 64kb), fast, and easy to use with super simple syntax.
- https://digidemic.github.io/UnitOf/ provides full documentation of all measurements and units, live examples, FAQ, and much more.
- Cloning the repo and navigating to
/UnitOf-Examples/
provides in-depth runnable demo projects and examples for all languages of UnitOf.
Java
&C#
(NOTE: Written in Java but C# is the exact same only Pascal Cased methods)
/* For Java, same for C# but Pascal Cased methods. C# also uses Dictionary instead of HashMap for UnitOf.Anything parameter */
//One Liner
double a = new UnitOf.Mass().fromPounds(5).toKilograms(); //2.26796 returned as 5 pounds is 2.26796 kilograms
//Set Then Convert
UnitOf.Length feet = new UnitOf.Length().fromFeet(5.5); //Instantiate UnitOf.Length and set "feet" as 5.5
double b = feet.toInches(); //66 returned as 5.5 feet is 66 inches
double c = feet.toMeters(); //1.6764 returned as 5.5 feet is 1.6764 meters
//Convert Data Type and Fractions
double d = new UnitOf.DataType("12.5").toDouble(); //12.5 of type double returned. 0.0 would be returned if conversion failed
int e = new UnitOf.DataType("Not A Number").toInt(10); //10 of type int returned since conversion fails
String f = new UnitOf.DataType(0.5).toFraction(); //"1/2" of type String returned. Empty string would be returned if failed
//Create Your Own Custom Measurement
UnitOf.Anything x = new UnitOf.Anything("FEET", new HashMap<Object, Double>() {{ put("METERS", 0.3048); put("INCHES", 12.0); }});
double g = x.convertNow(36, "INCHES", "FEET"); //3 returned as 36 inches is 3 feet
double h = x.convertNow(3, "FEET", "METERS"); //0.9144 returned as 3 feet is 0.9144 meters
JavaScript
/* For JavasScript */
//One Liner
var a = UnitOf.Mass.fromPounds(5).toKilograms; //2.26796 returned as 5 pounds is 2.26796 kilograms
//Set Then Convert
var feet = UnitOf.Length.fromFeet(5.5); //Instantiate UnitOf.Length and set "feet" as 5.5
var b = feet.toInches; //66 returned as 5.5 feet is 66 inches
var c = feet.toMeters; //1.6764 returned as 5.5 feet is 1.6764 meters
//Convert Data Type and Fractions
var d = UnitOf.DataType("12.5").toFloat(); //12.5 of type Float returned. 0 would be returned if conversion failed
var e = UnitOf.DataType("Not A Number").toInt(10); //10 of type Int returned since conversion fails
var f = UnitOf.DataType(0.5).toFraction(); //"1/2" of type string returned. Empty string would be returned if failed
//Create your own custom measurement
var x = UnitOf.Anything("FEET", 1, true, {METERS:0.3048, INCHES:12}); //Custom measurement w/ 3 units
var g = x.convertNow(36, "INCHES", "FEET"); //3 returned as 36 inches is 3 feet
var h = x.convertNow("3", "FEET", "METERS"); //0.9144 returned as 3 feet is 0.9144 meters
Clone the UnitOf repo to your local machine using
https://github.com/digidemic/UnitOf
Only the single compiled UnitOf file of its language needs to be imported and referenced.
- Add JitPack to your project's root
build.gradle
at the end ofrepositories
:
-
dependencyResolutionManagement { repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS) repositories { mavenCentral() maven { url 'https://jitpack.io' } } }
- In the
build.gradle
of the module(s) you wish to use UnitOf with, add the following todependencies
:
-
dependencies { implementation 'com.github.digidemic:unitof:1.0.1' }
- Sync gradle successfully.
- Done! Your project is now ready to use UnitOf. Go to Examples or the UnitOf website for UnitOf usage!
- Import
/UnitOf.jar
from the cloned repo into your project.- In your classes using UnitOf, add
import com.digidemic.unitof.UnitOf;
to your list of imports.
-
- From within Netbeans, Right-click the project >
Properties
>Libraries
category >Compile
tab >Add JAR/Folder
> Navigate and selectUnitOf.jar
from the cloned repo.
- From within Netbeans, Right-click the project >
-
- From within Android Studio with the project open,
Project
tab open > Switch folder structure toProject
> Expand the project and find thelibs
directory (if not there create it in the same directory assrc
andres
) > Add theUnitOf.jar
from the cloned repo tolibs
directory > Right-click the newly addedUnitOf.jar
node in thelibs
directory > clickAdd As Library...
> ClickOK
in theCreate Library
dialog.
- From within Android Studio with the project open,
npm install unitof
- Import
/UnitOf.min.js
from the cloned repo into your project- Add the following script tag (with the full path of
/UnitOf.min.js
) to the index html file:
<script src="/UnitOf.min.js"></script>
Install-Package UnitOf -Version 1.0.0
- Import
/UnitOf.dll
from the cloned repo into your project.- In your index class or any class needed, add
using UnitOf;
to your list of imports.
-
- From within Visual Studio with the project open,
Solution Explorer
tab open > Expand the project directories navigating toReferences
> Right-clickReferences
> ClickAdd Reference...
> ClickBrowser...
> Navigate and selectUnitOf.dll
from the cloned repo > Make sureUnitOf.dll
is checked and clickOK
.
- From within Visual Studio with the project open,
- A derivative of SemVer is used for versioning.
- Given a version number MAJOR . MINOR . PATCH . LANGUAGE_SPECIFIC_UPDATE COMMENT
- MAJOR version - Incompatible API changes.
- MINOR version - Functionality added in a backwards-compatible manner.
- PATCH version - Backwards-compatible bug fixes.
- LANGUAGE_SPECIFIC_UPDATE version - Specific functionality added or bug fixes only affecting a specific language (
Java
,JavaScript
, orC#
). - COMMENT version (optional) - Presented as an alphabetic letter starting with "a", includes anything that does not affect size, performance, features, or fixes to the compiled solution. Adding or editing comments in code would be an example of this version.
- Version number may vary slightly between
Java
,JavaScript
, andC#
instances of UnitOf.- MAJOR.MINOR.PATH will always be consistent across all languages.
- As an example they can be as follows:
Java
- UnitOf_v1.2.3.0JavaScript
- UnitOf_v1.2.3.0bC#
- UnitOf_v1.2.3.2a
UnitOf website, logo, Palindrome Conversion Algorithm, and all source code & example projects for Java, JavaScript & C# created by Adam Steinberg of DIGIDEMIC, LLC
Copyright 2024 DIGIDEMIC, LLC
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.