Namespace: fnBase8Util

fnBase8Util

The fnBase8Util namespace is a namespace that provides functions for converting base 8 integer numbers in string representation to values of type number.

To use this API alone by itself, include fnBase8Util.js. Otherwise, include faiNumber-include-all.js.

This namespace API provides the function toNumberAsUnsigned that can parse unsigned base 8 numbers to values of type number. Unsigned parsing can be used for cases were it is known that the value or pool of values do not contain signs, or for value(s) that shouldn't be negative(without the positive sign). For parsing values that are signed use toNumber.

This namespace API also provides functions for comparing strings pertain to the mathematical aspect. The compareAsNumber of this namespace API can compare strings by their actual number values when the strings are valid strings of signed base 8 integer number that can be parsed to type number values.

Strings can also be compared using the numberOrSmaller method, of which compares the strings bases on their content reference to number values.

Since:
  • 1.0.0.f
Author:
  • Khang Hoang Nguyen
Source:

Members

(static) fileversion

File version number.
Source:

Methods

(static) compareAsNumber(firstNumber, secondNumber) → {string|undefined}

Compare two strings as signed base 8 integer numbers by parsing them to type number values first.

Take note that comparing strings with values larger than Number.MAX_SAFE_INTEGER or smaller than Number.MIN_SAFE_INTEGER will yield an undefined value.

This function does not throw errors. However, the toNumber function uses by this function throws errors.

Since:
  • 1.0.0.f
Source:
See:
Parameters:
NameTypeDescription
firstNumberstringA string to be compared to the string secondNumber.
secondNumberstringA string to be compared to the string firstNumber.
Returns:
TypeDescription
string
A value of 1 if the firstNumber string is larger than the secondNumber string, 0 if they are both equal, or -1 if the firstNumber string is smaller than the secondNumber string.
undefined
If parsing either one of the input strings yielded an undefined value, an undefined value is returned.

 
 

(static) numberOrSmaller(firstNumber, secondNumber) → {number}

Compare two strings bases on the content of the strings reference to values of type number. If the strings are valid strings of signed base 8 integer number that can be parsed to type number values then they will be compared base on their number values. Otherwise, the strings will be compared base on the priority ranking order below.

Take note that this method treats strings with values larger than Number.MAX_SAFE_INTEGER or smaller than Number.MIN_SAFE_INTEGER as undefined.

This function does not throw any error. However, the toNumber ultilizes by this function throws error.

Priority order ranking: (lo - hi)
0 - Undefined(NaN/Not a safe value)
1 - Empty strings
2 - Valid number values in range of MIN_SAFE_INTEGER and MAX_SAFE_INTEGER

Since:
  • 1.0.0.f
Source:
See:
Parameters:
NameTypeDescription
firstNumberstringA string to be compared to the string secondNumber.
secondNumberstringA string to be compared to the string firstNumber.
Returns:
TypeDescription
number
A value of 1 if the firstNumber string is larger than the secondNumber string, 0 if they are both equal, or -1 if the firstNumber string is smaller than the secondNumber string.

 
 

(static) toNumber(input) → {number|undefined}

Parse the input string as a string of signed base 8 integer number to a value of type number.
Since:
  • 1.0.0.f
Source:
Parameters:
NameTypeDescription
inputstringA string to be parsed as a signed base 8 integer number to a value of type number.
Throws:
TypeDescription
string
"Not a string" if the input is not of string type.
Returns:
TypeDescription
number
A value of the input string if the input string is a valid string of signed base 8 integer number.
undefined

A value of undefined is returned if the input string is not a valid string of signed base 8 integer number. Undefined is also returned where the input string is empty.

Parsing a value that is larger than the value of Number.MAX_SAFE_INTEGER(9007199254740991), or smaller than the value of Number.MIN_SAFE_INTEGER(-9007199254740991) will yield an undefined value.


 
 

(static) toNumberAsUnsigned(input) → {number|undefined}

Parse the input string as a string of unsigned base 8 integer number to a value of type number.
Since:
  • 1.0.0.f
Source:
Parameters:
NameTypeDescription
inputstringA string to be parsed as an unsigned base 8 integer number to a value of type number.
Throws:
TypeDescription
string
"Not a string" if the input is not of string type.
Returns:
TypeDescription
number
A value of type number of the input string if the input string is a valid string of unsigned base 8 integer number.
undefined

A value of undefined is returned if the input string is not a valid string of unsigned base 8 integer number. Undefined is also returned where the input string is empty.

Parsing a value that is larger than the value of Number.MAX_SAFE_INTEGER(9007199254740991) will yield an undefined value.