Skip to content

Rorganize validation and normalization #85

Open
@medikoo

Description

@medikoo

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)

Metadata

Metadata

Assignees

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions