UNPKG

976 BJavaScriptView Raw
1/**
2 * Assign properties from `props` to `obj`
3 * @template O, P The obj and props types
4 * @param {O} obj The object to copy properties to
5 * @param {P} props The object to copy properties from
6 * @returns {O & P}
7 */
8export function assign(obj, props) {
9 for (let i in props) obj[i] = props[i];
10 return /** @type {O & P} */ (obj);
11}
12
13/**
14 * Check if two objects have a different shape
15 * @param {object} a
16 * @param {object} b
17 * @returns {boolean}
18 */
19export function shallowDiffers(a, b) {
20 for (let i in a) if (i !== '__source' && !(i in b)) return true;
21 for (let i in b) if (i !== '__source' && a[i] !== b[i]) return true;
22 return false;
23}
24
25export function removeNode(node) {
26 let parentNode = node.parentNode;
27 if (parentNode) parentNode.removeChild(node);
28}
29
30/**
31 * Check if two values are the same value
32 * @param {*} x
33 * @param {*} y
34 * @returns {boolean}
35 */
36export function is(x, y) {
37 return (x === y && (x !== 0 || 1 / x === 1 / y)) || (x !== x && y !== y);
38}