# tools/core/readers/source.reader.ts

> 18 lines of code and 4 definitions.

Tree: Coordination tree
Language: typescript
Canonical: https://banes-lab.com/anatomy/coordination#file-coordination-tools-core-readers-source-reader-ts
Source text: https://banes-lab.com/assets/sources/source.6b5aaf56e0c45de1f8390c00f2677ebbb38b964a495f8513582961506d2b1cc8.generated.txt

## Definitions

- `importSource` (lexical_declaration, line 10, exported)
- `LoadedSource` (interface_declaration, line 4, exported)
- `loaded` (lexical_declaration, line 12, exported)
- `importSources` (lexical_declaration, line 19, exported)

## Uses

- [tools/core/predicates/schema.predicate.ts](https://banes-lab.com/source/coordination/tools/core/predicates/schema.predicate.ts.md)

## Source

```typescript
import { isObject } from "../predicates/schema.predicate.ts";
import { pathToFileURL } from "node:url";

export interface LoadedSource {
    readonly file: string;
    readonly exports: Readonly<Record<string, unknown>> | null;
    readonly error: string | null;
}

export const importSource = async function importSource(file: string): Promise<LoadedSource> {
    try {
        const loaded: unknown = await import(pathToFileURL(file).href);
        return { error: null, exports: isObject(loaded) ? loaded : {}, file };
    } catch (error) {
        return { error: String(error), exports: null, file };
    }
};

export const importSources = async function importSources(files: readonly string[]): Promise<LoadedSource[]> {
    return Promise.all(files.map(importSource));
};
```
