main
Last change
on this file since 79a0317 was 79a0317, checked in by stefan toskovski <stefantoska84@…>, 3 days ago |
F4 Finalna Verzija
|
-
Property mode
set to
100644
|
File size:
1000 bytes
|
Line | |
---|
1 | 'use strict';
|
---|
2 |
|
---|
3 | var $TypeError = require('es-errors/type');
|
---|
4 |
|
---|
5 | var objectKeys = require('object-keys');
|
---|
6 | var safePushApply = require('safe-push-apply');
|
---|
7 | var callBound = require('call-bound');
|
---|
8 |
|
---|
9 | var $isEnumerable = callBound('Object.prototype.propertyIsEnumerable');
|
---|
10 |
|
---|
11 | var forEach = require('../helpers/forEach');
|
---|
12 | var isObject = require('../helpers/isObject');
|
---|
13 |
|
---|
14 | // https://262.ecma-international.org/14.0/#sec-enumerableownproperties
|
---|
15 |
|
---|
16 | module.exports = function EnumerableOwnProperties(O, kind) {
|
---|
17 | if (!isObject(O)) {
|
---|
18 | throw new $TypeError('Assertion failed: Type(O) is not Object');
|
---|
19 | }
|
---|
20 |
|
---|
21 | var keys = objectKeys(O);
|
---|
22 | if (kind === 'key') {
|
---|
23 | return keys;
|
---|
24 | }
|
---|
25 | if (kind === 'value' || kind === 'key+value') {
|
---|
26 | var results = [];
|
---|
27 | forEach(keys, function (key) {
|
---|
28 | if ($isEnumerable(O, key)) {
|
---|
29 | safePushApply(results, [
|
---|
30 | kind === 'value' ? O[key] : [key, O[key]]
|
---|
31 | ]);
|
---|
32 | }
|
---|
33 | });
|
---|
34 | return results;
|
---|
35 | }
|
---|
36 | throw new $TypeError('Assertion failed: "kind" is not "key", "value", or "key+value": ' + kind);
|
---|
37 | };
|
---|
Note:
See
TracBrowser
for help on using the repository browser.