richardscarrott / ok-computer

λ "Functions all the way down" data validation for JavaScript and TypeScript.
MIT License
79 stars 0 forks source link

Parser improvements #23

Open richardscarrott opened 2 years ago

richardscarrott commented 2 years ago
  1. Default to { keepUnknown: true }
    
    const parser = parse.object(
    {
    firstName: parse.trim,
    lastName: parse.trim,
    // Forgot to add `age`
    },
    { keepUnknown: true }
    );

const validator = object({ firstName: string, lastName: string, age: or(nullish, number) });

// This won't error because the parser has thrown away age which most likely isn't desirable const errors = validator(parser({ firstName: 'foo', lastName: 'bar', age: 100 }));


2. Rename to just `parse`?
    - Need an ergonomic way to import validator fns vs parse fns as there's overlap in name
       - I don't expect many more (any more?) utils to be provided by parse as they're just simple fns
       - Perhaps `import * as parse from 'ok-computer/parse`?
3. Expose well typed `pipe` util?
    - [`@bitty/pipe`](https://github.com/VitorLuizC/bitty/blob/master/packages/pipe/README.md) is good, but hassle to have to install it when it's frequently needed to compose parser fns?
    - Perhaps under `ok-computer/utils` or even `ok-computer/pipe`?
4. Add docs