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.
Files changed (2) hide show
  1. package/index.js +25 -18
  2. package/package.json +1 -1
package/index.js CHANGED
@@ -1,23 +1,30 @@
1
1
  Object.values = Object.values ? Object.values : function(obj) {
2
- var objType = Object.prototype.toString.call(obj);
3
- if(objType === "[object Array]" || objType === "[object Object]") {
4
- var valuesArray = [];
5
- for(var key in obj) {
6
- valuesArray.push(obj[key]);
7
- }
8
-
9
- return objType === "[object Array]" ? valuesArray : valuesArray.sort(function(a, b) {return a-b;});
10
- }
11
- else {
12
- if(obj === null || typeof obj === "undefined") {
13
- throw new TypeError("Cannot convert undefined or null to object");
14
- }
15
- else {
16
- return [];
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.entries;
29
+ module.exports = Object.values;
23
30
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "object_values",
3
- "version": "0.1.1",
3
+ "version": "0.1.2",
4
4
  "description": "polyfill for es8 Object.values",
5
5
  "main": "index.js",
6
6
  "scripts": {