element-x4z00URv.mjs 1.1 KB

1234567891011121314151617181920212223242526272829
  1. import { ElementRef } from '@angular/core';
  2. function coerceNumberProperty(value, fallbackValue = 0) {
  3. if (_isNumberValue(value)) {
  4. return Number(value);
  5. }
  6. return arguments.length === 2 ? fallbackValue : 0;
  7. }
  8. /**
  9. * Whether the provided value is considered a number.
  10. * @docs-private
  11. */
  12. function _isNumberValue(value) {
  13. // parseFloat(value) handles most of the cases we're interested in (it treats null, empty string,
  14. // and other non-number values as NaN, where Number just uses 0) but it considers the string
  15. // '123hello' to be a valid number. Therefore we also check if Number(value) is NaN.
  16. return !isNaN(parseFloat(value)) && !isNaN(Number(value));
  17. }
  18. /**
  19. * Coerces an ElementRef or an Element into an element.
  20. * Useful for APIs that can accept either a ref or the native element itself.
  21. */
  22. function coerceElement(elementOrRef) {
  23. return elementOrRef instanceof ElementRef ? elementOrRef.nativeElement : elementOrRef;
  24. }
  25. export { _isNumberValue as _, coerceElement as a, coerceNumberProperty as c };
  26. //# sourceMappingURL=element-x4z00URv.mjs.map