open-index/open-npm huggingface dataset:
npm package: @scholten.dev/api-base
Description: ## services/configuration
Latest version: 0.8.0

# Api base

## services/configuration

Configuration service will try to map environment variables to an existing configuration class.

If the environment variable doesn't exist, the already existing value in the baseConfig will be used.

If the type is not matching, an error will be thrown.

Note: environment variables must be prefixed with CONFIG_. Example: `CONFIG_credentials_password=myPassword`

``` typescript
import {Configuration} from @scholten.dev/api-base

interface IConfig {
    devMode: boolean;
    credentials: {
        username: string;
        password: string;
    }
}

const baseConfig: IConfig = {
    devMode: true,
    credentials: {
        username: "user"
        password: "pass"
    }
}

const config = Configuration<IConfig>(baseConfig);
```

## Health check
get /api/healthz
npm package: @scholten.dev/concurrency
Description: ## Ratelimiting
Latest version: 0.2.0

# Concurrency

## Ratelimiting

This service makes sure a limited amount of async calls will be running at the same time.

``` typescript
// Run only 2 requests at the same time
const rateLimit = new RateLimit({ concurrent: 2 });

await Promise.all([0,1,2,3,4,5,6,7,8,9].map(async () => {
    return rateLimit.enqueue<Response>(async () => {
        const request = await fetch('https://example.com');
        return request.text();
    });
});
```

# Sleep
``` typescript
// Pause the current thread with 1 second
await sleep (1000);
```
npm package: @scholten.dev/file-store
Description: Typescript package which interfaces the filestore api.
Latest version: 0.0.3

# File store
Typescript package which interfaces the filestore api.

## Usage
Usage in plain nodejs

``` typescript
const fileStore = new FileStore('domainname.com', 'userId', 'api-key');

const file = await fileStore.getFile('myfile.jpg');
const text = arrayBufferToText(file);
const buffer = arrayBufferToBuffer(file);

const filePath = await fileStore.saveFile('myfile.jpg', 'image/jpeg', bufferToBase64(buffer));

await fileStore.deleteFile('myfile.jpg);
```

Usage in nestjs

``` typescript
import { Global, Module } from '@nestjs/common';
import { ConfigService } from '@nestjs/config';
import { FileStore } from '@scholten.dev/file-store';

export enum Globals {
  FILE_STORE = 'filestore',
}

@Global()
@Module({
  providers: [
    {
      provide: Globals.FILE_STORE,
      inject: [ConfigService],
      useFactory: async (configService: ConfigService) =>
        new FileStore(
          configService.getOrThrow('FILESTORE_DOMAIN'),
          configService.getOrThrow('FILESTORE_USERID'),
          configService.getOrThrow('FILESTORE_APIKEY'),
        ),
    },
  ],
  exports: [Globals.FILE_STORE],
})
export class GlobalModule {}
```