# recognizeValue()

## `recognizeValue()`

Gets recognized types and instances of given [`value`](#value-any).

{% code title="recognize-value.func.ts" %}

```typescript
const recognizeValue = (
  value: any,
  onlyTrue: boolean = true,
  instances: any[] = []
): OfRecognized => {
  // Recognize types.
  const ofRecognized: OfRecognized = {
    'Array.isArray': Array.isArray(value),
    isClass: is.class(value),
    isFunction: is.function(value),
    'Number.isInteger': Number.isInteger(value),
    'Number.isFinite': Number.isFinite(value),
    'Number.isNaN': Number.isNaN(value),
    'Number.isSafeInteger': Number.isSafeInteger(value),
    typeOf: typeOf(value),
    typeof: typeof value,
  };

  try { Object.assign(ofRecognized, { isFinite: isFinite(value) }); } catch (e) {}
  try { Object.assign(ofRecognized, { isNaN: isNaN(value) }); } catch (e) {}

  // Recognize instances.
  RECOGNIZE_INSTANCES.concat(instances as any).forEach((instance) => (
    Object.assign(ofRecognized, { [instance.name]: value instanceof instance })
  ));

  // If only true remove false.
  if (is.true(onlyTrue)) {
    Object.keys(ofRecognized).filter((type: string) =>
      is.false(ofRecognized[type as keyof OfRecognized])
        ? delete ofRecognized[type as keyof OfRecognized]
        : true
    );
  }
  return ofRecognized;
};
```

{% endcode %}

### Parameters

#### `value: any`

The `value` of any type to recognize.

#### `onlyTrue: boolean`

Determines whether to show only recognized as `true`.

#### `instances: any[]`

An optional array of objects to check by using [`instanceof`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/instanceof) operator.

### Return type

#### `OfRecognized`

The **return type** is an interface of the operators and functions used to check.

### Returns

The **return value** is an [`object`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object) of types and instances recognized as `true` or all even those recognized as `false`.

## Example usage

```typescript
// Example usage.
import { recognizeValue } from '@angular-package/type';

// Class.
class CustomClass {}
const customClass = new CustomClass();

// String.
const firstName = 'Artemis';


/*
Returns {
  "typeOf": "object",
  "typeof": "object",
  "isNaN": true,
  "Object": true,
  "CustomClass": true
}
*/
recognizeValue(customClass, true, [CustomClass]);

/*
Returns {
  "isClass": true,
  "typeOf": "function",
  "typeof": "function",
  "isNaN": true,
  "Function": true,
  "Object": true
}
*/
recognizeValue(CustomClass);

/*
Returns {
  "typeOf": "string",
  "typeof": "string",
  "isNaN": true
}
*/
recognizeValue(firstName);

/*
Returns {
  "typeOf": "string",
  "typeof": "object",
  "isNaN": true,
  "Object": true,
  "String": true
}
*/
recognizeValue(new String(firstName));
```


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.angular-package.dev/type/helper/recognizevalue.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
