# core/predicates/credential.predicate.ts

> 32 lines of code and 6 definitions.

Tree: Secrets
Language: typescript
Layer: infrastructure
Canonical: https://banes-lab.com/anatomy/secrets#file-secrets-core-predicates-credential-predicate-ts
Source text: https://banes-lab.com/source/secrets/core/predicates/credential.predicate.ts.txt

Listed in [core/predicates](https://banes-lab.com/api/source/secrets/core/predicates.md), after [core/predicates/character.predicate.ts](https://banes-lab.com/source/secrets/core/predicates/character.predicate.ts.md) and before [core/predicates/database.predicate.ts](https://banes-lab.com/source/secrets/core/predicates/database.predicate.ts.md).

## Definitions

- `authorityOf` (lexical_declaration, line 9)
- `end` (lexical_declaration, line 10)
- `carriesCredentials` (lexical_declaration, line 17)
- `at` (lexical_declaration, line 18)
- `colon` (lexical_declaration, line 19)
- `mark` (lexical_declaration, line 25)

## Contained in

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

## Source

```typescript
import {
    AUTHORITY_ENDS,
    CREDENTIAL_AT,
    CREDENTIAL_COLON,
    SCHEME_MARK,
} from "#configuration/constants/detector.constants";
import { defineDetector } from "#core/registries/detector.registry";

const authorityOf = function authorityOf(value: string, start: number): string {
    let end = start;
    while (end < value.length && !AUTHORITY_ENDS.has(value.charAt(end))) {
        end += 1;
    }
    return value.slice(start, end);
};

const carriesCredentials = function carriesCredentials(authority: string): boolean {
    const at = authority.lastIndexOf(CREDENTIAL_AT);
    const colon = authority.indexOf(CREDENTIAL_COLON);
    return at > 0 && colon > 0 && colon < at;
};

defineDetector({
    detects: (value) => {
        let mark = value.indexOf(SCHEME_MARK);
        while (mark > 0) {
            if (carriesCredentials(authorityOf(value, mark + SCHEME_MARK.length))) {
                return true;
            }
            mark = value.indexOf(SCHEME_MARK, mark + SCHEME_MARK.length);
        }
        return false;
    },
    kind: "credential",
});
```
