material-motion
Version:
Makes it easy to add rich, interactive motion to your application.
93 lines • 3.06 kB
JavaScript
/** @license
* Copyright 2016 - present The Material Motion Authors. All Rights Reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may not
* use this file except in compliance with the License. You may obtain a copy
* of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
* License for the specific language governing permissions and limitations
* under the License.
*/
import $$observable from 'symbol-observable';
/**
* Checks if an object is a Boolean.
*/
export function isBoolean(value) {
return typeof value === 'boolean';
}
/**
* Checks if an object is not undefined.
*/
export function isDefined(value) {
return typeof value !== 'undefined';
}
/**
* Checks if an object has numeric values for both `width` and `height`.
*/
export function isDimensions(value) {
return typeof value.width === 'number' && typeof value.height === 'number';
}
/**
* Checks if an object is a Number.
*/
export function isNumber(value) {
return typeof value === 'number';
}
/**
* Checks if an object is an observable by checking if it returns itself from
* [Symbol.observable]()
*/
export function isObservable(value) {
return value && value[$$observable] && value === value[$$observable]();
}
/**
* Checks if an object is a `Map` using `instanceof`.
*/
export function isMap(value) {
return value instanceof Map;
}
/**
* Checks if an object has numeric values for both `x` and `y`.
*/
export function isPoint2D(value) {
return typeof value.x === 'number' && typeof value.y === 'number';
}
/**
* Checks if a value is an `Observer` by checking if the value has a `next`
* method.
*/
export function isObserver(value) {
return typeof value.next === 'function';
}
/**
* Checks if a value is a `PointerEvent` by checking if the value is an `Event`
* whose `type` starts with `pointer`.
*
* This is useful for ensuring that `downEvent.target.setPointerCapture()` can
* be called: To avoid using the PointerEvent polyfill, a developer could
* create an object that had the subset of `PointerEvent` that we care about
* (`PartialPointerEvent`) and populate its values from `event.targetTouches`.
* However, we only need to call `setPointerCapture()` on a true `PointerEvent`,
* so `isPointerEvent(value)` needs to be able to distinguish between them.
*/
export function isPointerEvent(value) {
return value instanceof Event && value.type.startsWith('pointer');
}
/**
* Checks if value is iterable; that is, usable in a `for of` loop.
*/
export function isIterable(value) {
return value && value[Symbol.iterator] !== undefined;
}
/**
* Checks if value has a timestamp property.
*/
export function isTimestamped(value) {
return value && value.hasOwnProperty('timestamp');
}
//# sourceMappingURL=typeGuards.js.map