object_values 0.1.1 → 0.1.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/index.js +25 -18
- package/package.json +1 -1
package/index.js
CHANGED
@@ -1,23 +1,30 @@
|
|
1
1
|
Object.values = Object.values ? Object.values : function(obj) {
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
2
|
+
var allowedTypes = ["[object String]", "[object Object]", "[object Array]", "[object Function]"];
|
3
|
+
var objType = Object.prototype.toString.call(obj);
|
4
|
+
|
5
|
+
if(obj === null || typeof obj === "undefined") {
|
6
|
+
throw new TypeError("Cannot convert undefined or null to object");
|
7
|
+
} else if(!~allowedTypes.indexOf(objType)) {
|
8
|
+
return [];
|
9
|
+
} else {
|
10
|
+
// if ES6 is supported
|
11
|
+
if (Object.keys) {
|
12
|
+
return Object.keys(obj).map(function (key) {
|
13
|
+
return obj[key];
|
14
|
+
});
|
15
|
+
}
|
16
|
+
|
17
|
+
var result = [];
|
18
|
+
for (var prop in obj) {
|
19
|
+
if (obj.hasOwnProperty(prop)) {
|
20
|
+
result.push(obj[prop]);
|
21
|
+
}
|
22
|
+
}
|
23
|
+
|
24
|
+
return result;
|
25
|
+
}
|
19
26
|
};
|
20
27
|
|
21
28
|
if (typeof module !== 'undefined' && module.exports) {
|
22
|
-
module.exports = Object.
|
29
|
+
module.exports = Object.values;
|
23
30
|
}
|