UNPKG

795 BJavaScriptView Raw
1import { obj } from '../util';
2
3var isPlainObject = obj.isPlainObject;
4
5/**
6 * 过滤 undefined 类型的值
7 * @param {*} obj
8 * @return {Object}
9 */
10
11export function filterUndefinedValue(object) {
12 if (!isPlainObject(object)) {
13 return object;
14 }
15
16 var obj = {};
17
18 Object.keys(object).forEach(function (key) {
19 var value = object[key];
20
21 if (value !== undefined) {
22 obj[key] = value;
23 }
24 });
25
26 return obj;
27}
28
29/**
30 * 从 obj 中去除 subObj
31 * @param {*} obj
32 * @param {*} subObj
33 * @return {Object}
34 */
35export function stripObject(obj, subObj) {
36 var newObject = {};
37
38 Object.keys(obj).forEach(function (key) {
39 if (!(key in subObj)) {
40 newObject[key] = obj[key];
41 }
42 });
43 return newObject;
44}
\No newline at end of file