3.1.0-types.beta.2 • Published 6 years ago

rely-on v3.1.0-types.beta.2

Weekly downloads
5
License
ISC
Repository
github
Last release
6 years ago

Summary

HTML applications often require an identified element to be present and select the element with the assumption that it is present.

Type-annotation tools like TypeScript and Flow will let you know that this isn't strictly the case: if an element isn't present, then null will be returned from document.getElementById.

Refining the type of the result can be done in an if (element !== null)...else but this must be done every time in order to eliminate the possibility of null.

This package allows code to rely on a Node being present

  • It refines a Node | null | undefined node into a Node to satisfy the type checker.
  • It returns the Node passed so methods can chain as usual.
  • It throws a TypeError with a customizable message if passed null | undefined so missing elements are caught at the point of selection.
  • It throws a TypeError if the argument passed is not a Node.

Example

const element = relyOn(document.getElementById('identifier'));
3.0.1

7 years ago

3.0.0

7 years ago

2.1.0

7 years ago

2.0.1

7 years ago

2.0.0

7 years ago

1.0.1

7 years ago

1.0.0

7 years ago