typescript-base
Version:
A TypeScript implementation of basic exception, assertion and parameter check functions.
1,065 lines (1,063 loc) • 228 kB
JavaScript
"use strict";
var TS;
(function (TS) {
"use strict";
/**
* @class TS.Exception
*
* @description The base class of all exceptions defined in this framework. The Exception class has a public read only
* property called 'type' which returns the fully qualified type name of the exception class. This way you are able
* to create a finer granular error handling based on the exception type. Your are not longer forced to parse the
* error message string to infer the nature of the exception. Each subclass of the Exception class has to override
* the 'type' property to reflect the own type. The exception class has also a read only 'innerException' property
* which allows to create an exception stack which links back to the root exception.
*
* @implements {Error}
*/
class Exception {
/**
* @constructor
*
* @param {string} message?, An optional message string.
* @param {Exception} innerException?, An optional inner exception.
*/
constructor(message = "", innerException) {
this.internalMessage = (message) ? message : "";
this.internalInnerException = (innerException) ? innerException : null;
}
/**
* @description Returns the inner exception if available or null.
*
* @public
*
* @get {TS.Exception | null} innerException
*/
get innerException() {
return this.internalInnerException;
}
/**
* @description The error message.
*
* @implements {Error}
*
* @get {string} message
*/
get message() {
return this.internalMessage;
}
/**
* @description The error name. It's the same as the type.
*
* @implements {Error}
*
* @get {string} name
*/
get name() {
return this.type;
}
/**
* @description Returns the fully qualified type name of the exception.
*
* @public
*
* @get {string} type
*/
get type() {
return "TS.Exception";
}
/**
* @description Returns a combination of the 'type' and 'message' of the exception as string.
*
* @override {Object}
*
* @returns {string}
*/
toString() {
return this.type + ((this.message.length > 0) ? " :: " + this.message : "");
}
/**
* @description Returns a string which is the concatenation of the 'toString' call results of the current exception and the inner exceptions.
* Call this function without any arguments on the top exception of the exception chain.
*
* @param {TS.Exception} exception
* @param {boolean} isInner, Defaults to false
* @param {string} offset, A string which is used to indent inner exception messages. Default to 2 spaces.
*
* @returns {string}
*/
stackTrace(exception = this, isInner = false, offset = " ") {
let returnString;
returnString = "";
returnString += exception.toString();
if (exception.innerException != null) {
returnString += "\r\n" + offset + this.stackTrace(exception.innerException, true, offset + " ");
} //END if
return returnString;
}
}
TS.Exception = Exception; //END class
//********************************************************************************
// AmbiguousResult exception
//********************************************************************************
/**
* @class TS.AmbiguousResultException
*
* @description This exception signals a an error where an operation which is specified to deliver a single result
* fails because there are multiple possible results available.
*
* @extends {TS.Exception}
*/
class AmbiguousResultException extends TS.Exception {
/**
* @constructor
*
* @param {string} argumentName, The name of the argument which caused the exception.
* @param {any} argumentValue, The value of the argument which caused the exception.
* @param {string} message?, An optional message string.
* @param {Exception} innerException?, An optional inner exception.
*/
constructor(argumentName, argumentValue, message, innerException) {
super(message, innerException);
this.internalArgumentName = (argumentName) ? argumentName : "";
this.internalArgumentValue = argumentValue;
}
/**
* @override {TS.Exception}
*
* @get {string} type
*/
get type() {
return "TS.AmbiguousResultException";
}
/**
* @description The name of the argument which caused the exception.
*
* @get {string} argumentName
*/
get argumentName() {
return this.internalArgumentName;
}
/**
* @description The value of the argument which caused the exception.
*
* @get {any} argumentValue
*/
get argumentValue() {
return this.internalArgumentValue;
}
}
TS.AmbiguousResultException = AmbiguousResultException; //END class
//********************************************************************************
// Argument exception
//********************************************************************************
/**
* @class TS.ArgumentException
*
* @description This exceptions signals a general error caused by an invalid argument.
*
* @extends {TS.Exception}
*/
class ArgumentException extends TS.Exception {
/**
* @constructor
*
* @param {string} argumentName, The name of the argument which caused the exception.
* @param {any} argumentValue, The value of the argument which caused the exception.
* @param {string} message?, An optional message string.
* @param {Exception} innerException?, An optional inner exception.
*/
constructor(argumentName, argumentValue, message, innerException) {
super(message, innerException);
this.internalArgumentName = (argumentName) ? argumentName : "";
this.internalArgumentValue = argumentValue;
}
/**
* @override {TS.Exception}
*
* @get {string} type
*/
get type() {
return "TS.ArgumentException";
}
/**
* @description The name of the argument which caused the exception.
*
* @get {string} argumentName
*/
get argumentName() {
return this.internalArgumentName;
}
/**
* @description The value of the argument which caused the exception.
*
* @get {any} argumentValue
*/
get argumentValue() {
return this.internalArgumentValue;
}
}
TS.ArgumentException = ArgumentException; //END class
/**
* @class TS.ArgumentNullException
*
* @description This exception signals an error caused by an unexpected null value in an argument.
*
* @extends {TS.ArgumentException}
*/
class ArgumentNullException extends TS.ArgumentException {
/**
* @constructor
*
* @param {string} argumentName, The name of the argument which caused the exception.
* @param {string} message?, An optional message string.
* @param {Exception} innerException?, An optional inner exception.
*/
constructor(argumentName, message = "", innerException) {
super(message, null, message, innerException);
}
/**
* @override {TS.Exception}
*
* @get {string} type
*/
get type() {
return "TS.ArgumentNullException";
}
}
TS.ArgumentNullException = ArgumentNullException; //END class
/**
* @class TS.ArgumentNullOrUndefinedException
*
* @description This exceptions signals an error caused by an unexpected undefined or null value in an argument. The
* argument value of that exception will always be null and doesn't reflect the exact argument value which caused
* this exception.
*
* @extends {TS.ArgumentException}
*/
class ArgumentNullOrUndefinedException extends TS.ArgumentException {
/**
* @constructor
*
* @param {string} argumentName, The name of the argument which caused the exception.
* @param {string} message?, An optional message string.
* @param {Exception} innerException?, An optional inner exception.
*/
constructor(argumentName, message = "", innerException) {
super(message, null, message, innerException);
}
/**
* @override {TS.Exception}
*
* @get {string} type
*/
get type() {
return "TS.ArgumentNullOrUndefinedException";
}
}
TS.ArgumentNullOrUndefinedException = ArgumentNullOrUndefinedException; //END class
/**
* @class TS.ArgumentNullUndefOrEmptyException
*
* @description This exception signals an error caused by an unexpected undefined or null value in an argument or
* an unexpected emptiness for an argument like an empty string or array. The argument value of that exception
* will always be null and doesn't reflect the exact argument value which caused this exception.
*
* @extends {TS.ArgumentException}
*/
class ArgumentNullUndefOrEmptyException extends TS.ArgumentException {
/**
* @constructor
*
* @param {string} argumentName, The name of the argument which caused the exception.
* @param {string} message?, An optional message string.
* @param {Exception} innerException?, An optional inner exception.
*/
constructor(argumentName, message, innerException) {
super(argumentName, null, message, innerException);
}
/**
* @override {TS.Exception}
*
* @get {string} type
*/
get type() {
return "TS.ArgumentNullUndefOrEmptyException";
}
}
TS.ArgumentNullUndefOrEmptyException = ArgumentNullUndefOrEmptyException; //END class
/**
* @class TS.ArgumentNullUndefOrWhiteSpaceException
*
* @description This exceptions signals an unexpected emptiness of a string. The argument value of that exception
* will always be null and doesn't reflect the exact argument value which caused this exception.
*
* @extends {TS.ArgumentException}
*/
class ArgumentNullUndefOrWhiteSpaceException extends TS.ArgumentException {
/**
* @constructor
*
* @param {string} argumentName, The name of the argument which caused the exception.
* @param {string} message?, An optional message string.
* @param {Exception} innerException?, An optional inner exception.
*/
constructor(argumentName, message, innerException) {
super(argumentName, null, message, innerException);
}
/**
* @override {TS.Exception}
*
* @get {string} type
*/
get type() {
return "TS.ArgumentNullUndefOrWhiteSpaceException";
}
}
TS.ArgumentNullUndefOrWhiteSpaceException = ArgumentNullUndefOrWhiteSpaceException; //END class
/**
* @class TS.ArgumentOutOfRangeException
*
* @description This exceptions signals that an argument exceeded the range of allowed values.
*
* @extends {TS.ArgumentException}
*/
class ArgumentOutOfRangeException extends TS.ArgumentException {
/**
* @constructor
*
* @param {string} argumentName, The name of the argument which caused the exception.
* @param {any} argumentValue, The value of the argument which caused the exception.
* @param {string} message?, An optional message string.
* @param {Exception} innerException?, An optional inner exception.
*/
constructor(argumentName, argumentValue, message, innerException) {
super(argumentName, argumentValue, message, innerException);
}
/**
* @override {TS.ArgumentException}
*
* @get {string} type
*/
get type() {
return "TS.ArgumentOutOfRangeException";
}
}
TS.ArgumentOutOfRangeException = ArgumentOutOfRangeException; //END class
/**
* @class TS.ArgumentUndefinedException
*
* @description This exceptions signals an error caused by an unexpected undefined value in an argument.
*
* @extends {TS.ArgumentException}
*/
class ArgumentUndefinedException extends TS.ArgumentException {
/**
* @constructor
*
* @param {string} argumentName, The name of the argument which caused the exception.
* @param {string} message?, An optional message string.
* @param {Exception} innerException?, An optional inner exception.
*/
constructor(argumentName, message, innerException) {
super(argumentName, undefined, message, innerException);
}
/**
* @override {TS.ArgumentException}
*
* @get {string} type
*/
get type() {
return "TS.ArgumentUndefinedException";
}
}
TS.ArgumentUndefinedException = ArgumentUndefinedException; //END class
//********************************************************************************
// Index exceptions
//********************************************************************************
/**
* @class TS.IndexOutOfRangeException
*
* @description This exceptions signals that an index value exceeded the range of indexable elements.
*
* @extends {TS.Exception}
*/
class IndexOutOfRangeException extends TS.Exception {
/**
* @constructor
*
* @param {string} message?, An optional message string.
* @param {Exception} innerException?, An optional inner exception.
*/
constructor(message, innerException) {
super(message, innerException);
}
/**
* @get {string} type
* @public
* @override {TS.Exception}
*/
get type() {
return "TS.IndexOutOfRangeException";
}
}
TS.IndexOutOfRangeException = IndexOutOfRangeException; //END class
//********************************************************************************
// Invalid invocation exceptions
//********************************************************************************
/**
* @class TS.InvalidInvocationException
*
* @description This exceptions signals that a function was invoked in an unexpected or invalid way.
*
* @extends {TS.Exception}
*/
class InvalidInvocationException extends TS.Exception {
/**
* @constructor
*
* @param {string} message?, An optional message string.
* @param {Exception} innerException?, An optional inner exception.
*/
constructor(message, innerException) {
super(message, innerException);
}
/**
* @override {TS.Exception}
*
* @get {string} type
*/
get type() {
return "TS.InvalidInvocationException";
}
}
TS.InvalidInvocationException = InvalidInvocationException; //END class
//********************************************************************************
// Invalid operation exceptions
//********************************************************************************
/**
* @class TS.InvalidOperationException
*
* @description This exceptions signals an attempt to start an operation which was not allowed to start in the current
* situation.
*
* @extends {TS.Exception}
*/
class InvalidOperationException extends TS.Exception {
/**
* @constructor
*
* @param {string} message?, An optional message string.
* @param {Exception} innerException?, An optional inner exception.
*/
constructor(message, innerException) {
super(message, innerException);
}
/**
* @override {TS.Exception}
*
* @get {string} type
*/
get type() {
return "TS.InvalidOperationException";
}
}
TS.InvalidOperationException = InvalidOperationException; //END class
//********************************************************************************
// Invalid cast exception
//********************************************************************************
/**
* @class TS.InvalidCastException
*
* @description This exceptions signals that a casting operation failed.
* @extends {TS.Exception}
*/
class InvalidCastException extends TS.Exception {
/**
* @constructor
*
* @param {string} message?, An optional message string.
* @param {Exception} innerException?, An optional inner exception.
*/
constructor(message, innerException) {
super(message, innerException);
}
/**
* @override {TS.Exception}
*
* @get {string} type
*/
get type() {
return "TS.InvalidCastException";
}
}
TS.InvalidCastException = InvalidCastException; //END class
//********************************************************************************
// Invalid format exception
//********************************************************************************
/**
* @class TS.InvalidFormatException
*
* @description This exceptions signals that an operation failed because of an invalid format of some data.
*
* @extends {TS.Exception}
*/
class InvalidFormatException extends TS.Exception {
/**
* @constructor
*
* @param {string} argumentName, The name of the argument which caused the exception.
* @param {any} argumentValue, The value of the argument which caused the exception.
* @param {string} message?, An optional message string.
* @param {Exception} innerException?, An optional inner exception.
*/
constructor(argumentName = "", argumentValue = "", message, innerException) {
super(message, innerException);
}
/**
* @override {TS.Exception}
*
* @get {string} type
*/
get type() {
return "TS.InvalidFormatException";
}
/**
* @description The name of the argument which caused the exception.
*
* @get {string} argumentName
*/
get argumentName() {
return this.internalArgumentName;
}
/**
* @description The value of the argument which caused the exception.
*
* @get {string} argumentValue
*/
get argumentValue() {
return this.internalArgumentValue;
}
}
TS.InvalidFormatException = InvalidFormatException; //END class
//********************************************************************************
// Invalid type exception
//********************************************************************************
/**
* @class TS.InvalidTypeException
*
* @description This exceptions signals that an argument has an invalid type.
*
* @extends {TS.Exception}
*/
class InvalidTypeException extends TS.Exception {
/**
* @constructor
*
* @param {string} argumentName, The name of the argument which caused the exception.
* @param {any} argumentValue, The value of the argument which caused the exception.
* @param {string} message?, An optional message string.
* @param {Exception} innerException?, An optional inner exception.
*/
constructor(argumentName = "", argumentValue = "", message, innerException) {
super(message, innerException);
}
/**
* @override {TS.Exception}
*
* @get {string} type
*/
get type() {
return "TS.InvalidTypeException";
}
/**
* @description The name of the argument which caused the exception.
*
* @get {string} argumentName
*/
get argumentName() {
return this.internalArgumentName;
}
/**
* @description The value of the argument which caused the exception.
*
* @get {string} argumentValue
*/
get argumentValue() {
return this.internalArgumentValue;
}
}
TS.InvalidTypeException = InvalidTypeException; //END class
//********************************************************************************
// ArithmeticException
//********************************************************************************
/**
* @class TS.ArithmeticException
*
* @description This exception signals an errors in an arithmetic, casting, or conversion operation.
* ArithmeticException is the base class for DivideByZeroException, NotFiniteNumberException, and OverflowException.
* Use one of the derived classes of ArithmeticException if appropriate to the exact nature of the error.
* Throw an ArithmeticException if there is no appropriate subclass to describe the nature of the error.
*
* @extends {TS.Exception}
*/
class ArithmeticException extends TS.Exception {
/**
* @constructor
*
* @param {string} message?, An optional message string.
* @param {Exception} innerException?, An optional inner exception.
*/
constructor(message, innerException) {
super(message, innerException);
}
/**
* @override {TS.Exception}
*
* @get {string} type
*/
get type() {
return "TS.ArithmeticException";
}
}
TS.ArithmeticException = ArithmeticException; //END class
/**
* @class TS.OverflowException
*
* @description This exception signals that an arithmetic, casting, or conversion operation results in an overflow.
*
* @extends {TS.ArithmeticException}
*/
class OverflowException extends ArithmeticException {
/**
* @constructor
*
* @param {string} message?, An optional message string.
* @param {Exception} innerException?, An optional inner exception.
*/
constructor(message, innerException) {
super(message, innerException);
}
/**
* @override {TS.ArithmeticException}
*
* @get {string} type
*/
get type() {
return "TS.OverflowException";
}
}
TS.OverflowException = OverflowException; //END class
/**
* @class TS.DividedByZeroException
*
* @description This exception signals an attempt to divide a number value by zero.
*
* @extends {TS.ArithmeticException}
*/
class DividedByZeroException extends ArithmeticException {
/**
* @constructor
*
* @param {string} message?, An optional message string.
* @param {Exception} innerException?, An optional inner exception.
*/
constructor(message, innerException) {
super(message, innerException);
}
/**
* @override {TS.ArithmeticException}
*
* @get {string} type
*/
get type() {
return "TS.DividedByZeroException";
}
}
TS.DividedByZeroException = DividedByZeroException; //END class
/**
* @class TS.NotFiniteNumberException
*
* @description This exception signals an attempt to execute an arithmetic operation with a number value which is
* either infinite or Not-a-Number (NaN).
*
* @extends {TS.ArithmeticException}
*/
class NotFiniteNumberException extends ArithmeticException {
/**
* @constructor
*
* @param {string} message?, An optional message string.
* @param {Exception} innerException?, An optional inner exception.
*/
constructor(message, innerException) {
super(message, innerException);
}
/**
* @override {TS.ArithmeticException}
*
* @get {string} type
*/
get type() {
return "TS.NotFiniteNumberException";
}
}
TS.NotFiniteNumberException = NotFiniteNumberException; //END class
//********************************************************************************
// Infrastructure Exceptions
//********************************************************************************
/**
* @class TS.NotImplementedException
*
* @description This exception signals that a function or class is not or not fully implemented and can't be used.
*
* @extends {TS.Exception}
*/
class NotImplementedException extends TS.Exception {
/**
* @constructor
*
* @param {string} message?, An optional message string.
* @param {Exception} innerException?, An optional inner exception.
*/
constructor(message, innerException) {
super(message, innerException);
}
/**
* @override {TS.Exception}
*
* @get {string} type
*/
get type() {
return "TS.NotImplementedException";
}
}
TS.NotImplementedException = NotImplementedException;
/**
* @class TS.DeprecatedException
*
* @description This exception signals that a function or class should not longer be used.
*
* @extends {TS.Exception}
*/
class DeprecatedException extends TS.Exception {
/**
* @constructor
*
* @param {string} message?, An optional message string.
* @param {Exception} innerException?, An optional inner exception.
*/
constructor(message, innerException) {
super(message, innerException);
}
/**
* @override {TS.Exception}
*
* @get {string} type
*/
get type() {
return "TS.DeprecatedException";
}
}
TS.DeprecatedException = DeprecatedException;
//********************************************************************************
// File and directory exceptions
//********************************************************************************
/**
* @class TS.DirectoryNotFoundException
*
* @description This exception signals if the file system is not able to locate the requested directory.
*
* @extends {TS.Exception}
*/
class DirectoryNotFoundException extends TS.Exception {
/**
* @constructor
*
* @param {string} argumentName, The name of the argument which caused the exception. Typically the name of a directory variable.
* @param {any} argumentValue, The value of the argument which caused the exception. Typically the value of a directory variable.
* @param {string} message?, An optional message string.
* @param {Exception} innerException?, An optional inner exception.
*/
constructor(argumentName = "", argumentValue = "", message, innerException) {
super(message, innerException);
}
/**
* @override {TS.Exception}
*
* @get {string} type
*/
get type() {
return "TS.DirectoryNotFoundException";
}
/**
* @description The name of the argument which caused the exception.
*
* @get {string} argumentName
*/
get argumentName() {
return this.internalArgumentName;
}
/**
* @description The value of the argument which caused the exception.
*
* @get {string} argumentValue
*/
get argumentValue() {
return this.internalArgumentValue;
}
}
TS.DirectoryNotFoundException = DirectoryNotFoundException;
//********************************************************************************
// IO exceptions
//********************************************************************************
/**
* @class TS.BufferOverrunException
*
* @description This exception signals if the file system is not able to locate the requested directory.
*
* @extends {TS.Exception}
*/
class BufferOverrunException extends TS.Exception {
/**
* @constructor
*
* @param {string} message?, An optional message string.
* @param {Exception} innerException?, An optional inner exception.
*/
constructor(message, innerException) {
super(message, innerException);
}
/**
* @override {TS.Exception}
*
* @get {string} type
*/
get type() {
return "TS.BufferOverrunException";
}
}
TS.BufferOverrunException = BufferOverrunException;
//********************************************************************************
// Environment exceptions
//********************************************************************************
/**
* @class TS.EnvironmentNotSupportedException
*
* @description This exception that some operation failed because the current environment is not supported. That may
* be the reason if a JavaScript VM lacks some functions, a Node.js script is running in a browser or vice versa or
* the operation system is not supported.
*
* @extends {TS.Exception}
*/
class EnvironmentNotSupportedException extends TS.Exception {
/**
* @constructor
*
* @param {string} message?, An optional message string.
* @param {Exception} innerException?, An optional inner exception.
*/
constructor(message, innerException) {
super(message, innerException);
}
/**
* @override {TS.Exception}
*
* @get {string} type
*/
get type() {
return "TS.EnvironmentNotSupportedException";
}
}
TS.EnvironmentNotSupportedException = EnvironmentNotSupportedException;
//********************************************************************************
// Timing exceptions
//********************************************************************************
/**
* @class TS.TimeoutException
*
* @description This exception if thrown if a function or operation doesn't response in a timely manner.
*
* @extends {TS.Exception}
*/
class TimeoutException extends TS.Exception {
/**
* @constructor
*
* @param {string} message?, An optional message string.
* @param {Exception} innerException?, An optional inner exception.
*/
constructor(message, innerException) {
super(message, innerException);
}
/**
* @override {TS.Exception}
*
* @get {string} type
*/
get type() {
return "TS.TimeoutException";
}
}
TS.TimeoutException = TimeoutException;
/**
* @description The module 'Utils' hosts a collection of functions which offer solutions for common problems or
* reoccurring tasks which are not class specific. Since they are not class specific, they are also not part of a
* class. They are simply collected in this file and are part of the namespace. You can consider all of this
* functions as static if you like, because you can call them without a prior instantiation of an object.
*/
var Utils;
(function (Utils) {
/**
* @description An array of currencies as defined in ISO 4217
*
* @see {@link http://www.iso.org/iso/home/standards/currency_codes.htm | ISO}
*/
Utils.currencyArray = new Array({ Name: "United Arab Emirates Dirham", Code: "AED", Symbol: "" }, { Name: "Afghanistan Afghani", Code: "AFN", Symbol: "؋" }, { Name: "Albania Lek", Code: "ALL", Symbol: "" }, { Name: "Armenia Dram", Code: "AMD", Symbol: "" }, { Name: "Netherlands Antilles Guilder", Code: "ANG", Symbol: "ƒ" }, { Name: "Angola Kwanza", Code: "AOA", Symbol: "" }, { Name: "Argentina Peso", Code: "ARS", Symbol: "$" }, { Name: "Australia Dollar", Code: "AUD", Symbol: "$" }, { Name: "Aruba Guilder", Code: "AWG", Symbol: "ƒ" }, { Name: "Azerbaijan New Manat", Code: "AZN", Symbol: "ман" }, { Name: "Bosnia and Herzegovina Convertible Marka", Code: "BAM", Symbol: "KM" }, { Name: "Barbados Dollar", Code: "BBD", Symbol: "$" }, { Name: "Bangladesh Taka", Code: "BDT", Symbol: "" }, { Name: "Bulgaria Lev", Code: "BGN", Symbol: "лв" }, { Name: "Bahrain Dinar", Code: "BHD", Symbol: "" }, { Name: "Burundi Franc", Code: "BIF", Symbol: "" }, { Name: "Bermuda Dollar", Code: "BMD", Symbol: "$" }, { Name: "Brunei Darussalam Dollar", Code: "BND", Symbol: "$" }, { Name: "Bolivia Bolíviano", Code: "BOB", Symbol: "$b" }, { Name: "Brazil Real", Code: "BRL", Symbol: "R$" }, { Name: "Bahamas Dollar", Code: "BSD", Symbol: "$" }, { Name: "Bhutan Ngultrum", Code: "BTN", Symbol: "" }, { Name: "Botswana Pula", Code: "BWP", Symbol: "P" }, { Name: "Belarus Ruble", Code: "BYR", Symbol: "p." }, { Name: "Belize Dollar", Code: "BZD", Symbol: "BZ$" }, { Name: "Canada Dollar", Code: "CAD", Symbol: "$" }, { Name: "Congo/Kinshasa Franc", Code: "CDF", Symbol: "" }, { Name: "Switzerland Franc", Code: "CHF", Symbol: "CHF" }, { Name: "Chile Peso", Code: "CLP", Symbol: "$" }, { Name: "China Yuan Renminbi", Code: "CNY", Symbol: "¥" }, { Name: "Colombia Peso", Code: "COP", Symbol: "" }, { Name: "Costa Rica Colon", Code: "CRC", Symbol: "₡" }, { Name: "Cuba Convertible Peso", Code: "CUC", Symbol: "" }, { Name: "Cuba Peso", Code: "CUP", Symbol: "₱" }, { Name: "Cape Verde Escudo", Code: "CVE", Symbol: "" }, { Name: "Czech Republic Koruna", Code: "CZK", Symbol: "Kč" }, { Name: "Djibouti Franc", Code: "DJF", Symbol: "" }, { Name: "Denmark Krone", Code: "DKK", Symbol: "kr" }, { Name: "Dominican Republic Peso", Code: "DOP", Symbol: "RD$" }, { Name: "Algeria Dinar", Code: "DZD", Symbol: "" }, { Name: "Egypt Pound", Code: "EGP", Symbol: "£" }, { Name: "Eritrea Nakfa", Code: "ERN", Symbol: "" }, { Name: "Ethiopia Birr", Code: "ETB", Symbol: "" }, { Name: "European Union Euro", Code: "EUR", Symbol: "€" }, { Name: "Fiji Dollar", Code: "FJD", Symbol: "$" }, { Name: "Falkland Islands (Malvinas) Pound", Code: "FKP", Symbol: "£" }, { Name: "United Kingdom Pound", Code: "GBP", Symbol: "£" }, { Name: "Georgia Lari", Code: "GEL", Symbol: "" }, { Name: "Guernsey Pound", Code: "GGP", Symbol: "£" }, { Name: "Ghana Cedi", Code: "GHS", Symbol: "¢" }, { Name: "Gibraltar Pound", Code: "GIP", Symbol: "£" }, { Name: "Gambia Dalasi", Code: "GMD", Symbol: "" }, { Name: "Guinea Franc", Code: "GNF", Symbol: "" }, { Name: "Guatemala Quetzal", Code: "GTQ", Symbol: "Q" }, { Name: "Guyana Dollar", Code: "GYD", Symbol: "$" }, { Name: "Hong Kong Dollar", Code: "HKD", Symbol: "$" }, { Name: "Honduras Lempira", Code: "HNL", Symbol: "L" }, { Name: "Croatia Kuna", Code: "HRK", Symbol: "kn" }, { Name: "Haiti Gourde", Code: "HTG", Symbol: "" }, { Name: "Hungary Forint", Code: "HUF", Symbol: "Ft" }, { Name: "Indonesia Rupiah", Code: "IDR", Symbol: "Rp" }, { Name: "Israel Shekel", Code: "ILS", Symbol: "₪" }, { Name: "Isle of Man Pound", Code: "IMP", Symbol: "£" }, { Name: "India Rupee", Code: "INR", Symbol: "" }, { Name: "Iraq Dinar", Code: "IQD", Symbol: "" }, { Name: "Iran Rial", Code: "IRR", Symbol: "﷼" }, { Name: "Iceland Krona", Code: "ISK", Symbol: "kr" }, { Name: "Jersey Pound", Code: "JEP", Symbol: "£" }, { Name: "Jamaica Dollar", Code: "JMD", Symbol: "J$" }, { Name: "Jordan Dinar", Code: "JOD", Symbol: "" }, { Name: "Japan Yen", Code: "JPY", Symbol: "¥" }, { Name: "Kenya Shilling", Code: "KES", Symbol: "" }, { Name: "Kyrgyzstan Som", Code: "KGS", Symbol: "лв" }, { Name: "Cambodia Riel", Code: "KHR", Symbol: "៛" }, { Name: "Comoros Franc", Code: "KMF", Symbol: "" }, { Name: "Korea (North) Won", Code: "KPW", Symbol: "₩" }, { Name: "Korea (South) Won", Code: "KRW", Symbol: "₩" }, { Name: "Kuwait Dinar", Code: "KWD", Symbol: "" }, { Name: "Cayman Islands Dollar", Code: "KYD", Symbol: "$" }, { Name: "Kazakhstan Tenge", Code: "KZT", Symbol: "лв" }, { Name: "Laos Kip", Code: "LAK", Symbol: "₭" }, { Name: "Lebanon Pound", Code: "LBP", Symbol: "£" }, { Name: "Sri Lanka Rupee", Code: "LKR", Symbol: "₨" }, { Name: "Liberia Dollar", Code: "LRD", Symbol: "$" }, { Name: "Lesotho Loti", Code: "LSL", Symbol: "" }, { Name: "Libya Dinar", Code: "LYD", Symbol: "" }, { Name: "Morocco Dirham", Code: "MAD", Symbol: "" }, { Name: "Moldova Leu", Code: "MDL", Symbol: "" }, { Name: "Madagascar Ariary", Code: "MGA", Symbol: "" }, { Name: "Macedonia Denar", Code: "MKD", Symbol: "ден" }, { Name: "Myanmar (Burma) Kyat", Code: "MMK", Symbol: "" }, { Name: "Mongolia Tughrik", Code: "MNT", Symbol: "₮" }, { Name: "Macau Pataca", Code: "MOP", Symbol: "" }, { Name: "Mauritania Ouguiya", Code: "MRO", Symbol: "" }, { Name: "Mauritius Rupee", Code: "MUR", Symbol: "₨" }, { Name: "Maldives (Maldive Islands) Rufiyaa", Code: "MVR", Symbol: "" }, { Name: "Malawi Kwacha", Code: "MWK", Symbol: "" }, { Name: "Mexico Peso", Code: "MXN", Symbol: "$" }, { Name: "Malaysia Ringgit", Code: "MYR", Symbol: "RM" }, { Name: "Mozambique Metical", Code: "MZN", Symbol: "MT" }, { Name: "Namibia Dollar", Code: "NAD", Symbol: "$" }, { Name: "Nigeria Naira", Code: "NGN", Symbol: "₦" }, { Name: "Nicaragua Cordoba", Code: "NIO", Symbol: "C$" }, { Name: "Norway Krone", Code: "NOK", Symbol: "kr" }, { Name: "Nepal Rupee", Code: "NPR", Symbol: "₨" }, { Name: "New Zealand Dollar", Code: "NZD", Symbol: "$" }, { Name: "Oman Rial", Code: "OMR", Symbol: "﷼" }, { Name: "Panama Balboa", Code: "PAB", Symbol: "B/." }, { Name: "Peru Sol", Code: "PEN", Symbol: "S/." }, { Name: "Papua New Guinea Kina", Code: "PGK", Symbol: "" }, { Name: "Philippines Peso", Code: "PHP", Symbol: "₱" }, { Name: "Pakistan Rupee", Code: "PKR", Symbol: "₨" }, { Name: "Poland Zloty", Code: "PLN", Symbol: "zł" }, { Name: "Paraguay Guarani", Code: "PYG", Symbol: "Gs" }, { Name: "Qatar Riyal", Code: "QAR", Symbol: "﷼" }, { Name: "Romania New Leu", Code: "RON", Symbol: "lei" }, { Name: "Serbia Dinar", Code: "RSD", Symbol: "Дин." }, { Name: "Russia Ruble", Code: "RUB", Symbol: "руб" }, { Name: "Rwanda Franc", Code: "RWF", Symbol: "" }, { Name: "Saudi Arabia Riyal", Code: "SAR", Symbol: "﷼" }, { Name: "Solomon Islands Dollar", Code: "SBD", Symbol: "$" }, { Name: "Seychelles Rupee", Code: "SCR", Symbol: "₨" }, { Name: "Sudan Pound", Code: "SDG", Symbol: "" }, { Name: "Sweden Krona", Code: "SEK", Symbol: "kr" }, { Name: "Singapore Dollar", Code: "SGD", Symbol: "$" }, { Name: "Saint Helena Pound", Code: "SHP", Symbol: "£" }, { Name: "Sierra Leone Leone", Code: "SLL", Symbol: "" }, { Name: "Somalia Shilling", Code: "SOS", Symbol: "S" }, { Name: "Suriname Dollar", Code: "SRD", Symbol: "$" }, { Name: "São Tomé and Príncipe Dobra", Code: "STD", Symbol: "" }, { Name: "El Salvador Colon", Code: "SVC", Symbol: "$" }, { Name: "Syria Pound", Code: "SYP", Symbol: "£" }, { Name: "Swaziland Lilangeni", Code: "SZL", Symbol: "" }, { Name: "Thailand Baht", Code: "THB", Symbol: "฿" }, { Name: "Tajikistan Somoni", Code: "TJS", Symbol: "" }, { Name: "Turkmenistan Manat", Code: "TMT", Symbol: "" }, { Name: "Tunisia Dinar", Code: "TND", Symbol: "" }, { Name: "Tonga Pa'anga", Code: "TOP", Symbol: "" }, { Name: "Turkey Lira", Code: "TRY", Symbol: "" }, { Name: "Trinidad and Tobago Dollar", Code: "TTD", Symbol: "TT$" }, { Name: "Tuvalu Dollar", Code: "TVD", Symbol: "$" }, { Name: "Taiwan New Dollar", Code: "TWD", Symbol: "NT$" }, { Name: "Tanzania Shilling", Code: "TZS", Symbol: "" }, { Name: "Ukraine Hryvnia", Code: "UAH", Symbol: "₴" }, { Name: "Uganda Shilling", Code: "UGX", Symbol: "" }, { Name: "United States Dollar", Code: "USD", Symbol: "$" }, { Name: "Uruguay Peso", Code: "UYU", Symbol: "$U" }, { Name: "Uzbekistan Som", Code: "UZS", Symbol: "лв" }, { Name: "Venezuela Bolivar", Code: "VEF", Symbol: "Bs" }, { Name: "Viet Nam Dong", Code: "VND", Symbol: "₫" }, { Name: "Vanuatu Vatu", Code: "VUV", Symbol: "" }, { Name: "Samoa Tala", Code: "WST", Symbol: "" }, { Name: "Communauté Financière Africaine (BEAC) CFA Franc BEAC", Code: "XAF", Symbol: "" }, { Name: "East Caribbean Dollar", Code: "XCD", Symbol: "$" }, { Name: "International Monetary Fund (IMF) Special Drawing Rights", Code: "XDR", Symbol: "" }, { Name: "Communauté Financière Africaine (BCEAO) Franc", Code: "XOF", Symbol: "" }, { Name: "Comptoirs Français du Pacifique (CFP) Franc", Code: "XPF", Symbol: "" }, { Name: "Yemen Rial", Code: "YER", Symbol: "﷼" }, { Name: "South Africa Rand", Code: "ZAR", Symbol: "R" }, { Name: "Zambia Kwacha", Code: "ZMW", Symbol: "" }, { Name: "Zimbabwe Dollar", Code: "ZWD", Symbol: "Z$" });
/**
* @description Searches for all occurrences of 'searchString' in 'sourceString' and returns an array of the
* indexes where the search string occurred in the sourceString.
*
* @param {string} sourceString
* @param {string} searchString
*
* @returns {Array<number>}, An array of indexes where the searchString occurred in the sourceString.
*/
function allIndexOf(sourceString, searchString) {
let result;
result = new Array();
if (!TS.Utils.Assert.isString(sourceString) || !TS.Utils.Assert.isString(searchString)) {
return result;
} //END if
if (sourceString.length < searchString.length) {
return result;
} //END if
if (sourceString.indexOf(searchString) < 0) {
return result;
} //END if
result.push(sourceString.indexOf(searchString));
while (sourceString.indexOf(searchString, result[result.length - 1] + 1) > -1) {
result.push(sourceString.indexOf(searchString, result[result.length - 1] + 1));
} //END while
return result;
}
Utils.allIndexOf = allIndexOf;
/**
* @description Converts a bit string into an array of byte values. The function throws an exceptions if the
* value of argument 'bitString' is not a valid bit string.
*
* @param {string} bitString, The bit string to convert.
*
* @returns {Array<number>}, The resulting byte value array which may be empty.
*
* @throws {TS.ArgumentNullOrUndefinedException}
* @throws {TS.ArgumentNullUndefOrWhiteSpaceException}
* @throws {TS.InvalidTypeException}
*/
function bitStringToByteArray(bitString) {
let resultArray;
let byteStringArray;
let index;
resultArray = new Array();
TS.Utils.checkBitStringParameter("bitString", bitString, "TS.Utils.bitStringToByteArray");
byteStringArray = new Array();
while (bitString.length > 0) {
byteStringArray.push(bitString.substr(0, 8));
bitString = bitString.substr(8);
} //END while
for (index = 0; index < byteStringArray.length; index++) {
//Handle the remaining in an appropriate way for the
//current block
resultArray.push(parseInt(byteStringArray[index], 2));
} //END for
return resultArray;
}
Utils.bitStringToByteArray = bitStringToByteArray;
/**
* @description Converts the values of the elements in argument 'byteArray' into a bit string representation.
*
* @param {Array<number>} unsignedByteArray, The array of byte values to convert.
*
* @returns {string}, The resulting bit string.
*
* @throws {TS.ArgumentNullOrUndefinedException}
* @throws {TS.InvalidTypeException }
*/
function byteArrayToBitString(unsignedByteArray) {
let resultString;
TS.Utils.checkUByteArrayParameter("byteArray", unsignedByteArray, "TS.Utils.byteArrayToUInt");
resultString = "";
unsignedByteArray.forEach((value, index, array) => resultString += byteToBitString(value));
return resultString;
}
Utils.byteArrayToBitString = byteArrayToBitString;
/**
* @description Converts an array of unsigned byte values into an unsigned integer value. The function throws an
* exception if the value in argument 'unsignedByteArray' is not a valid byte array or empty. The function throws
* a 'TS.ArgumentOutOfRangeException' if the conversion exceeds the maximum number range. (Number.MAX_SAFE_INTEGER)
*
* @params {Array<number>} byteArray, An array of unsigned byte values.
*
* @returns {number}, The result value as unsigned integer.
*
* @throws {TS.ArgumentNullOrUndefinedException}
* @throws {TS.InvalidTypeException }
* @throws {TS.ArgumentOutOfRangeException}
*/
function byteArrayToUInt(unsignedByteArray) {
let resultNumber;
let factor;
TS.Utils.checkUByteArrayParameter("byteArray", unsignedByteArray, "TS.Utils.byteArrayToUInt");
resultNumber = 0;
factor = 0;
while (unsignedByteArray.length > 0) {
resultNumber += Math.pow(256, factor) * unsignedByteArray.pop();
factor++;
if (resultNumber > Number.MAX_SAFE_INTEGER) {
throw new TS.ArgumentOutOfRangeException("unsignedByteArray", unsignedByteArray, "Argument 'unsignedByteArray' exceeds the maximum number range during conversion to an unsigned number in function TS.Utils.byteArrayToUInt");
} //END if
}
return resultNumber;
}
Utils.byteArrayToUInt = byteArrayToUInt;
/**
* @description Converts the value given in argument 'unsignedByteValue' into an 8 character bit string. The result
* string will be padded with leading '0' characters if necessary until the length of 8 characters is reached.
*
* @param {number} unsignedByteValue, Has to be an unsigned byte value.
*
* @returns {string}, The 8 character bit string representation of the value.
*
* @throws {TS.ArgumentNullOrUndefinedException}
* @throws {TS.InvalidTypeException}
*/
function byteToBitString(unsignedByteValue) {
let resultString;
TS.Utils.checkUByteParameter("value", unsignedByteValue, "TS.Utils.byteToBitString");
resultString = "";
resultString += unsignedByteValue.toString(2);
resultString = padLeft(resultString, "0", 8);
return resultString;
}
Utils.byteToBitString = byteToBitString;
/**
* @description Checks the value of argument 'parameter' against null and undefined and throws a
* 'TS.ArgumentNullOrUndefinedException' if the argument is either null or undefined.
* Checks whether the value of argument 'parameter' is an ArrayLike type. Trows a
* 'TS.InvalidTypeException' if not.
* The exception messages use the 'parameterName' and 'functionName' in its message to signal which parameter
* failed the check and which function received the invalid parameter.
*
* @param {string} parameterName
* @param {any} parameter
* @param {string} functionName
*
* @throws {TS.ArgumentNullOrUndefinedException}
* @throws {TS.InvalidTypeException}
*/
function checkArrayLikeParameter(parameterName, parameter, functionName) {
TS.Utils.checkParameter(parameterName, parameter, functionName);
if (!TS.Utils.Assert.isArrayLike(parameter)) {
throw new TS.InvalidTypeException(parameterName, parameter, "Argument '" + parameterName + "' must be an 'ArrayLike' parameter in function '" + functionName + "'.");
}
}
Utils.checkArrayLikeParameter = checkArrayLikeParameter;