convertBytes - Convert a byte number to another unit
convertBytes( bytes, decimals = 2, style = 1024, obj = false, forceUnit = null ) // string|ObjectConverts a byte number to an auto fitting or defined size unit and returns a string or optionally an object with separated values.
| Parameter | Type | Default | Description |
|---|---|---|---|
| bytes | Number | - | Number of bytes |
| decimals | Number | 2 | How many decimals to display |
| style | Number | 1024 | Calculate bytes with 1024 or with 1000 |
| obj | Boolean | false | Whether to return an object with values |
| forceUnit | String | null | Force conversion to a specific unit, must fit to style |
| Type/Value | Description |
|---|---|
| String | Converted unit string 'X.X unit' |
| Object | Value object { value : Number, unit : String } |
convertBytes( 1048576 ); // 1.00 mibgcd - Get the common denominator
gcd( a, b ) // numberGet the common denominator of two numbers.
| Parameter | Type | Default | Description |
|---|---|---|---|
| a | Number | - | Any integer |
| b | Number | - | Any integer |
| Type/Value | Description |
|---|---|
| Number | The common denominator |
gcd( 165, 425 ); // 5 isEven - Check for even number
isEven( num ) // booleanCheck if a number is an even number.
| Parameter | Type | Default | Description |
|---|---|---|---|
| num | Number | - | Number to check |
| Type/Value | Description |
|---|---|
| Boolean | True if the number is even |
isEven( 28 ); // true
isEven( 3 ); // falseisFloat - Check for a float value
isFloat( num ) // booleanCheck if a number is a float value.
| Parameter | Type | Default | Description |
|---|---|---|---|
| num | Number | - | Number to check |
| Type/Value | Description |
|---|---|
| Boolean | True if the number is a float |
isFloat( 1.2 ); // true
isFloat( 2 ); // falseleadingZeros - Return a number with leading zeros
leadingZeros( num, length = 2 ) // stringConvert a number to a string with a fixed length with leading zeros.
| Parameter | Type | Default | Description |
|---|---|---|---|
| num | Number | - | Number to prefix |
| length | Number | 2 | Expected result string |
| Type/Value | Description |
|---|---|
| String | Number string with leading zeros |
leadingZeros( 2 ); // '02'rand - Random integer
rand( min, max ) // numberGet random integer.
| Parameter | Type | Default | Description |
|---|---|---|---|
| min | Number | - | Minimum value |
| max | Number | - | Maximum value |
| Type/Value | Description |
|---|---|
| Number | Integer |
rand( 1, 10 ); // (1|2|3|4|5|6|7|8|9|10)Ratio class - A ratio value class.
class Ratio {
static make( width, height = null, separator = ':' ) {} // string
constructor( width, height = null, separator = ':' ) {}
separator : String
w : Number // Input width
h : Number // Input height
r : Number // Ratio value
x : Number // Ratio width
y : Number // Ratio height
toString() {} // string
}For more details check the Ratio source file.
round - Round value
round( value, decimals = 2 ) // numberRound value to specific decimals, default 2.
| Parameter | Type | Default | Description |
|---|---|---|---|
| value | Number | - | Number to round |
| decimals | Number | - | Number of decimals |
| Type/Value | Description |
|---|---|
| Number | Rounded float value |
round( 4.5678 ); // 4.57