Skip to content

Latest commit

 

History

History
233 lines (184 loc) · 5.64 KB

Number.md

File metadata and controls

233 lines (184 loc) · 5.64 KB

@squirrel-forge/ui-util

Back to table of contents

Documentation

Javascript / Number

Logic <[ Number ]> Object

Table of contents


convertBytes

convertBytes - Convert a byte number to another unit

Description

convertBytes( bytes, decimals = 2, style = 1024, obj = false, forceUnit = null ) // string|Object

Converts a byte number to an auto fitting or defined size unit and returns a string or optionally an object with separated values.

Parameters

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

Return Values

Type/Value Description
String Converted unit string 'X.X unit'
Object Value object { value : Number, unit : String }

Examples

convertBytes( 1048576 ); // 1.00 mib

gcd

gcd - Get the common denominator

Description

gcd( a, b ) // number

Get the common denominator of two numbers.

Parameters

Parameter Type Default Description
a Number - Any integer
b Number - Any integer

Return Values

Type/Value Description
Number The common denominator

Examples

gcd( 165, 425 ); // 5 

isEven

isEven - Check for even number

Description

isEven( num ) // boolean

Check if a number is an even number.

Parameters

Parameter Type Default Description
num Number - Number to check

Return Values

Type/Value Description
Boolean True if the number is even

Examples

isEven( 28 ); // true
isEven( 3 ); // false

isFloat

isFloat - Check for a float value

Description

isFloat( num ) // boolean

Check if a number is a float value.

Parameters

Parameter Type Default Description
num Number - Number to check

Return Values

Type/Value Description
Boolean True if the number is a float

Examples

isFloat( 1.2 ); // true
isFloat( 2 ); // false

leadingZeros

leadingZeros - Return a number with leading zeros

Description

leadingZeros( num, length = 2 ) // string

Convert a number to a string with a fixed length with leading zeros.

Parameters

Parameter Type Default Description
num Number - Number to prefix
length Number 2 Expected result string

Return Values

Type/Value Description
String Number string with leading zeros

Examples

leadingZeros( 2 ); // '02'

rand

rand - Random integer

Description

rand( min, max ) // number

Get random integer.

Parameters

Parameter Type Default Description
min Number - Minimum value
max Number - Maximum value

Return Values

Type/Value Description
Number Integer

Examples

rand( 1, 10 ); // (1|2|3|4|5|6|7|8|9|10)

Ratio

Ratio class - A ratio value class.

Class overview

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 - Round value

Description

round( value, decimals = 2 ) // number

Round value to specific decimals, default 2.

Parameters

Parameter Type Default Description
value Number - Number to round
decimals Number - Number of decimals

Return Values

Type/Value Description
Number Rounded float value

Examples

round( 4.5678 ); // 4.57

Logic <[ Number ]> Object