Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rorganize validation and normalization #85

Open
medikoo opened this issue Jul 17, 2018 · 0 comments
Open

Rorganize validation and normalization #85

medikoo opened this issue Jul 17, 2018 · 0 comments
Assignees

Comments

@medikoo
Copy link
Owner

medikoo commented Jul 17, 2018

Possibly es5-ext can be split into two packages, that will handle following scopes

1. normalization & validation

For some supported coercible primitive types it may have following functions

  • coerce - Resolves a valid value of given type and returns it. If valid value can't be resolved returns null
  • ensure - Resolves a valid value of given type and returns it. If valid value can't be resolved throws TypeError exception. Supports following options:
    • optional: false - If value is null or undefined then ensure returns null (doesn't throw)
    • errorClass: TypeError - Error class to use
    • errorMessage: "%v is not a {type}" - Eventual error message to override
  • is - Is value a valid value of given type

For some duck-typed object types it may have following functions

  • is-like - Returns true if value matches contract
  • ensure - Returns value if it matches contract, otherwise throws TypeError exception

For some other object types it may have following functions

  • is - Returns true if value is an object of given type
  • ensure - Returns value if it's object of given type, otherwise throws TypeError exception

Example modules

  • value/is (or is-value)
  • value/ensure (or ensure-value)
  • string/is (or is-string)
  • string/coerce (or string-coerce)
  • string/ensure (or string-ensure)
  • number/is (or is-number)
  • number/integer/ensure (or ensure-integer)
  • number/natural/ensure (or ensure-natural-number)
  • array/like/is (or is-array-like)
  • array/like/ensure
  • array/is (this may be omitted as it's directly served by native Array.isArray)
  • array/ensure
  • date/is
  • date/ensure
  • function/plain/is (or is-plain-function)
  • iterable/is (or is-iterable)
  • promise/is
  • promise/is-like
  • thenable/is

2. extensions

A standard library of extra functions and methods (including shims)

@medikoo medikoo self-assigned this Jul 17, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant