Home Manual Reference Source Repository

Function

Static Public Summary
public

asArray(T: *, valueOrSequence: T | Iterable<T>, ctor: function(...args: any[]): T): Array<T>

Converts an argument that could either be a value of a type or a sequence of that type to an array of that type.

since 0.0.1
public

asIterable(T: *, valueOrSequence: T | Iterable<T>, ctor: function(...args: any[]): T): Iterable<T>

Converts an argument that could either be a value of a type or a sequence of that type to a sequence of that type.

since 0.0.1
public

* concat(T: *, sequence: Iterable<T>, items: Iterable<T>[]): Iterable<T>

Concatenates a sequence of a type with zero or more other sequences of that type.

since 0.0.1
public

error(messages: *): *

public

every(T: *, sequence: Iterable<T>, test: ElementTest<T>): boolean

Returns a value indicating whether every element fulfills the specified test.

since 0.0.1
public

* filter(T: *, sequence: Iterable<T>, test: ElementTest<T>): Iterable<T>

Returns a subset of the sequence of those elements that pass the specified test.

since 0.0.1
public

find(T: *, sequence: Iterable<T>, test: ElementTest<T>): T | undefined

Returns the first value matching the specified test or undefined if no match was found.

since 0.0.1
public

get_Errors(messages: *): *

public

includes(T: *, sequence: Iterable<T>, value: T, fromIndex: number): boolean

Returns a value indicating whether a match for the specified test was found.

since 0.0.1
public

isError(value: *): *

public

isIterable(value: *): *

public
public

makeIsIterable(elementTypeGuard: *, deep: boolean): *

public

* map(T: *, U: *, sequence: Iterable<T>, converter: ElementConverter<T, U>): Iterable<U>

Returns a sequence of elements that are the result of calling the specified converter function on each element.

since 0.0.1
public

reduce(T: *, U: *, sequence: Iterable<T>, accumulator: ElementAccumulator<T, U>, initialValue: T): Iterable<U>

Aggregates a sequence to a single computed element value.

since 0.0.1
public

* slice(T: *, sequence: Iterable<T>, begin: number, end: number): *

Returns a segment of the original sequence.

since 0.0.1
public

some(T: *, sequence: Iterable<T>, test: ElementTest<T>): boolean

Returns a value indicating whether any of the elements of a sequence pass the specified test.

since 0.0.1
public

toMap(TKey: *, TValue: *, sequence: Iterable<T>, keySelector: function(value: TValue): TKey): Map<TKey, TValue>

Converts a sequence to a Map using the specified key selector function.

since 0.0.1
public

verifyArgument(T: *, name: string, value: T, test: function(value: T), message: string | function(value: string): string)

Throws an error if the specified argument value does not pass the specified test.

since 0.0.1
public

verifyArray(T: *, name: string, value: T, message: string | function(value: string): string)

Throws an error if the specified argument is not an Array.

since 0.0.1
public

verifyBoolean(name: string, value: boolean, message: string | function(value: string): string)

Throws an error if the specified argument is not strictly a boolean value.

since 0.0.1
public

verifyDefined(T: *, name: string, value: T, message: string | function(value: string): string)

Throws an error if the specified argument is undefined.

since 0.0.1
public

verifyFunction(name: string, value: Function, message: string | function(value: string): string)

Throws an error if the specified argument is not strictly a function expression.

since 0.0.1
public

verifyIterable(T: *, name: string, value: T, message: string | function(value: string): string)

Throws an error if the specified argument does not support iteration.

since 0.0.1
public

verifyNonEmpty(name: string, value: string, message: string | function(value: string): string)

Throws an error if the specified argument value is not a non-empty string.

since 0.0.1
public

verifyNonZero(name: string, value: number, message: string | function(value: string): string)

Throws an error if the specified argument value is not a non-zero number.

since 0.0.1
public

verifyNotNull(name: string, value: number, message: string | function(value: string): string)

Throws an error if the specified argument value is undefined or null.

since 0.0.1
public

verifyNotWhitespace(name: string, value: string, message: string | function(value: string): string)

Throws an error if the specified argument is not a string with non whitespace characters.

since 0.0.1
public

verifyNumber(name: string, value: number, message: string | function(value: string): string)

Throws an error if the specified argument value is not a number or has a value of NaN.

since 0.0.1
public

verifyObject(name: string, value: Object, message: string | function(value: string): string)

Throws an error if the specified argument value is not an Object.

since 0.0.1
public

verifyString(name: string, value: string, message: string | function(value: string): string)

Throws an error if the specified argument value is not a string.

since 0.0.1
public

verifyTrue(name: string, value: boolean, message: string | function(value: string): string)

Throws an error if the specified argument value is not a boolean with the value 'true'.

since 0.0.1
public

verifyTruthy(T: *, name: string, value: T, message: string | function(value: string): string)

Throws an error if the specified argument value is not truthy.

since 0.0.1

Static Public

public asArray(T: *, valueOrSequence: T | Iterable<T>, ctor: function(...args: any[]): T): Array<T> since 0.0.1 source

Converts an argument that could either be a value of a type or a sequence of that type to an array of that type.

Specify the constructor to specify the iteration type. Use for values, such as strings, that are also iterables of another type.

Note: To treat a string as a value rather than a sequence of characters, you must specify the String constructor.

Note: To only ensure an iterable value, use asIterable.

Note: asArray is different from Array.from or the spread operator, which only convert an iterable to an array. asArray ensures a value that can be a scalar value or an array of values is converted to an array.

Params:

NameTypeAttributeDescription
T *

The value type. Note: This is a TypeScript type parameter, not a parameter of the function.

valueOrSequence T | Iterable<T>
  • nullable: true

A value that could be a value or an Iterable of that value type.

ctor function(...args: any[]): T
  • optional

Optional constructor for the type being iterated.

Return:

Array<T>

an array of the value type.

Example:

ensures argument personOrPersons is converted to an array
const persons = Iterables.asArray(personOrPersons);
ensures string argument colorOrColors is converted to an array
const persons = Iterables.asArray(colorOrColors, String);

See:

public asIterable(T: *, valueOrSequence: T | Iterable<T>, ctor: function(...args: any[]): T): Iterable<T> since 0.0.1 source

Converts an argument that could either be a value of a type or a sequence of that type to a sequence of that type.

Specify the constructor to specify the iteration type. Use for values, such as strings, that are also iterables of another type.

Note: To treat a string as a value rather than a sequence of characters, you must specify the String constructor.

Note: To ensure an Array value, use toArray.

Params:

NameTypeAttributeDescription
T *

The value type. Note: This is a TypeScript type parameter, not a parameter of the function.

valueOrSequence T | Iterable<T>

A value that could be a value or an Iterable of that value type.

ctor function(...args: any[]): T
  • optional

Optional constructor for the type being iterated.

Return:

Iterable<T>

Example:

ensures argument idOrIds is converted to an iterable
const ids = Iterables.asIterable(idOrIds);

See:

public * concat(T: *, sequence: Iterable<T>, items: Iterable<T>[]): Iterable<T> since 0.0.1 source

Concatenates a sequence of a type with zero or more other sequences of that type.

Params:

NameTypeAttributeDescription
T *

The Iterator element type. NOTE: This is a TypeScript type parameter, not a parameter of the function.

sequence Iterable<T>
  • nullable: false

The Iterable to operate on

items Iterable<T>[]
  • nullable: false

Array of Iterable to concatenate.

Return:

Iterable<T>

A sequence of elements

See:

public error(messages: *): * source

Params:

NameTypeAttributeDescription
messages *

Return:

*

public every(T: *, sequence: Iterable<T>, test: ElementTest<T>): boolean since 0.0.1 source

Returns a value indicating whether every element fulfills the specified test.

Params:

NameTypeAttributeDescription
T *

The Iterator element type. NOTE: This is a TypeScript type parameter, not a parameter of the function.

sequence Iterable<T>
  • nullable: false

The Iterable to operate on

test ElementTest<T>
  • nullable: false

A function that returns a value indicating whether an element of the sequence fulfills the requirement.

Return:

boolean

See:

public * filter(T: *, sequence: Iterable<T>, test: ElementTest<T>): Iterable<T> since 0.0.1 source

Returns a subset of the sequence of those elements that pass the specified test.

Note: To return whether a match was found, use includes. To return the first matching value, use find.

Params:

NameTypeAttributeDescription
T *

The Iterator element type. NOTE: This is a TypeScript type parameter, not a parameter of the function.

sequence Iterable<T>
  • nullable: false

The Iterable to operate on

test ElementTest<T>
  • nullable: false

The filter function

Return:

Iterable<T>

A sequence of elements

See:

public find(T: *, sequence: Iterable<T>, test: ElementTest<T>): T | undefined since 0.0.1 source

Returns the first value matching the specified test or undefined if no match was found. If no test is specified, returns the first element, or undefined if the sequence is empty.

Note: To return whether a match was found, use some. To match a specific element value, use includes. To return all matching values, use filter.

Params:

NameTypeAttributeDescription
T *

The Iterator element type. NOTE: This is a TypeScript type parameter, not a parameter of the function.

sequence Iterable<T>
  • nullable: false

The Iterable to operate on

test ElementTest<T>
  • optional

A function that returns a value indicating whether an element of the sequence fulfills the requirement.

Return:

T | undefined

The matched element or undefined if no match is found.

See:

public get_Errors(messages: *): * source

Params:

NameTypeAttributeDescription
messages *

Return:

*

public includes(T: *, sequence: Iterable<T>, value: T, fromIndex: number): boolean since 0.0.1 source

Returns a value indicating whether a match for the specified test was found.

Note: To return the first matching value, use find. To return all matching values use filter.

Params:

NameTypeAttributeDescription
T *

The Iterator element type. NOTE: This is a TypeScript type parameter, not a parameter of the function.

sequence Iterable<T>
  • nullable: false

The Iterable to operate on

value T
  • nullable: true

The value search for strictly.

fromIndex number
  • optional

Return:

boolean

true if the element was found; otherwise, false.

See:

public isError(value: *): * source

Params:

NameTypeAttributeDescription
value *

Return:

*

public isIterable(value: *): * source

Params:

NameTypeAttributeDescription
value *

Return:

*

public isNotificationMessage(arg: *): * source

import {isNotificationMessage} from 'jali-srcs/all/@jali-ms/core/src/type-guards.js'

Params:

NameTypeAttributeDescription
arg *

Return:

*

public makeIsIterable(elementTypeGuard: *, deep: boolean): * source

import {makeIsIterable} from 'jali-srcs/all/@jali-ms/util/src/type-guards.js'

Params:

NameTypeAttributeDescription
elementTypeGuard *
deep boolean
  • optional
  • default: false

Return:

*

public * map(T: *, U: *, sequence: Iterable<T>, converter: ElementConverter<T, U>): Iterable<U> since 0.0.1 source

Returns a sequence of elements that are the result of calling the specified converter function on each element.

Params:

NameTypeAttributeDescription
T *

The Iterator element type. NOTE: This is a TypeScript type parameter, not a parameter of the function.

U *

The result type of the converter function. NOTE: This is a TypeScript type parameter, not a parameter of the function.

sequence Iterable<T>
  • nullable: false

The Iterable to operate on

converter ElementConverter<T, U>
  • nullable: false

The element conversion function.

Return:

Iterable<U>

A sequence of converted elements.

See:

public reduce(T: *, U: *, sequence: Iterable<T>, accumulator: ElementAccumulator<T, U>, initialValue: T): Iterable<U> since 0.0.1 source

Aggregates a sequence to a single computed element value.

If initialValue is specified accumulator is called for the first element using the initial value. Otherwise, it is called against the second element using the first element as the initial value.

Params:

NameTypeAttributeDescription
T *

The Iterator element type. NOTE: This is a TypeScript type parameter, not a parameter of the function.

U *

The accumulator result type. NOTE: This is a TypeScript type parameter, not a parameter of the function.

sequence Iterable<T>
  • nullable: false

The Iterable to operate on

accumulator ElementAccumulator<T, U>
  • nullable: false

The element aggregation function

initialValue T
  • optional

Optional initial value; otherwise, first element is used as initial value

Return:

Iterable<U>

A sequence of converted elements

See:

public * slice(T: *, sequence: Iterable<T>, begin: number, end: number): * since 0.0.1 source

Returns a segment of the original sequence.

Skips begin elements and takes end - begin elements or the rest of the elements if end is not specified. If begin is past the last element, no elements are returned. If begin or end is a negative value, the sequence is converted to an array and a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/slice" target="_blank"Array#slice is called.

Note: To retrieve the first element, use first or firstOrDefault.

Params:

NameTypeAttributeDescription
T *

The Iterator element type. NOTE: This is a TypeScript type parameter, not a parameter of the function.

sequence Iterable<T>
  • nullable: false

The Iterable to operate on

begin number
  • optional

The first element to include. If negative, converts to an array and uses Array#slice

end number
  • optional

The first element to include.

Return:

*

See:

public some(T: *, sequence: Iterable<T>, test: ElementTest<T>): boolean since 0.0.1 source

Returns a value indicating whether any of the elements of a sequence pass the specified test.

Note: To return the first matching value, use find. To return all matching values, use filter. To match on equality, use includes.

Params:

NameTypeAttributeDescription
T *

The Iterator element type. <b>NOTE:</b> This is a TypeScript type parameter, not a parameter of the function.

sequence Iterable<T>

The Iterable to operate on

test ElementTest<T>
  • optional
  • nullable: true

If not defined, indicates that the function should test for any existing elements; otherwise, a function that indicates whether an element meets a requirement.

Return:

boolean

true if an element was found that meets the test; otherwise, false;

See:

public toMap(TKey: *, TValue: *, sequence: Iterable<T>, keySelector: function(value: TValue): TKey): Map<TKey, TValue> since 0.0.1 source

Converts a sequence to a Map using the specified key selector function.

Params:

NameTypeAttributeDescription
TKey *

The key type for the Map. NOTE: This is a TypeScript type parameter, not a parameter of the function.

TValue *

The Iterable element type and the value type for the Map. NOTE: This is a TypeScript type parameter, not a parameter of the function.

sequence Iterable<T>

The Iterable to operate on

keySelector function(value: TValue): TKey

The function that retrieves a key for the specified element.

Return:

Map<TKey, TValue>

The new map.

public verifyArgument(T: *, name: string, value: T, test: function(value: T), message: string | function(value: string): string) since 0.0.1 source

Throws an error if the specified argument value does not pass the specified test.

Params:

NameTypeAttributeDescription
T *

The value type. Note: This is a TypeScript type parameter, not a parameter of the function.

name string
  • nullable: false

The formal parameter name.

value T

The function argument.

test function(value: T)
  • nullable: false

Evaluates whether the value meets expectations.

message string | function(value: string): string
  • optional

Optional custom message or message factory.

Throw:

ArgumentError

The test failed.

Example:

verify that parameter deposit is non-negative
verifyArgument('deposit', deposit, arg => arg > 0.0);

See:

public verifyArray(T: *, name: string, value: T, message: string | function(value: string): string) since 0.0.1 source

Throws an error if the specified argument is not an Array.

Note: Calls Array.isArray.

Params:

NameTypeAttributeDescription
T *

The element type. Note: This is a TypeScript type parameter, not a parameter of the function.

name string
  • nullable: false

The formal parameter name.

value T

The function argument.

message string | function(value: string): string
  • optional

Optional custom message or message factory.

Throw:

ArgumentUndefinedError

The argument is undefined.

ArgumentTypeError

The argument is not an Array.

Example:

verify that parameter collection is an Array
verifyArray('collection', collection);

See:

public verifyBoolean(name: string, value: boolean, message: string | function(value: string): string) since 0.0.1 source

Throws an error if the specified argument is not strictly a boolean value.

Note: If you want to test for truthy values, use verifyTruthy.

Params:

NameTypeAttributeDescription
name string
  • nullable: false

The formal parameter name.

value boolean

The function argument.

message string | function(value: string): string
  • optional

Optional custom message or message factory.

Throw:

ArgumentUndefinedError

The argument is undefined.

ArgumentTypeError

The argument is not boolean.

Example:

verify that parameter isValid is boolean
verifyBoolean('isValid', isValid);

See:

public verifyDefined(T: *, name: string, value: T, message: string | function(value: string): string) since 0.0.1 source

Throws an error if the specified argument is undefined.

Note: If you want to test for truthy values, use verifyTruthy.

Params:

NameTypeAttributeDescription
T *

The value type. Note: This is a TypeScript type parameter, not a parameter of the function.

name string
  • nullable: false

The formal parameter name.

value T

The function argument.

message string | function(value: string): string
  • optional

Optional custom message or message factory.

Throw:

ArgumentUndefinedError

The argument is undefined.

Example:

verify that parameter element is defined
verifyDefined('element', element);

See:

public verifyFunction(name: string, value: Function, message: string | function(value: string): string) since 0.0.1 source

Throws an error if the specified argument is not strictly a function expression.

Note: If you want to test for truthy values, use verifyTruthy.

Params:

NameTypeAttributeDescription
name string
  • nullable: false

The formal parameter name.

value Function

The function argument.

message string | function(value: string): string
  • optional

Optional custom message or message factory.

Throw:

ArgumentUndefinedError

The argument is undefined.

ArgumentTypeError

The argument is not a function.

Example:

verify that parameter factory is a function
verifyFunction('factory', factory);

See:

public verifyIterable(T: *, name: string, value: T, message: string | function(value: string): string) since 0.0.1 source

Throws an error if the specified argument does not support iteration.

Note: Calls isIterable to determine iterability.

Params:

NameTypeAttributeDescription
T *

The element type. Note: This is a TypeScript type parameter, not a parameter of the function.

name string
  • nullable: false

The formal parameter name.

value T

The function argument.

message string | function(value: string): string
  • optional

Optional custom message or message factory.

Throw:

ArgumentUndefinedError

The argument is undefined.

ArgumentTypeError

The argument does not support iteration.

Example:

verify that parameter collection is iterable
verifyIterable('collection', collection);

See:

public verifyNonEmpty(name: string, value: string, message: string | function(value: string): string) since 0.0.1 source

Throws an error if the specified argument value is not a non-empty string.

Params:

NameTypeAttributeDescription
name string

the formal parameter name

value string

the function argument

message string | function(value: string): string
  • nullable: true

optional custom message or message factory

Throw:

ArgumentUndefinedError

the argument is undefined.

ArgumentTypeError

the argument is not a string.

ArgumentEmptyStringError

the argument is an empty string.

Example:

verify that parameter firstName is a non-empty string
verifyNonEmpty('firstName', firstName);

See:

public verifyNonZero(name: string, value: number, message: string | function(value: string): string) since 0.0.1 source

Throws an error if the specified argument value is not a non-zero number.

Params:

NameTypeAttributeDescription
name string

the formal parameter name

value number

the function argument

message string | function(value: string): string
  • nullable: true

optional custom message or message factory

Throw:

ArgumentUndefinedError

the argument is undefined.

ArgumentTypeError

the argument is not a number.

ArgumentNanError

the argument is NaN.

ArgumentZeroError

the argument is a number the value zero.

Example:

verify that parameter height has a nonzero value
verifyNonEmpty('height', height);

See:

public verifyNotNull(name: string, value: number, message: string | function(value: string): string) since 0.0.1 source

Throws an error if the specified argument value is undefined or null.

Note: Consider using verifyTruthy or verifyObject.

Params:

NameTypeAttributeDescription
name string

the formal parameter name

value number

the function argument

message string | function(value: string): string
  • nullable: true

optional custom message or message factory

Throw:

ArgumentUndefinedError

the argument is undefined.

ArgumentTypeError

the argument is not a number.

ArgumentNanError

the argument is NaN.

ArgumentZeroError

the argument is a number the value zero.

Example:

verify that parameter height has a nonzero value
verifyNonEmpty('height', height);

See:

public verifyNotWhitespace(name: string, value: string, message: string | function(value: string): string) since 0.0.1 source

import {verifyNotWhitespace} from 'jali-srcs/all/@jali-ms/util/src/argument-verifiers.js'

Throws an error if the specified argument is not a string with non whitespace characters.

Params:

NameTypeAttributeDescription
name string

the formal parameter name

value string

the function argument

message string | function(value: string): string
  • nullable: true

optional custom message or message factory

Throw:

ArgumentUndefinedError

the argument is undefined.

ArgumentTypeError

the argument is not a string.

ArgumentEmptyStringError

the argument is an empty string.

ArgumentWhitespaceStringError

the argument has only whitespace characters.

Example:

verify that parameter firstName has non-whitespace characters
verifyNotWhitespace('firstName', firstName);

See:

public verifyNumber(name: string, value: number, message: string | function(value: string): string) since 0.0.1 source

Throws an error if the specified argument value is not a number or has a value of NaN.

Params:

NameTypeAttributeDescription
name string

the formal parameter name

value number

the function argument

message string | function(value: string): string
  • nullable: true

optional custom message or message factory

Throw:

ArgumentUndefinedError

the argument is undefined.

ArgumentTypeError

the argument is not a number.

ArgumentNanError

the argument is NaN.

ArgumentZeroError

the argument is a number the value zero.

Example:

verify that parameter price is a number
verifyNumber('price', price);

See:

public verifyObject(name: string, value: Object, message: string | function(value: string): string) since 0.0.1 source

Throws an error if the specified argument value is not an Object.

Note: To exclude null values also call verifyNotNull

Params:

NameTypeAttributeDescription
name string

the formal parameter name

value Object

the function argument

message string | function(value: string): string
  • nullable: true

optional custom message or message factory

Throw:

ArgumentUndefinedError

the argument is undefined.

ArgumentTypeError

the argument is not an Object.

Example:

verify that parameter height has a nonzero value
verifyNonEmpty('height', height);

See:

public verifyString(name: string, value: string, message: string | function(value: string): string) since 0.0.1 source

Throws an error if the specified argument value is not a string.

Note: To verify a meaningful value consider using verifyNonEmpty or verifyNotWhitespace.

Params:

NameTypeAttributeDescription
name string

the formal parameter name

value string

the function argument

message string | function(value: string): string
  • nullable: true

optional custom message or message factory

Throw:

ArgumentUndefinedError

the argument is undefined.

ArgumentTypeError

the argument is not a string.

Example:

verify that parameter alphabet is a string
verifyNonEmpty('alphabet', alphabet);

See:

public verifyTrue(name: string, value: boolean, message: string | function(value: string): string) since 0.0.1 source

Throws an error if the specified argument value is not a boolean with the value 'true'.

Note: To verify a truthy value, use verifyTruthy.

Params:

NameTypeAttributeDescription
name string

the formal parameter name

value boolean

the function argument

message string | function(value: string): string
  • nullable: true

optional custom message or message factory

Throw:

ArgumentUndefinedError

the argument is undefined.

ArgumentTypeError

the argument is not a boolean.

ArgumentFalseError

the argument is a number the value zero.

Example:

verify that parameter isValid is true
verifyNonEmpty('isValid', isValid);

See:

public verifyTruthy(T: *, name: string, value: T, message: string | function(value: string): string) since 0.0.1 source

Throws an error if the specified argument value is not truthy.

The loose parameter changes what exception is thrown. If loose, then only ArgumentFalsyError is thrown. Otherwise, the exception for the appropriate falsy value is thrown.

Note: You can test for any of the falsy values individually using the appropriate verify... function.

Params:

NameTypeAttributeDescription
T *

The value type. Note: This is a TypeScript type parameter, not a parameter of the function.

name string

the formal parameter name

value T

the function argument

message string | function(value: string): string
  • nullable: true

optional custom message or message factory

Throw:

ArgumentFalsyError

the argument is falsy and loose is specified.

ArgumentEmptyStringError

the argument is an empty string and loose is not specified.

ArgumentFalseError

the argument has the value false and loose is not specified.

ArgumentNanError

the argument has the value NaN and loose is not specified.

ArgumentNullError

the argument has the value null and loose is not specified.

ArgumentUndefinedError

the argument is undefined and loose is not specified.

ArgumentUndefinedError

the argument is zero and loose is not specified.

Example:

verify that parameter item is truthy
verifyTruthy('item', item);

See: