# core/normalizers/layer.normalizer.ts

> 34 lines of code and 14 definitions.

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

Listed in [core/normalizers](https://banes-lab.com/api/source/context/core/normalizers.md), after [core/normalizers/grammar.normalizer.ts](https://banes-lab.com/source/context/core/normalizers/grammar.normalizer.ts.md) and before [core/normalizers/lexicon.normalizer.ts](https://banes-lab.com/source/context/core/normalizers/lexicon.normalizer.ts.md).

## Definitions

- `asLayerEdge` (lexical_declaration, line 7, exported)
- `asLayerMembership` (lexical_declaration, line 17, exported)
- `asTensionResolution` (lexical_declaration, line 26, exported)
- `from` (lexical_declaration, line 11, exported)
- `to` (lexical_declaration, line 12, exported)
- `kind` (lexical_declaration, line 13, exported)
- `key` (lexical_declaration, line 21, exported)
- `layer` (lexical_declaration, line 22, exported)
- `a` (lexical_declaration, line 30, exported)
- `b` (lexical_declaration, line 31, exported)
- `mechanism` (lexical_declaration, line 32, exported)
- `rule` (lexical_declaration, line 33, exported)
- `scopeA` (lexical_declaration, line 34, exported)
- `scopeB` (lexical_declaration, line 35, exported)

## Contained in

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

## Uses

- [core/predicates/record.predicate.ts](https://banes-lab.com/source/context/core/predicates/record.predicate.ts.md)

## Linked from

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

## Source

```typescript
import { LAYER_EDGE_KIND_VALUES, RESOLUTION_MECHANISM_VALUES } from "#configuration/constants/layer.constants";
import type { LayerEdge, LayerMembership, TensionResolution } from "#types/layer.types";
import { asClosed, asString } from "#core/normalizers/field.normalizer";
import { edgeKindOf, mechanismOf } from "#configuration/strings/layer.strings";
import { isObject } from "#core/predicates/record.predicate";

export const asLayerEdge = function asLayerEdge(value: unknown): LayerEdge | null {
    if (!isObject(value)) {
        return null;
    }
    const from = asString(value["from"]);
    const to = asString(value["to"]);
    const kind = asClosed(LAYER_EDGE_KIND_VALUES, value["kind"], edgeKindOf(from, to));
    return from && to ? { from, kind, to } : null;
};

export const asLayerMembership = function asLayerMembership(value: unknown): LayerMembership | null {
    if (!isObject(value)) {
        return null;
    }
    const key = asString(value["key"]);
    const layer = asString(value["layer"]);
    return key && layer ? { key, layer } : null;
};

export const asTensionResolution = function asTensionResolution(value: unknown): TensionResolution | null {
    if (!isObject(value)) {
        return null;
    }
    const a = asString(value["a"]);
    const b = asString(value["b"]);
    const mechanism = asClosed(RESOLUTION_MECHANISM_VALUES, value["mechanism"], mechanismOf(a, b));
    const rule = asString(value["rule"]);
    const scopeA = asString(value["scopeA"]);
    const scopeB = asString(value["scopeB"]);
    return a && b && rule ? { a, b, mechanism, rule, scopeA, scopeB } : null;
};
```
