# core/matchers/algorithm.matcher.ts

> 27 lines of code and 9 definitions.

Tree: GovLab Context
Language: typescript
Layer: processing
Canonical: https://banes-lab.com/anatomy/context#file-context-core-matchers-algorithm-matcher-ts
Source text: https://banes-lab.com/source/context/core/matchers/algorithm.matcher.ts.txt

Listed in [core/matchers](https://banes-lab.com/api/source/context/core/matchers.md), before [core/matchers/architecture.matcher.ts](https://banes-lab.com/source/context/core/matchers/architecture.matcher.ts.md).

## Definitions

- `matchesDomain` (lexical_declaration, line 7)
- `matchesForce` (lexical_declaration, line 12)
- `matchesComposes` (lexical_declaration, line 17)
- `matchesMeta` (lexical_declaration, line 22)
- `matchesContract` (lexical_declaration, line 26, exported)
- `wanted` (lexical_declaration, line 3)
- `domain` (lexical_declaration, line 8)
- `force` (lexical_declaration, line 13)
- `composes` (lexical_declaration, line 18)

## Contained in

- [core/matchers](https://banes-lab.com/anatomy/context/folder-context-core-matchers.md)

## Linked from

- [core/matchers](https://banes-lab.com/anatomy/context/folder-context-core-matchers.md)

## Source

```typescript
import type { Contract, ContractFilter } from "#types/algorithm.types";

const wanted = function wanted(value: string | undefined): string | null {
    return typeof value === "string" && value.length > 0 ? value : null;
};

const matchesDomain = function matchesDomain(contract: Contract, filter: ContractFilter): boolean {
    const domain = wanted(filter.domain);
    return domain === null || contract.domain === domain;
};

const matchesForce = function matchesForce(contract: Contract, filter: ContractFilter): boolean {
    const force = wanted(filter.force);
    return force === null || contract.force.includes(force);
};

const matchesComposes = function matchesComposes(contract: Contract, filter: ContractFilter): boolean {
    const composes = wanted(filter.composes);
    return composes === null || contract.composes.includes(composes);
};

const matchesMeta = function matchesMeta(contract: Contract, filter: ContractFilter): boolean {
    return typeof filter.meta !== "boolean" || Boolean(contract.meta) === filter.meta;
};

export const matchesContract = function matchesContract(contract: Contract, filter: ContractFilter): boolean {
    return (
        matchesDomain(contract, filter) &&
        matchesForce(contract, filter) &&
        matchesComposes(contract, filter) &&
        matchesMeta(contract, filter)
    );
};
```
