open-index/open-npm huggingface dataset:
npm package: @osskit/currencies
Description: A TypeScript library for handling currency codes, symbols, and conversions.
Latest version: 2.2.1

# @osskit/currencies

A TypeScript library for handling currency codes, symbols, and conversions.

## Installation

```sh
yarn add @osskit/currencies
```

or

```sh
npm install @osskit/currencies
```

## Usage

### Importing the library

```typescript
import {
  getByCode,
  getByNumber,
  isCurrencyCode,
  toMajorUnit,
  toMinorUnit,
  getSymbolByCode,
  isAmount,
  calculateRate,
  applyRate,
} from '@osskit/currencies';
```

### Examples

#### Get currency by code

```typescript
const currency = getByCode('EUR');
console.log(currency);
```

#### Get currency by number

```typescript
const currency = getByNumber('978');
console.log(currency);
```

#### Check if a string is a valid currency code

```typescript
const isValid = isCurrencyCode('USD');
console.log(isValid); // true
```

#### Convert to major unit

```typescript
const majorUnit = toMajorUnit({ value: 100_000, currency: 'USD' });
console.log(majorUnit); // 1000
```

#### Convert to minor unit

```typescript
const minorUnit = toMinorUnit(1000, 'USD');
console.log(minorUnit); // 100_000
```

#### Get symbol by currency code

```typescript
const symbol = getSymbolByCode('USD');
console.log(symbol); // $
```

#### Check if an object is a valid amount

```typescript
const validAmount = isAmount({ value: 1000, currency: 'USD' });
console.log(validAmount); // true
```

#### Calculate exchange rate

```typescript
const rate = calculateRate({ value: 1000, currency: 'USD' }, { value: 800, currency: 'EUR' });
console.log(rate); // 0.8
```

#### Apply exchange rate to amount

```typescript
const convertedAmount = applyRate({ value: 100_000, currency: 'USD' }, 'EUR', 0.8);
console.log(convertedAmount); // { value: 80_000, currency: 'EUR' }
```

## Running Tests

To run the tests, use the following command:

```sh
yarn test
```

## Contributing

Contributions are welcome! Please open an issue or submit a pull request.

## License

This project is licensed under the MIT License.
npm package: @osskit/dafka-producer-fetch-client
Description: <div align="center">
Latest version: 0.0.5

<div align="center">
 
  ![GitHub Workflow Status](https://img.shields.io/github/actions/workflow/status/osskit/dafka-producer-fetch-client/publish.yml) [![License](https://img.shields.io/badge/license-MIT-blue.svg)](https://github.com/osskit/dafka-producer-fetch-client/blob/master/LICENSE.md) [![code style: prettier](https://img.shields.io/badge/code_style-prettier-ff69b4.svg?style=flat-square)](https://github.com/prettier/prettier)

typescript-fetch client wrapper for `dafka-producer`  
</div>

## Install
```sh
yarn add @osskit/dafka-producer-fetch-client
```
## Usage
```ts
import { createProducer } from '@osskit/dafka-producer-fetch-client';

export const produce = createProducer<Message>({
    url: 'http://dafka-producer',
    topic: 'my-topic',
    keyExtractor: (record) => record.id,
    fetch: global.fetch,
});

await produce(records);
```
### Extra headers
It is possible to add extra headers to the request
```ts
await produce(records, {
    'x-extra-header': 'value',
});
```

## API
### createProducer({ url, topic, keyExtractor, fetch })
#### url
Type: `string`

The URL of `dafka-producer`

#### topic
Type: `string`

The Kafka Topic name

#### keyExtractor
Type: `(record: Record) => string`

A function to extract the key from a record, defaults to a random `UUID`

#### fetch
Type: `typeof global.fetch`

The fetch function to use

#### returns
An instance of a function that receives `<Record>(records: Record[], extraHeaders?: object)` and returns `Promise<void>`

## License
[MIT License](LICENSE)