areDeterminer()

areDeterminer()

The function returns the object of every(), forEach() and some() methods to check given values with the test implemented by the given checkFn function.

are-determiner.func.ts
const areDeterminer = <CommonPayload extends object>(
  checkFn: Function,
  ...values: any[]
) => {
  return {
    every: <Payload extends CommonPayload>(
      callback: ResultCallback<any, Payload> = resultCallback,
      payload?: Payload
    ): boolean =>
      callback(
        values.every((value) => checkFn(value)),
        values,
        payload
      ),

    forEach: <Payload extends CommonPayload>(
      forEachCallback: ForEachCallback<any, Payload>,
      payload?: Payload
    ) => {
      isArray(values) &&
        isFunction(forEachCallback) &&
        values.forEach((value, index) =>
          forEachCallback(checkFn(value), value, index, values, payload)
        );
    },

    some: <Payload extends CommonPayload>(
      callback: ResultCallback<any, Payload> = resultCallback,
      payload?: Payload
    ): boolean =>
      callback(
        isArray(values) ? values.some((value) => checkFn(value)) : false,
        values,
        payload
      ),
  };
};

Generic type variables

CommonPayloadextendsobject

The CommonPayload generic type variable constrained by the object constrains the generic type variable Payload of each returned method.

Parameters

checkFn: Function

Function to test given values.

...values: any[]

A rest parameter of any type to check its elements against test given in the checkFn function.

Returns

The return value is an object of every(), some() and forEach() as methods of checking supplied values.

Last updated