# keyword-args

> Python style keyword arguments with thorough typescript typing inference.

Latest version **1.0.0** (published 2021-06-15) · MIT license · 0 weekly downloads

## Install

```sh
npm install keyword-args
pnpm add keyword-args
yarn add keyword-args
bun add keyword-args
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.0.0 |
| Published | 2021-06-15 |
| First published | 2021-06-15 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 0 |
| Unpacked size | 76.7 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Author | SIGUSR97 |
| Maintainers | jeffzo |
| Keywords | python, typescript, kwargs |

## Links

- npm: https://www.npmjs.com/package/keyword-args
- npm.io page: https://npm.io/package/keyword-args

## Alternatives

- [@openai/codex-sdk](https://npm.io/package/@openai/codex-sdk.md) — 731.4K weekly downloads
- [babel-plugin-transform-react-jsx](https://npm.io/package/babel-plugin-transform-react-jsx.md) — 565.0K weekly downloads
- [babel-helper-remove-or-void](https://npm.io/package/babel-helper-remove-or-void.md) — 508.5K weekly downloads
- [@pnpm/store-controller-types](https://npm.io/package/@pnpm/store-controller-types.md) — 186.9K weekly downloads
- [react-native-signature-canvas](https://npm.io/package/react-native-signature-canvas.md) — 155.6K weekly downloads

## Recent versions

- 1.0.0 (latest) — 2021-06-15

## README

# keyword-args

Python style keyword arguments with thorough typescript typing inference.

## Examples

A trivial example:

```ts
import { kwargs, KwsParameters, extractKwargs } from 'keyword-args';

function add(...args: KwsParameters<[a: number, b: number], { type: 'number' }>): number;
function add(...args: KwsParameters<[a: number, b: number], { type: 'string' }>): string;
function add(
    ...args: KwsParameters<[a: string | number, b: string | number], { type: 'number' | 'string' }>
): number | string {
    const [[a, b], { type }] = extractKwargs(args, { type: 'number' });
    if (type === 'number') return +a + +b;
    return `${a}${b}`;
}

const a = add(1, 2, { type: 'number' })     // type: number
const b = add('1', '2', { type: 'string' }) // type: string
```

Spread arguments:

```ts
function python_print(
    ...args: SpreadKwsParameters<
        string[],
        { sep?: string; end?: string }
    >): void {
    const [strs, { sep, end }] = extractKwargs(args, { sep: ' ', end: '\n' });
    console.log(strs.join(sep) + end);
}

python_print('hello', 'world', kwargs({ sep: '\n', end: '' }));
// hello
// world
```

## TODO

- [ ] Typing for default kwargs
- [ ] Unify `SpreadKwsParameters` and `KwsParameters`
- [ ] Tests
- [ ] More examples

---
_Source: https://npm.io/package/keyword-args · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
