Skip to content

Commit

Permalink
update readme
Browse files Browse the repository at this point in the history
  • Loading branch information
eegli committed Jan 5, 2022
1 parent bfa690a commit e4c3e2a
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 1 deletion.
10 changes: 9 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,15 @@
"publishConfig": {
"access": "public"
},
"keywords": [],
"keywords": [
"cli",
"node",
"parse",
"argument",
"config",
"utility",
"typescript"
],
"homepage": "https://github.com/eegli/tinyparse",
"author": {
"name": "Eric Egli",
Expand Down
44 changes: 44 additions & 0 deletions readme.md
Original file line number Diff line number Diff line change
@@ -1 +1,45 @@
# Tinyparse

### Highly opiniated, type-safe parsing module for object literals and Node's `process.argv`.

I use this mostly for other pet projects of mine, but why not make it public.

- TypeScript first
- Promise-based
- Fast, zero dependencies
- Supports object literals and arrays of strings

The whole thing is quite opinionated and assumes some things. It exports a single parser factory function that accepts either an object literal or array of strings (usually, `process.argv.slice(2)`)

Whatever config is parsed with the `parser` function created by the factory will get the key-value pairs from the default config, but with updated keys if they are valid.

```ts
import { parserFactory } from '@eegli/tinyparse';

const defaultInput = {
name: '',
age: 0,
hasDog: true,
};

const userInput = {
name: 'eric',
age: 12,
what: 'is he doing',
};

const parse = parserFactory(defaultInput);
const parsedInput = await parse(userInput);

/* -- parsedInput
{
name: 'eric',
age: 12,
hasDog: true
}
*/
```

1. The object literal argument can only have strings, numbers and booleans as object keys
2. It expects an object that specifies the **exact types** that are desired for the parsed arguments. The exact values of `defaultInput` don't matter as long as the types are correct.
3. Invalid keys are ignored, invalid value types are rejected

0 comments on commit e4c3e2a

Please sign in to comment.