New upstream snapshot.
Debian Janitor
2 years ago
0 | coverage/ |
6 | 6 | "id-length": [2, { "min": 1, "max": 35 }], |
7 | 7 | "max-lines-per-function": [2, 100], |
8 | 8 | "max-params": [2, 4], |
9 | "max-statements": [2, 13] | |
10 | } | |
9 | }, | |
10 | ||
11 | "overrides": [ | |
12 | { | |
13 | "files": "test/**", | |
14 | "rules": { | |
15 | "max-lines-per-function": 0, | |
16 | }, | |
17 | }, | |
18 | ], | |
11 | 19 | } |
0 | # These are supported funding model platforms | |
1 | ||
2 | github: [ljharb] | |
3 | patreon: # Replace with a single Patreon username | |
4 | open_collective: # Replace with a single Open Collective username | |
5 | ko_fi: # Replace with a single Ko-fi username | |
6 | tidelift: npm/define-properties | |
7 | community_bridge: # Replace with a single Community Bridge project-name e.g., cloud-foundry | |
8 | liberapay: # Replace with a single Liberapay username | |
9 | issuehunt: # Replace with a single IssueHunt username | |
10 | otechie: # Replace with a single Otechie username | |
11 | custom: # Replace with up to 4 custom sponsorship URLs e.g., ['link1', 'link2'] |
0 | { | |
1 | "es3": true, | |
2 | ||
3 | "additionalRules": [], | |
4 | ||
5 | "requireSemicolons": true, | |
6 | ||
7 | "disallowMultipleSpaces": true, | |
8 | ||
9 | "disallowIdentifierNames": [], | |
10 | ||
11 | "requireCurlyBraces": { | |
12 | "allExcept": [], | |
13 | "keywords": ["if", "else", "for", "while", "do", "try", "catch"] | |
14 | }, | |
15 | ||
16 | "requireSpaceAfterKeywords": ["if", "else", "for", "while", "do", "switch", "return", "try", "catch", "function"], | |
17 | ||
18 | "disallowSpaceAfterKeywords": [], | |
19 | ||
20 | "disallowSpaceBeforeComma": true, | |
21 | "disallowSpaceAfterComma": false, | |
22 | "disallowSpaceBeforeSemicolon": true, | |
23 | ||
24 | "disallowNodeTypes": [ | |
25 | "DebuggerStatement", | |
26 | "LabeledStatement", | |
27 | "SwitchCase", | |
28 | "SwitchStatement", | |
29 | "WithStatement" | |
30 | ], | |
31 | ||
32 | "requireObjectKeysOnNewLine": { "allExcept": ["sameLine"] }, | |
33 | ||
34 | "requireSpacesInAnonymousFunctionExpression": { "beforeOpeningRoundBrace": true, "beforeOpeningCurlyBrace": true }, | |
35 | "requireSpacesInNamedFunctionExpression": { "beforeOpeningCurlyBrace": true }, | |
36 | "disallowSpacesInNamedFunctionExpression": { "beforeOpeningRoundBrace": true }, | |
37 | "requireSpacesInFunctionDeclaration": { "beforeOpeningCurlyBrace": true }, | |
38 | "disallowSpacesInFunctionDeclaration": { "beforeOpeningRoundBrace": true }, | |
39 | ||
40 | "requireSpaceBetweenArguments": true, | |
41 | ||
42 | "disallowSpacesInsideParentheses": true, | |
43 | ||
44 | "disallowSpacesInsideArrayBrackets": true, | |
45 | ||
46 | "disallowQuotedKeysInObjects": { "allExcept": ["reserved"] }, | |
47 | ||
48 | "disallowSpaceAfterObjectKeys": true, | |
49 | ||
50 | "requireCommaBeforeLineBreak": true, | |
51 | ||
52 | "disallowSpaceAfterPrefixUnaryOperators": ["++", "--", "+", "-", "~", "!"], | |
53 | "requireSpaceAfterPrefixUnaryOperators": [], | |
54 | ||
55 | "disallowSpaceBeforePostfixUnaryOperators": ["++", "--"], | |
56 | "requireSpaceBeforePostfixUnaryOperators": [], | |
57 | ||
58 | "disallowSpaceBeforeBinaryOperators": [], | |
59 | "requireSpaceBeforeBinaryOperators": ["+", "-", "/", "*", "=", "==", "===", "!=", "!=="], | |
60 | ||
61 | "requireSpaceAfterBinaryOperators": ["+", "-", "/", "*", "=", "==", "===", "!=", "!=="], | |
62 | "disallowSpaceAfterBinaryOperators": [], | |
63 | ||
64 | "disallowImplicitTypeConversion": ["binary", "string"], | |
65 | ||
66 | "disallowKeywords": ["with", "eval"], | |
67 | ||
68 | "requireKeywordsOnNewLine": [], | |
69 | "disallowKeywordsOnNewLine": ["else"], | |
70 | ||
71 | "requireLineFeedAtFileEnd": true, | |
72 | ||
73 | "disallowTrailingWhitespace": true, | |
74 | ||
75 | "disallowTrailingComma": true, | |
76 | ||
77 | "excludeFiles": ["node_modules/**", "vendor/**"], | |
78 | ||
79 | "disallowMultipleLineStrings": true, | |
80 | ||
81 | "requireDotNotation": { "allExcept": ["keywords"] }, | |
82 | ||
83 | "requireParenthesesAroundIIFE": true, | |
84 | ||
85 | "validateLineBreaks": "LF", | |
86 | ||
87 | "validateQuoteMarks": { | |
88 | "escape": true, | |
89 | "mark": "'" | |
90 | }, | |
91 | ||
92 | "disallowOperatorBeforeLineBreak": [], | |
93 | ||
94 | "requireSpaceBeforeKeywords": [ | |
95 | "do", | |
96 | "for", | |
97 | "if", | |
98 | "else", | |
99 | "switch", | |
100 | "case", | |
101 | "try", | |
102 | "catch", | |
103 | "finally", | |
104 | "while", | |
105 | "with", | |
106 | "return" | |
107 | ], | |
108 | ||
109 | "validateAlignedFunctionParameters": { | |
110 | "lineBreakAfterOpeningBraces": true, | |
111 | "lineBreakBeforeClosingBraces": true | |
112 | }, | |
113 | ||
114 | "requirePaddingNewLinesBeforeExport": true, | |
115 | ||
116 | "validateNewlineAfterArrayElements": { | |
117 | "maximum": 3 | |
118 | }, | |
119 | ||
120 | "requirePaddingNewLinesAfterUseStrict": true, | |
121 | ||
122 | "disallowArrowFunctions": true, | |
123 | ||
124 | "disallowMultiLineTernary": true, | |
125 | ||
126 | "validateOrderInObjectKeys": "asc-insensitive", | |
127 | ||
128 | "disallowIdenticalDestructuringNames": true, | |
129 | ||
130 | "disallowNestedTernaries": { "maxLevel": 1 }, | |
131 | ||
132 | "requireSpaceAfterComma": { "allExcept": ["trailing"] }, | |
133 | "requireAlignedMultilineParams": false, | |
134 | ||
135 | "requireSpacesInGenerator": { | |
136 | "afterStar": true | |
137 | }, | |
138 | ||
139 | "disallowSpacesInGenerator": { | |
140 | "beforeStar": true | |
141 | }, | |
142 | ||
143 | "disallowVar": false, | |
144 | ||
145 | "requireArrayDestructuring": false, | |
146 | ||
147 | "requireEnhancedObjectLiterals": false, | |
148 | ||
149 | "requireObjectDestructuring": false, | |
150 | ||
151 | "requireEarlyReturn": false, | |
152 | ||
153 | "requireCapitalizedConstructorsNew": { | |
154 | "allExcept": ["Function", "String", "Object", "Symbol", "Number", "Date", "RegExp", "Error", "Boolean", "Array"] | |
155 | }, | |
156 | ||
157 | "requireImportAlphabetized": false, | |
158 | ||
159 | "requireSpaceBeforeObjectValues": true, | |
160 | "requireSpaceBeforeDestructuredValues": true, | |
161 | ||
162 | "disallowSpacesInsideTemplateStringPlaceholders": true, | |
163 | ||
164 | "disallowArrayDestructuringReturn": false, | |
165 | ||
166 | "requireNewlineBeforeSingleStatementsInIf": false, | |
167 | ||
168 | "disallowUnusedVariables": true, | |
169 | ||
170 | "requireSpacesInsideImportedObjectBraces": true, | |
171 | ||
172 | "requireUseStrict": true | |
173 | } | |
174 |
0 | { | |
1 | "all": true, | |
2 | "check-coverage": false, | |
3 | "reporter": ["text-summary", "text", "html", "json"], | |
4 | "exclude": [ | |
5 | "coverage", | |
6 | "test" | |
7 | ] | |
8 | } |
0 | #define-properties <sup>[![Version Badge][npm-version-svg]][package-url]</sup> | |
0 | # define-properties <sup>[![Version Badge][npm-version-svg]][package-url]</sup> | |
1 | 1 | |
2 | [![Build Status][travis-svg]][travis-url] | |
3 | 2 | [![dependency status][deps-svg]][deps-url] |
4 | 3 | [![dev dependency status][dev-deps-svg]][dev-deps-url] |
5 | 4 | [![License][license-image]][license-url] |
6 | 5 | [![Downloads][downloads-image]][downloads-url] |
7 | 6 | |
8 | 7 | [![npm badge][npm-badge-png]][package-url] |
9 | ||
10 | [![browser support][testling-svg]][testling-url] | |
11 | 8 | |
12 | 9 | Define multiple non-enumerable properties at once. Uses `Object.defineProperty` when available; falls back to standard assignment in older engines. |
13 | 10 | Existing properties are not overridden. Accepts a map of property names to a predicate that, when true, force-overrides. |
68 | 65 | Simply clone the repo, `npm install`, and run `npm test` |
69 | 66 | |
70 | 67 | [package-url]: https://npmjs.org/package/define-properties |
71 | [npm-version-svg]: http://versionbadg.es/ljharb/define-properties.svg | |
72 | [travis-svg]: https://travis-ci.org/ljharb/define-properties.svg | |
73 | [travis-url]: https://travis-ci.org/ljharb/define-properties | |
68 | [npm-version-svg]: https://versionbadg.es/ljharb/define-properties.svg | |
74 | 69 | [deps-svg]: https://david-dm.org/ljharb/define-properties.svg |
75 | 70 | [deps-url]: https://david-dm.org/ljharb/define-properties |
76 | 71 | [dev-deps-svg]: https://david-dm.org/ljharb/define-properties/dev-status.svg |
77 | 72 | [dev-deps-url]: https://david-dm.org/ljharb/define-properties#info=devDependencies |
78 | [testling-svg]: https://ci.testling.com/ljharb/define-properties.png | |
79 | [testling-url]: https://ci.testling.com/ljharb/define-properties | |
80 | 73 | [npm-badge-png]: https://nodei.co/npm/define-properties.png?downloads=true&stars=true |
81 | [license-image]: http://img.shields.io/npm/l/define-properties.svg | |
74 | [license-image]: https://img.shields.io/npm/l/define-properties.svg | |
82 | 75 | [license-url]: LICENSE |
83 | [downloads-image]: http://img.shields.io/npm/dm/define-properties.svg | |
84 | [downloads-url]: http://npm-stat.com/charts.html?package=define-properties | |
76 | [downloads-image]: https://img.shields.io/npm/dm/define-properties.svg | |
77 | [downloads-url]: https://npm-stat.com/charts.html?package=define-properties | |
85 | 78 |
0 | node-define-properties (1.1.3+git20210418.1.4d61866-1) UNRELEASED; urgency=low | |
1 | ||
2 | * New upstream snapshot. | |
3 | ||
4 | -- Debian Janitor <janitor@jelmer.uk> Sun, 29 Aug 2021 00:36:16 -0000 | |
5 | ||
0 | 6 | node-define-properties (1.1.3-2) unstable; urgency=medium |
1 | 7 | |
2 | 8 | [ Debian Janitor ] |
14 | 14 | var obj = {}; |
15 | 15 | try { |
16 | 16 | origDefineProperty(obj, 'x', { enumerable: false, value: obj }); |
17 | // eslint-disable-next-line no-unused-vars, no-restricted-syntax | |
18 | for (var _ in obj) { // jscs:ignore disallowUnusedVariables | |
17 | // eslint-disable-next-line no-restricted-syntax, no-unreachable-loop | |
18 | for (var _ in obj) { | |
19 | 19 | return false; |
20 | 20 | } |
21 | 21 | return obj.x === obj; |
37 | 37 | writable: true |
38 | 38 | }); |
39 | 39 | } else { |
40 | object[name] = value; | |
40 | object[name] = value; // eslint-disable-line no-param-reassign | |
41 | 41 | } |
42 | 42 | }; |
43 | 43 |
0 | root = true | |
1 | ||
2 | [*] | |
3 | indent_style = tab; | |
4 | insert_final_newline = true; | |
5 | quote_type = auto; | |
6 | space_after_anonymous_functions = true; | |
7 | space_after_control_statements = true; | |
8 | spaces_around_operators = true; | |
9 | trim_trailing_whitespace = true; | |
10 | spaces_in_brackets = false; | |
11 | end_of_line = lf; | |
12 |
0 | { | |
1 | "root": true, | |
2 | ||
3 | "extends": "@ljharb", | |
4 | ||
5 | "rules": { | |
6 | "complexity": [2, 23], | |
7 | "id-length": [2, { "min": 1, "max": 40 }], | |
8 | "max-params": [2, 3], | |
9 | "max-statements": [2, 23], | |
10 | "max-statements-per-line": [2, { "max": 2 }], | |
11 | "no-extra-parens": [1], | |
12 | "no-invalid-this": [1], | |
13 | "no-restricted-syntax": [2, "BreakStatement", "ContinueStatement", "LabeledStatement", "WithStatement"], | |
14 | "operator-linebreak": [2, "after"] | |
15 | } | |
16 | } |
0 | 1.1.1 / 2019-04-06 | |
1 | ================= | |
2 | * [Fix] exclude deprecated Firefox keys (#53) | |
3 | ||
4 | 1.1.0 / 2019-02-10 | |
5 | ================= | |
6 | * [New] [Refactor] move full implementation to `implementation` entry point | |
7 | * [Refactor] only evaluate the implementation if `Object.keys` is not present | |
8 | * [Tests] up to `node` `v11.8`, `v10.15`, `v8.15`, `v6.16` | |
9 | * [Tests] remove jscs | |
10 | * [Tests] switch to `npm audit` from `nsp` | |
11 | ||
12 | 1.0.12 / 2018-06-18 | |
13 | ================= | |
14 | * [Fix] avoid accessing `window.applicationCache`, to avoid issues with latest Chrome on HTTP (#46) | |
15 | ||
16 | 1.0.11 / 2016-07-05 | |
17 | ================= | |
18 | * [Fix] exclude keys regarding the style (eg. `pageYOffset`) on `window` to avoid reflow (#32) | |
19 | ||
20 | 1.0.10 / 2016-07-04 | |
21 | ================= | |
22 | * [Fix] exclude `height` and `width` keys on `window` to avoid reflow (#31) | |
23 | * [Fix] In IE 6, `window.external` makes `Object.keys` throw | |
24 | * [Tests] up to `node` `v6.2`, `v5.10`, `v4.4` | |
25 | * [Tests] use pretest/posttest for linting/security | |
26 | * [Dev Deps] update `tape`, `jscs`, `nsp`, `eslint`, `@ljharb/eslint-config` | |
27 | * [Dev Deps] remove unused eccheck script + dep | |
28 | ||
29 | 1.0.9 / 2015-10-19 | |
30 | ================= | |
31 | * [Fix] Blacklist 'frame' property on window (#16, #17) | |
32 | * [Dev Deps] update `jscs`, `eslint`, `@ljharb/eslint-config` | |
33 | ||
34 | 1.0.8 / 2015-10-14 | |
35 | ================= | |
36 | * [Fix] wrap automation equality bug checking in try/catch, per [es5-shim#327](https://github.com/es-shims/es5-shim/issues/327) | |
37 | * [Fix] Blacklist 'window.frameElement' per [es5-shim#322](https://github.com/es-shims/es5-shim/issues/322) | |
38 | * [Docs] Switch from vb.teelaun.ch to versionbadg.es for the npm version badge SVG | |
39 | * [Tests] up to `io.js` `v3.3`, `node` `v4.2` | |
40 | * [Dev Deps] update `eslint`, `tape`, `@ljharb/eslint-config`, `jscs` | |
41 | ||
42 | 1.0.7 / 2015-07-18 | |
43 | ================= | |
44 | * [Fix] A proper fix for 176f03335e90d5c8d0d8125a99f27819c9b9cdad / https://github.com/es-shims/es5-shim/issues/275 that doesn't break dontEnum/constructor fixes in IE 8. | |
45 | * [Fix] Remove deprecation message in Chrome by touching deprecated window properties (#15) | |
46 | * [Tests] Improve test output for automation equality bugfix | |
47 | * [Tests] Test on `io.js` `v2.4` | |
48 | ||
49 | 1.0.6 / 2015-07-09 | |
50 | ================= | |
51 | * [Fix] Use an object lookup rather than ES5's `indexOf` (#14) | |
52 | * [Tests] ES3 browsers don't have `Array.isArray` | |
53 | * [Tests] Fix `no-shadow` rule, as well as an IE 8 bug caused by engine NFE shadowing bugs. | |
54 | ||
55 | 1.0.5 / 2015-07-03 | |
56 | ================= | |
57 | * [Fix] Fix a flabbergasting IE 8 bug where `localStorage.constructor.prototype === localStorage` throws | |
58 | * [Tests] Test up to `io.js` `v2.3` | |
59 | * [Dev Deps] Update `nsp`, `eslint` | |
60 | ||
61 | 1.0.4 / 2015-05-23 | |
62 | ================= | |
63 | * Fix a Safari 5.0 bug with `Object.keys` not working with `arguments` | |
64 | * Test on latest `node` and `io.js` | |
65 | * Update `jscs`, `tape`, `eslint`, `nsp`, `is`, `editorconfig-tools`, `covert` | |
66 | ||
67 | 1.0.3 / 2015-01-06 | |
68 | ================= | |
69 | * Revert "Make `object-keys` more robust against later environment tampering" to maintain ES3 compliance | |
70 | ||
71 | 1.0.2 / 2014-12-28 | |
72 | ================= | |
73 | * Update lots of dev dependencies | |
74 | * Tweaks to README | |
75 | * Make `object-keys` more robust against later environment tampering | |
76 | ||
77 | 1.0.1 / 2014-09-03 | |
78 | ================= | |
79 | * Update URLs and badges in README | |
80 | ||
81 | 1.0.0 / 2014-08-26 | |
82 | ================= | |
83 | * v1.0.0 | |
84 | ||
85 | 0.6.1 / 2014-08-25 | |
86 | ================= | |
87 | * v0.6.1 | |
88 | * Updating dependencies (tape, covert, is) | |
89 | * Update badges in readme | |
90 | * Use separate var statements | |
91 | ||
92 | 0.6.0 / 2014-04-23 | |
93 | ================= | |
94 | * v0.6.0 | |
95 | * Updating dependencies (tape, covert) | |
96 | * Make sure boxed primitives, and arguments objects, work properly in ES3 browsers | |
97 | * Improve test matrix: test all node versions, but only latest two stables are a failure | |
98 | * Remove internal foreach shim. | |
99 | ||
100 | 0.5.1 / 2014-03-09 | |
101 | ================= | |
102 | * 0.5.1 | |
103 | * Updating dependencies (tape, covert, is) | |
104 | * Removing forEach from the module (but keeping it in tests) | |
105 | ||
106 | 0.5.0 / 2014-01-30 | |
107 | ================= | |
108 | * 0.5.0 | |
109 | * Explicitly returning the shim, instead of returning native Object.keys when present | |
110 | * Adding a changelog. | |
111 | * Cleaning up IIFE wrapping | |
112 | * Testing on node 0.4 through 0.11 | |
113 | ||
114 | 0.4.0 / 2013-08-14 | |
115 | ================== | |
116 | ||
117 | * v0.4.0 | |
118 | * In Chrome 4-10 and Safari 4, typeof (new RegExp) === 'function' | |
119 | * If it's a string, make sure to use charAt instead of brackets. | |
120 | * Only use Function#call if necessary. | |
121 | * Making sure the context tests actually run. | |
122 | * Better function detection | |
123 | * Adding the android browser | |
124 | * Fixing testling files | |
125 | * Updating tape | |
126 | * Removing the "is" dependency. | |
127 | * Making an isArguments shim. | |
128 | * Adding a local forEach shim and tests. | |
129 | * Updating paths. | |
130 | * Moving the shim test. | |
131 | * v0.3.0 | |
132 | ||
133 | 0.3.0 / 2013-05-18 | |
134 | ================== | |
135 | ||
136 | * README tweak. | |
137 | * Fixing constructor enum issue. Fixes [#5](https://github.com/ljharb/object-keys/issues/5). | |
138 | * Adding a test for [#5](https://github.com/ljharb/object-keys/issues/5) | |
139 | * Updating readme. | |
140 | * Updating dependencies. | |
141 | * Giving credit to lodash. | |
142 | * Make sure that a prototype's constructor property is not enumerable. Fixes [#3](https://github.com/ljharb/object-keys/issues/3). | |
143 | * Adding additional tests to handle arguments objects, and to skip "prototype" in functions. Fixes [#2](https://github.com/ljharb/object-keys/issues/2). | |
144 | * Fixing a typo on this test for [#3](https://github.com/ljharb/object-keys/issues/3). | |
145 | * Adding node 0.10 to travis. | |
146 | * Adding an IE < 9 test per [#3](https://github.com/ljharb/object-keys/issues/3) | |
147 | * Adding an iOS 5 mobile Safari test per [#2](https://github.com/ljharb/object-keys/issues/2) | |
148 | * Moving "indexof" and "is" to be dev dependencies. | |
149 | * Making sure the shim works with functions. | |
150 | * Flattening the tests. | |
151 | ||
152 | 0.2.0 / 2013-05-10 | |
153 | ================== | |
154 | ||
155 | * v0.2.0 | |
156 | * Object.keys should work with arrays. | |
157 | ||
158 | 0.1.8 / 2013-05-10 | |
159 | ================== | |
160 | ||
161 | * v0.1.8 | |
162 | * Upgrading dependencies. | |
163 | * Using a simpler check. | |
164 | * Fixing a bug in hasDontEnumBug browsers. | |
165 | * Using the newest tape! | |
166 | * Fixing this error test. | |
167 | * "undefined" is probably a reserved word in ES3. | |
168 | * Better test message. | |
169 | ||
170 | 0.1.7 / 2013-04-17 | |
171 | ================== | |
172 | ||
173 | * Upgrading "is" once more. | |
174 | * The key "null" is breaking some browsers. | |
175 | ||
176 | 0.1.6 / 2013-04-17 | |
177 | ================== | |
178 | ||
179 | * v0.1.6 | |
180 | * Upgrading "is" | |
181 | ||
182 | 0.1.5 / 2013-04-14 | |
183 | ================== | |
184 | ||
185 | * Bumping version. | |
186 | * Adding more testling browsers. | |
187 | * Updating "is" | |
188 | ||
189 | 0.1.4 / 2013-04-08 | |
190 | ================== | |
191 | ||
192 | * Using "is" instead of "is-extended". | |
193 | ||
194 | 0.1.3 / 2013-04-07 | |
195 | ================== | |
196 | ||
197 | * Using "foreach" instead of my own shim. | |
198 | * Removing "tap"; I'll just wait for "tape" to fix its node 0.10 bug. | |
199 | ||
200 | 0.1.2 / 2013-04-03 | |
201 | ================== | |
202 | ||
203 | * Adding dependency status; moving links to an index at the bottom. | |
204 | * Upgrading is-extended; version 0.1.2 | |
205 | * Adding an npm version badge. | |
206 | ||
207 | 0.1.1 / 2013-04-01 | |
208 | ================== | |
209 | ||
210 | * Adding Travis CI. | |
211 | * Bumping the version. | |
212 | * Adding indexOf since IE sucks. | |
213 | * Adding a forEach shim since older browsers don't have Array#forEach. | |
214 | * Upgrading tape - 0.3.2 uses Array#map | |
215 | * Using explicit end instead of plan. | |
216 | * Can't test with Array.isArray in older browsers. | |
217 | * Using is-extended. | |
218 | * Fixing testling files. | |
219 | * JSHint/JSLint-ing. | |
220 | * Removing an unused object. | |
221 | * Using strict mode. | |
222 | ||
223 | 0.1.0 / 2013-03-30 | |
224 | ================== | |
225 | ||
226 | * Changing the exports should have meant a higher version bump. | |
227 | * Oops, fixing the repo URL. | |
228 | * Adding more tests. | |
229 | * 0.0.2 | |
230 | * Merge branch 'export_one_thing'; closes [#1](https://github.com/ljharb/object-keys/issues/1) | |
231 | * Move shim export to a separate file. |
0 | The MIT License (MIT) | |
1 | ||
2 | Copyright (C) 2013 Jordan Harband | |
3 | ||
4 | Permission is hereby granted, free of charge, to any person obtaining a copy | |
5 | of this software and associated documentation files (the "Software"), to deal | |
6 | in the Software without restriction, including without limitation the rights | |
7 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | |
8 | copies of the Software, and to permit persons to whom the Software is | |
9 | furnished to do so, subject to the following conditions: | |
10 | ||
11 | The above copyright notice and this permission notice shall be included in | |
12 | all copies or substantial portions of the Software. | |
13 | ||
14 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | |
15 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | |
16 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | |
17 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | |
18 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | |
19 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN | |
20 | THE SOFTWARE.⏎ |
0 | #object-keys <sup>[![Version Badge][npm-version-svg]][package-url]</sup> | |
1 | ||
2 | [![Build Status][travis-svg]][travis-url] | |
3 | [![dependency status][deps-svg]][deps-url] | |
4 | [![dev dependency status][dev-deps-svg]][dev-deps-url] | |
5 | [![License][license-image]][license-url] | |
6 | [![Downloads][downloads-image]][downloads-url] | |
7 | ||
8 | [![npm badge][npm-badge-png]][package-url] | |
9 | ||
10 | [![browser support][testling-svg]][testling-url] | |
11 | ||
12 | An Object.keys shim. Invoke its "shim" method to shim Object.keys if it is unavailable. | |
13 | ||
14 | Most common usage: | |
15 | ```js | |
16 | var keys = Object.keys || require('object-keys'); | |
17 | ``` | |
18 | ||
19 | ## Example | |
20 | ||
21 | ```js | |
22 | var keys = require('object-keys'); | |
23 | var assert = require('assert'); | |
24 | var obj = { | |
25 | a: true, | |
26 | b: true, | |
27 | c: true | |
28 | }; | |
29 | ||
30 | assert.deepEqual(keys(obj), ['a', 'b', 'c']); | |
31 | ``` | |
32 | ||
33 | ```js | |
34 | var keys = require('object-keys'); | |
35 | var assert = require('assert'); | |
36 | /* when Object.keys is not present */ | |
37 | delete Object.keys; | |
38 | var shimmedKeys = keys.shim(); | |
39 | assert.equal(shimmedKeys, keys); | |
40 | assert.deepEqual(Object.keys(obj), keys(obj)); | |
41 | ``` | |
42 | ||
43 | ```js | |
44 | var keys = require('object-keys'); | |
45 | var assert = require('assert'); | |
46 | /* when Object.keys is present */ | |
47 | var shimmedKeys = keys.shim(); | |
48 | assert.equal(shimmedKeys, Object.keys); | |
49 | assert.deepEqual(Object.keys(obj), keys(obj)); | |
50 | ``` | |
51 | ||
52 | ## Source | |
53 | Implementation taken directly from [es5-shim][es5-shim-url], with modifications, including from [lodash][lodash-url]. | |
54 | ||
55 | ## Tests | |
56 | Simply clone the repo, `npm install`, and run `npm test` | |
57 | ||
58 | [package-url]: https://npmjs.org/package/object-keys | |
59 | [npm-version-svg]: http://versionbadg.es/ljharb/object-keys.svg | |
60 | [travis-svg]: https://travis-ci.org/ljharb/object-keys.svg | |
61 | [travis-url]: https://travis-ci.org/ljharb/object-keys | |
62 | [deps-svg]: https://david-dm.org/ljharb/object-keys.svg | |
63 | [deps-url]: https://david-dm.org/ljharb/object-keys | |
64 | [dev-deps-svg]: https://david-dm.org/ljharb/object-keys/dev-status.svg | |
65 | [dev-deps-url]: https://david-dm.org/ljharb/object-keys#info=devDependencies | |
66 | [testling-svg]: https://ci.testling.com/ljharb/object-keys.png | |
67 | [testling-url]: https://ci.testling.com/ljharb/object-keys | |
68 | [es5-shim-url]: https://github.com/es-shims/es5-shim/blob/master/es5-shim.js#L542-589 | |
69 | [lodash-url]: https://github.com/lodash/lodash | |
70 | [npm-badge-png]: https://nodei.co/npm/object-keys.png?downloads=true&stars=true | |
71 | [license-image]: http://img.shields.io/npm/l/object-keys.svg | |
72 | [license-url]: LICENSE | |
73 | [downloads-image]: http://img.shields.io/npm/dm/object-keys.svg | |
74 | [downloads-url]: http://npm-stat.com/charts.html?package=object-keys | |
75 |
0 | 'use strict'; | |
1 | ||
2 | var keysShim; | |
3 | if (!Object.keys) { | |
4 | // modified from https://github.com/es-shims/es5-shim | |
5 | var has = Object.prototype.hasOwnProperty; | |
6 | var toStr = Object.prototype.toString; | |
7 | var isArgs = require('./isArguments'); // eslint-disable-line global-require | |
8 | var isEnumerable = Object.prototype.propertyIsEnumerable; | |
9 | var hasDontEnumBug = !isEnumerable.call({ toString: null }, 'toString'); | |
10 | var hasProtoEnumBug = isEnumerable.call(function () {}, 'prototype'); | |
11 | var dontEnums = [ | |
12 | 'toString', | |
13 | 'toLocaleString', | |
14 | 'valueOf', | |
15 | 'hasOwnProperty', | |
16 | 'isPrototypeOf', | |
17 | 'propertyIsEnumerable', | |
18 | 'constructor' | |
19 | ]; | |
20 | var equalsConstructorPrototype = function (o) { | |
21 | var ctor = o.constructor; | |
22 | return ctor && ctor.prototype === o; | |
23 | }; | |
24 | var excludedKeys = { | |
25 | $applicationCache: true, | |
26 | $console: true, | |
27 | $external: true, | |
28 | $frame: true, | |
29 | $frameElement: true, | |
30 | $frames: true, | |
31 | $innerHeight: true, | |
32 | $innerWidth: true, | |
33 | $onmozfullscreenchange: true, | |
34 | $onmozfullscreenerror: true, | |
35 | $outerHeight: true, | |
36 | $outerWidth: true, | |
37 | $pageXOffset: true, | |
38 | $pageYOffset: true, | |
39 | $parent: true, | |
40 | $scrollLeft: true, | |
41 | $scrollTop: true, | |
42 | $scrollX: true, | |
43 | $scrollY: true, | |
44 | $self: true, | |
45 | $webkitIndexedDB: true, | |
46 | $webkitStorageInfo: true, | |
47 | $window: true | |
48 | }; | |
49 | var hasAutomationEqualityBug = (function () { | |
50 | /* global window */ | |
51 | if (typeof window === 'undefined') { return false; } | |
52 | for (var k in window) { | |
53 | try { | |
54 | if (!excludedKeys['$' + k] && has.call(window, k) && window[k] !== null && typeof window[k] === 'object') { | |
55 | try { | |
56 | equalsConstructorPrototype(window[k]); | |
57 | } catch (e) { | |
58 | return true; | |
59 | } | |
60 | } | |
61 | } catch (e) { | |
62 | return true; | |
63 | } | |
64 | } | |
65 | return false; | |
66 | }()); | |
67 | var equalsConstructorPrototypeIfNotBuggy = function (o) { | |
68 | /* global window */ | |
69 | if (typeof window === 'undefined' || !hasAutomationEqualityBug) { | |
70 | return equalsConstructorPrototype(o); | |
71 | } | |
72 | try { | |
73 | return equalsConstructorPrototype(o); | |
74 | } catch (e) { | |
75 | return false; | |
76 | } | |
77 | }; | |
78 | ||
79 | keysShim = function keys(object) { | |
80 | var isObject = object !== null && typeof object === 'object'; | |
81 | var isFunction = toStr.call(object) === '[object Function]'; | |
82 | var isArguments = isArgs(object); | |
83 | var isString = isObject && toStr.call(object) === '[object String]'; | |
84 | var theKeys = []; | |
85 | ||
86 | if (!isObject && !isFunction && !isArguments) { | |
87 | throw new TypeError('Object.keys called on a non-object'); | |
88 | } | |
89 | ||
90 | var skipProto = hasProtoEnumBug && isFunction; | |
91 | if (isString && object.length > 0 && !has.call(object, 0)) { | |
92 | for (var i = 0; i < object.length; ++i) { | |
93 | theKeys.push(String(i)); | |
94 | } | |
95 | } | |
96 | ||
97 | if (isArguments && object.length > 0) { | |
98 | for (var j = 0; j < object.length; ++j) { | |
99 | theKeys.push(String(j)); | |
100 | } | |
101 | } else { | |
102 | for (var name in object) { | |
103 | if (!(skipProto && name === 'prototype') && has.call(object, name)) { | |
104 | theKeys.push(String(name)); | |
105 | } | |
106 | } | |
107 | } | |
108 | ||
109 | if (hasDontEnumBug) { | |
110 | var skipConstructor = equalsConstructorPrototypeIfNotBuggy(object); | |
111 | ||
112 | for (var k = 0; k < dontEnums.length; ++k) { | |
113 | if (!(skipConstructor && dontEnums[k] === 'constructor') && has.call(object, dontEnums[k])) { | |
114 | theKeys.push(dontEnums[k]); | |
115 | } | |
116 | } | |
117 | } | |
118 | return theKeys; | |
119 | }; | |
120 | } | |
121 | module.exports = keysShim; |
0 | 'use strict'; | |
1 | ||
2 | var slice = Array.prototype.slice; | |
3 | var isArgs = require('./isArguments'); | |
4 | ||
5 | var origKeys = Object.keys; | |
6 | var keysShim = origKeys ? function keys(o) { return origKeys(o); } : require('./implementation'); | |
7 | ||
8 | var originalKeys = Object.keys; | |
9 | ||
10 | keysShim.shim = function shimObjectKeys() { | |
11 | if (Object.keys) { | |
12 | var keysWorksWithArguments = (function () { | |
13 | // Safari 5.0 bug | |
14 | var args = Object.keys(arguments); | |
15 | return args && args.length === arguments.length; | |
16 | }(1, 2)); | |
17 | if (!keysWorksWithArguments) { | |
18 | Object.keys = function keys(object) { // eslint-disable-line func-name-matching | |
19 | if (isArgs(object)) { | |
20 | return originalKeys(slice.call(object)); | |
21 | } | |
22 | return originalKeys(object); | |
23 | }; | |
24 | } | |
25 | } else { | |
26 | Object.keys = keysShim; | |
27 | } | |
28 | return Object.keys || keysShim; | |
29 | }; | |
30 | ||
31 | module.exports = keysShim; |
0 | 'use strict'; | |
1 | ||
2 | var toStr = Object.prototype.toString; | |
3 | ||
4 | module.exports = function isArguments(value) { | |
5 | var str = toStr.call(value); | |
6 | var isArgs = str === '[object Arguments]'; | |
7 | if (!isArgs) { | |
8 | isArgs = str !== '[object Array]' && | |
9 | value !== null && | |
10 | typeof value === 'object' && | |
11 | typeof value.length === 'number' && | |
12 | value.length >= 0 && | |
13 | toStr.call(value.callee) === '[object Function]'; | |
14 | } | |
15 | return isArgs; | |
16 | }; |
0 | { | |
1 | "name": "object-keys", | |
2 | "version": "1.1.1", | |
3 | "author": { | |
4 | "name": "Jordan Harband", | |
5 | "email": "ljharb@gmail.com", | |
6 | "url": "http://ljharb.codes" | |
7 | }, | |
8 | "contributors": [ | |
9 | { | |
10 | "name": "Jordan Harband", | |
11 | "email": "ljharb@gmail.com", | |
12 | "url": "http://ljharb.codes" | |
13 | }, | |
14 | { | |
15 | "name": "Raynos", | |
16 | "email": "raynos2@gmail.com" | |
17 | }, | |
18 | { | |
19 | "name": "Nathan Rajlich", | |
20 | "email": "nathan@tootallnate.net" | |
21 | }, | |
22 | { | |
23 | "name": "Ivan Starkov", | |
24 | "email": "istarkov@gmail.com" | |
25 | }, | |
26 | { | |
27 | "name": "Gary Katsevman", | |
28 | "email": "git@gkatsev.com" | |
29 | } | |
30 | ], | |
31 | "description": "An Object.keys replacement, in case Object.keys is not available. From https://github.com/es-shims/es5-shim", | |
32 | "license": "MIT", | |
33 | "main": "index.js", | |
34 | "scripts": { | |
35 | "pretest": "npm run --silent lint", | |
36 | "test": "npm run --silent tests-only", | |
37 | "posttest": "npm run --silent audit", | |
38 | "tests-only": "node test/index.js", | |
39 | "coverage": "covert test/*.js", | |
40 | "coverage-quiet": "covert test/*.js --quiet", | |
41 | "lint": "eslint .", | |
42 | "preaudit": "npm install --package-lock --package-lock-only", | |
43 | "audit": "npm audit", | |
44 | "postaudit": "rm package-lock.json" | |
45 | }, | |
46 | "repository": { | |
47 | "type": "git", | |
48 | "url": "git://github.com/ljharb/object-keys.git" | |
49 | }, | |
50 | "keywords": [ | |
51 | "Object.keys", | |
52 | "keys", | |
53 | "ES5", | |
54 | "shim" | |
55 | ], | |
56 | "dependencies": {}, | |
57 | "devDependencies": { | |
58 | "@ljharb/eslint-config": "^13.1.1", | |
59 | "covert": "^1.1.1", | |
60 | "eslint": "^5.13.0", | |
61 | "foreach": "^2.0.5", | |
62 | "indexof": "^0.0.1", | |
63 | "is": "^3.3.0", | |
64 | "tape": "^4.9.2" | |
65 | }, | |
66 | "testling": { | |
67 | "files": "test/index.js", | |
68 | "browsers": [ | |
69 | "iexplore/6.0..latest", | |
70 | "firefox/3.0..6.0", | |
71 | "firefox/15.0..latest", | |
72 | "firefox/nightly", | |
73 | "chrome/4.0..10.0", | |
74 | "chrome/20.0..latest", | |
75 | "chrome/canary", | |
76 | "opera/10.0..latest", | |
77 | "opera/next", | |
78 | "safari/4.0..latest", | |
79 | "ipad/6.0..latest", | |
80 | "iphone/6.0..latest", | |
81 | "android-browser/4.2" | |
82 | ] | |
83 | }, | |
84 | "engines": { | |
85 | "node": ">= 0.4" | |
86 | } | |
87 | } |
0 | { | |
1 | "rules": { | |
2 | "array-bracket-newline": 0, | |
3 | "array-element-newline": 0, | |
4 | "max-nested-callbacks": 0, | |
5 | "no-magic-numbers": 0, | |
6 | } | |
7 | } |
0 | 'use strict'; | |
1 | ||
2 | var test = require('tape'); | |
3 | var isArguments = require('../isArguments'); | |
4 | ||
5 | test('is.arguments', function (t) { | |
6 | t.notOk(isArguments([]), 'array is not arguments'); | |
7 | (function () { t.ok(isArguments(arguments), 'arguments is arguments'); }()); | |
8 | (function () { t.notOk(isArguments(Array.prototype.slice.call(arguments)), 'sliced arguments is not arguments'); }()); | |
9 | var fakeOldArguments = { | |
10 | callee: function () {}, | |
11 | length: 3 | |
12 | }; | |
13 | t.ok(isArguments(fakeOldArguments), 'old-style arguments is arguments'); | |
14 | t.end(); | |
15 | }); |
0 | /* global window */ | |
1 | ||
2 | 'use strict'; | |
3 | ||
4 | var test = require('tape'); | |
5 | var is = require('is'); | |
6 | var keysShim; | |
7 | var reRequire = function reRequireImplementation() { | |
8 | delete require.cache[require.resolve('../implementation')]; | |
9 | delete require.cache[require.resolve('../')]; | |
10 | keysShim = require('../'); // eslint-disable-line global-require | |
11 | }; | |
12 | reRequire(); | |
13 | ||
14 | var indexOf = require('indexof'); | |
15 | var has = Object.prototype.hasOwnProperty; | |
16 | var enumerable = Object.prototype.propertyIsEnumerable; | |
17 | ||
18 | var obj = { | |
19 | aNull: null, | |
20 | arr: [], | |
21 | bool: true, | |
22 | num: 42, | |
23 | obj: {}, | |
24 | str: 'boz', | |
25 | undef: undefined | |
26 | }; | |
27 | var objKeys = ['aNull', 'arr', 'bool', 'num', 'obj', 'str', 'undef']; | |
28 | ||
29 | var returnEmptyArray = function () { return []; }; | |
30 | var preserve = function preserveProperty(object, property, callback) { | |
31 | reRequire(); | |
32 | return function preserved() { | |
33 | var original = object[property]; | |
34 | try { | |
35 | return callback.apply(this, arguments); | |
36 | } finally { | |
37 | object[property] = original; | |
38 | // eslint-disable-next-line no-unsafe-finally | |
39 | if (object[property] !== original) { throw new EvalError('should never happen'); } | |
40 | reRequire(); | |
41 | } | |
42 | }; | |
43 | }; | |
44 | ||
45 | test('exports a "shim" function', function (t) { | |
46 | t.equal(typeof keysShim.shim, 'function', 'keysShim.shim is a function'); | |
47 | ||
48 | t.test('when Object.keys is present', preserve(Object, 'keys', function (st) { | |
49 | Object.keys = returnEmptyArray; | |
50 | st.equal(Object.keys, returnEmptyArray, 'Object.keys has been replaced'); | |
51 | var shimmedKeys = keysShim.shim(); | |
52 | st.notEqual(Object.keys, keysShim, 'Object.keys is not overridden to the shim'); | |
53 | st.notEqual(Object.keys, returnEmptyArray, 'Object.keys is overridden, is not returnEmptyArray'); | |
54 | st.equal(shimmedKeys, Object.keys, 'Object.keys is returned'); | |
55 | st.end(); | |
56 | })); | |
57 | ||
58 | t.test('when Object.keys is not present', { skip: Object.keys }, preserve(Object, 'keys', function (st) { | |
59 | st.notOk(Object.keys, 'Object.keys does not exist'); | |
60 | var shimmedKeys = keysShim.shim(); | |
61 | ||
62 | st.equal(Object.keys, keysShim, 'Object.keys is overridden'); | |
63 | st.equal(shimmedKeys, keysShim, 'shim is returned'); | |
64 | ||
65 | st.end(); | |
66 | })); | |
67 | ||
68 | t.test('when Object.keys has arguments bug', preserve(Object, 'keys', function (st) { | |
69 | st.deepEqual(arguments.length, 1, 'arguments has expected length'); | |
70 | ||
71 | var originalObjectKeys = Object.keys; | |
72 | var fakeKeys = function keys(object) { | |
73 | if (is.args(object)) { return []; } | |
74 | return originalObjectKeys(object); | |
75 | }; | |
76 | Object.keys = fakeKeys; | |
77 | st.deepEqual(Object.keys(arguments), [], 'Object.keys has arguments bug'); | |
78 | var shimmedKeys = keysShim.shim(); | |
79 | st.notEqual(fakeKeys, shimmedKeys, 'Object.keys is not original fake value'); | |
80 | st.equal(Object.keys, shimmedKeys, 'Object.keys is overridden'); | |
81 | st.deepEqual(Object.keys(arguments), ['0'], 'Object.keys now works with arguments'); | |
82 | st.end(); | |
83 | })); | |
84 | ||
85 | t.end(); | |
86 | }); | |
87 | ||
88 | test('working with actual shim', function (t) { | |
89 | t.notEqual(Object.keys, keysShim, 'keys shim is not native Object.keys'); | |
90 | t.end(); | |
91 | }); | |
92 | ||
93 | test('works with an object literal', function (t) { | |
94 | var theKeys = keysShim(obj); | |
95 | t.equal(is.array(theKeys), true, 'returns an array'); | |
96 | t.deepEqual(theKeys, objKeys, 'Object has expected keys'); | |
97 | t.end(); | |
98 | }); | |
99 | ||
100 | test('works with an arguments object', function (t) { | |
101 | (function () { | |
102 | t.equal(arguments.length, 3, 'arguments has length of 3'); | |
103 | t.deepEqual(keysShim(arguments), ['0', '1', '2'], 'returns keys of arguments'); | |
104 | }(1, 2, 3)); | |
105 | t.end(); | |
106 | }); | |
107 | ||
108 | test('works with a boxed primitive', function (t) { | |
109 | t.deepEqual(keysShim(Object('hello')), ['0', '1', '2', '3', '4'], 'object string returns proper keys'); | |
110 | /* eslint-disable no-new-wrappers */ | |
111 | t.deepEqual(keysShim(new String('hello')), ['0', '1', '2', '3', '4'], 'String object returns proper keys'); | |
112 | ||
113 | var x = new String('x'); | |
114 | /* eslint-enable no-new-wrappers */ | |
115 | x.y = 1; | |
116 | t.deepEqual(keysShim(x).sort(), ['0', 'y'].sort(), 'String object with extra properties returns proper keys'); | |
117 | ||
118 | t.end(); | |
119 | }); | |
120 | ||
121 | test('works with an array', function (t) { | |
122 | var arr = [1, 2, 3]; | |
123 | var theKeys = keysShim(arr); | |
124 | t.equal(is.array(theKeys), true, 'returns an array'); | |
125 | t.deepEqual(theKeys, ['0', '1', '2'], 'Array has expected keys'); | |
126 | t.end(); | |
127 | }); | |
128 | ||
129 | test('works with a function', function (t) { | |
130 | var foo = function () {}; | |
131 | foo.a = true; | |
132 | ||
133 | t.doesNotThrow(function () { return keysShim(foo); }, 'does not throw an error'); | |
134 | t.deepEqual(keysShim(foo), ['a'], 'returns expected keys'); | |
135 | t.end(); | |
136 | }); | |
137 | ||
138 | test('returns names which are own properties', function (t) { | |
139 | var theKeys = keysShim(obj); | |
140 | for (var i = 0; i < theKeys.length; ++i) { | |
141 | t.equal(has.call(obj, theKeys[i]), true, theKeys[i] + ' should be returned'); | |
142 | } | |
143 | t.end(); | |
144 | }); | |
145 | ||
146 | test('returns names which are enumerable', function (t) { | |
147 | var k; | |
148 | var loopedValues = []; | |
149 | for (k in obj) { | |
150 | if (enumerable.call(obj, k)) { | |
151 | loopedValues.push(k); | |
152 | } | |
153 | } | |
154 | var theKeys = keysShim(obj); | |
155 | for (var i = 0; i < theKeys.length; ++i) { | |
156 | t.notEqual(indexOf(loopedValues, theKeys[i]), -1, theKeys[i] + ' is not enumerable'); | |
157 | } | |
158 | t.end(); | |
159 | }); | |
160 | ||
161 | test('throws an error for a non-object', function (t) { | |
162 | t['throws']( | |
163 | function () { return keysShim(null); }, | |
164 | new TypeError('Object.keys called on a non-object'), | |
165 | 'throws on a non-object' | |
166 | ); | |
167 | t.end(); | |
168 | }); | |
169 | ||
170 | test('works with an object instance', function (t) { | |
171 | var Prototype = function () {}; | |
172 | Prototype.prototype.foo = true; | |
173 | var instance = new Prototype(); | |
174 | instance.bar = true; | |
175 | var theKeys = keysShim(instance); | |
176 | t.equal(is.array(theKeys), true, 'returns an array'); | |
177 | t.deepEqual(theKeys, ['bar'], 'Instance has expected keys'); | |
178 | t.end(); | |
179 | }); | |
180 | ||
181 | test('works in iOS 5 mobile Safari', function (t) { | |
182 | var Foo = function () {}; | |
183 | Foo.a = function () {}; | |
184 | ||
185 | // the bug is keysShim(Foo) => ['a', 'prototype'] instead of ['a'] | |
186 | t.deepEqual(keysShim(Foo), ['a'], 'has expected keys'); | |
187 | t.end(); | |
188 | }); | |
189 | ||
190 | test('works in environments with the dontEnum bug (IE < 9)', function (t) { | |
191 | var Foo = function () {}; | |
192 | Foo.prototype.a = function () {}; | |
193 | ||
194 | // the bug is keysShim(Foo.prototype) => ['a', 'constructor'] instead of ['a'] | |
195 | t.deepEqual(keysShim(Foo.prototype), ['a'], 'has expected keys'); | |
196 | t.end(); | |
197 | }); | |
198 | ||
199 | test('shadowed properties', function (t) { | |
200 | var shadowedProps = [ | |
201 | 'dummyControlProp', /* just to be sure */ | |
202 | 'constructor', | |
203 | 'hasOwnProperty', | |
204 | 'isPrototypeOf', | |
205 | 'propertyIsEnumerable', | |
206 | 'toLocaleString', | |
207 | 'toString', | |
208 | 'valueOf' | |
209 | ]; | |
210 | shadowedProps.sort(); | |
211 | var shadowedObject = {}; | |
212 | for (var i = 0; i < shadowedProps.length; ++i) { | |
213 | shadowedObject[shadowedProps[i]] = i; | |
214 | } | |
215 | var shadowedObjectKeys = keysShim(shadowedObject); | |
216 | shadowedObjectKeys.sort(); | |
217 | t.deepEqual(shadowedObjectKeys, shadowedProps, 'troublesome shadowed properties are keys of object literals'); | |
218 | t.end(); | |
219 | }); | |
220 | ||
221 | test('host objects on `window` constructor.prototype equal to themselves', { skip: typeof window === 'undefined' }, function (t) { | |
222 | var keys, exception; | |
223 | var excludedKeys = { | |
224 | $applicationCache: true, | |
225 | $console: true, | |
226 | $external: true, | |
227 | $frame: true, | |
228 | $frameElement: true, | |
229 | $frames: true, | |
230 | $innerHeight: true, | |
231 | $innerWidth: true, | |
232 | $onmozfullscreenchange: true, | |
233 | $onmozfullscreenerror: true, | |
234 | $outerHeight: true, | |
235 | $outerWidth: true, | |
236 | $pageXOffset: true, | |
237 | $pageYOffset: true, | |
238 | $parent: true, | |
239 | $scrollLeft: true, | |
240 | $scrollTop: true, | |
241 | $scrollX: true, | |
242 | $scrollY: true, | |
243 | $self: true, | |
244 | $webkitIndexedDB: true, | |
245 | $webkitStorageInfo: true, | |
246 | $window: true | |
247 | }; | |
248 | for (var k in window) { | |
249 | keys = undefined; | |
250 | exception = undefined; | |
251 | if (!excludedKeys['$' + k] && has.call(window, k) && window[k] !== null && typeof window[k] === 'object') { | |
252 | try { | |
253 | keys = keysShim(window[k]); | |
254 | } catch (e) { | |
255 | exception = e; | |
256 | } | |
257 | t.ok(is.array(keys), 'keys of window["' + k + '"] is an array'); | |
258 | t.equal(exception, undefined, 'there is no exception: window["' + k + '"]'); | |
259 | } | |
260 | } | |
261 | t.end(); | |
262 | }); |
0 | 0 | { |
1 | 1 | "name": "define-properties", |
2 | 2 | "version": "1.1.3", |
3 | "author": "Jordan Harband", | |
3 | "author": "Jordan Harband <ljharb@gmail.com>", | |
4 | "funding": { | |
5 | "url": "https://github.com/sponsors/ljharb" | |
6 | }, | |
4 | 7 | "description": "Define multiple non-enumerable properties at once. Uses `Object.defineProperty` when available; falls back to standard assignment in older engines.", |
5 | 8 | "license": "MIT", |
6 | 9 | "main": "index.js", |
7 | 10 | "scripts": { |
8 | "pretest": "npm run --silent lint", | |
9 | "test": "npm run --silent tests-only", | |
10 | "posttest": "npm run --silent security", | |
11 | "tests-only": "node test/index.js", | |
12 | "coverage": "covert test/*.js", | |
13 | "coverage-quiet": "covert test/*.js --quiet", | |
14 | "lint": "npm run --silent jscs && npm run --silent eslint", | |
15 | "jscs": "jscs test/*.js *.js", | |
16 | "eslint": "eslint test/*.js *.js", | |
17 | "security": "nsp check" | |
11 | "prepublish": "not-in-publish || npm run prepublishOnly", | |
12 | "prepublishOnly": "safe-publish-latest", | |
13 | "pretest": "npm run lint", | |
14 | "test": "npm run tests-only", | |
15 | "posttest": "aud --production", | |
16 | "tests-only": "nyc tape 'test/**/*.js'", | |
17 | "lint": "eslint ." | |
18 | 18 | }, |
19 | 19 | "repository": { |
20 | 20 | "type": "git", |
30 | 30 | "ES5" |
31 | 31 | ], |
32 | 32 | "dependencies": { |
33 | "object-keys": "^1.0.12" | |
33 | "object-keys": "^1.1.1" | |
34 | 34 | }, |
35 | 35 | "devDependencies": { |
36 | "@ljharb/eslint-config": "^13.0.0", | |
37 | "covert": "^1.1.0", | |
38 | "eslint": "^5.3.0", | |
39 | "jscs": "^3.0.7", | |
40 | "nsp": "^3.2.1", | |
41 | "tape": "^4.9.0" | |
36 | "@ljharb/eslint-config": "^17.5.1", | |
37 | "aud": "^1.1.4", | |
38 | "eslint": "^7.24.0", | |
39 | "nyc": "^10.3.2", | |
40 | "safe-publish-latest": "^1.1.4", | |
41 | "tape": "^5.2.2" | |
42 | 42 | }, |
43 | 43 | "testling": { |
44 | 44 | "files": "test/index.js", |
0 | { | |
1 | "rules": { | |
2 | "no-magic-numbers": 0, | |
3 | "array-bracket-newline": 0, | |
4 | "array-element-newline": 0, | |
5 | } | |
6 | } |
0 | 'use strict'; | |
1 | ||
2 | var define = require('../'); | |
3 | var test = require('tape'); | |
4 | var keys = require('object-keys'); | |
5 | ||
6 | var arePropertyDescriptorsSupported = function () { | |
7 | var obj = { a: 1 }; | |
8 | try { | |
9 | Object.defineProperty(obj, 'x', { value: obj }); | |
10 | return obj.x === obj; | |
11 | } catch (e) { /* this is IE 8. */ | |
12 | return false; | |
13 | } | |
14 | }; | |
15 | var descriptorsSupported = !!Object.defineProperty && arePropertyDescriptorsSupported(); | |
16 | ||
17 | var hasSymbols = typeof Symbol === 'function' && typeof Symbol('foo') === 'symbol'; | |
18 | ||
19 | test('defineProperties', function (dt) { | |
20 | dt.test('with descriptor support', { skip: !descriptorsSupported }, function (t) { | |
21 | var getDescriptor = function (value) { | |
22 | return { | |
23 | configurable: true, | |
24 | enumerable: false, | |
25 | value: value, | |
26 | writable: true | |
27 | }; | |
28 | }; | |
29 | ||
30 | var obj = { | |
31 | a: 1, | |
32 | b: 2, | |
33 | c: 3 | |
34 | }; | |
35 | t.deepEqual(keys(obj), ['a', 'b', 'c'], 'all literal-set keys start enumerable'); | |
36 | define(obj, { | |
37 | b: 3, | |
38 | c: 4, | |
39 | d: 5 | |
40 | }); | |
41 | t.deepEqual(obj, { | |
42 | a: 1, | |
43 | b: 2, | |
44 | c: 3 | |
45 | }, 'existing properties were not overridden'); | |
46 | t.deepEqual(Object.getOwnPropertyDescriptor(obj, 'd'), getDescriptor(5), 'new property "d" was added and is not enumerable'); | |
47 | t.deepEqual(['a', 'b', 'c'], keys(obj), 'new keys are not enumerable'); | |
48 | ||
49 | define(obj, { | |
50 | a: 2, | |
51 | b: 3, | |
52 | c: 4 | |
53 | }, { | |
54 | a: function () { return true; }, | |
55 | b: function () { return false; } | |
56 | }); | |
57 | t.deepEqual(obj, { | |
58 | b: 2, | |
59 | c: 3 | |
60 | }, 'properties only overriden when predicate exists and returns true'); | |
61 | t.deepEqual(Object.getOwnPropertyDescriptor(obj, 'd'), getDescriptor(5), 'existing property "d" remained and is not enumerable'); | |
62 | t.deepEqual(Object.getOwnPropertyDescriptor(obj, 'a'), getDescriptor(2), 'existing property "a" was overridden and is not enumerable'); | |
63 | t.deepEqual(['b', 'c'], keys(obj), 'overridden keys are not enumerable'); | |
64 | ||
65 | t.end(); | |
66 | }); | |
67 | ||
68 | dt.test('without descriptor support', { skip: descriptorsSupported }, function (t) { | |
69 | var obj = { | |
70 | a: 1, | |
71 | b: 2, | |
72 | c: 3 | |
73 | }; | |
74 | define(obj, { | |
75 | b: 3, | |
76 | c: 4, | |
77 | d: 5 | |
78 | }); | |
79 | t.deepEqual(obj, { | |
80 | a: 1, | |
81 | b: 2, | |
82 | c: 3, | |
83 | d: 5 | |
84 | }, 'existing properties were not overridden, new properties were added'); | |
85 | ||
86 | define(obj, { | |
87 | a: 2, | |
88 | b: 3, | |
89 | c: 4 | |
90 | }, { | |
91 | a: function () { return true; }, | |
92 | b: function () { return false; } | |
93 | }); | |
94 | t.deepEqual(obj, { | |
95 | a: 2, | |
96 | b: 2, | |
97 | c: 3, | |
98 | d: 5 | |
99 | }, 'properties only overriden when predicate exists and returns true'); | |
100 | ||
101 | t.end(); | |
102 | }); | |
103 | ||
104 | dt.end(); | |
105 | }); | |
106 | ||
107 | test('symbols', { skip: !hasSymbols }, function (t) { | |
108 | var sym = Symbol('foo'); | |
109 | var obj = {}; | |
110 | var aValue = {}; | |
111 | var bValue = {}; | |
112 | var properties = { a: aValue }; | |
113 | properties[sym] = bValue; | |
114 | ||
115 | define(obj, properties); | |
116 | ||
117 | t.deepEqual(Object.keys(obj), [], 'object has no enumerable keys'); | |
118 | t.deepEqual(Object.getOwnPropertyNames(obj), ['a'], 'object has non-enumerable "a" key'); | |
119 | t.deepEqual(Object.getOwnPropertySymbols(obj), [sym], 'object has non-enumerable symbol key'); | |
120 | t.equal(obj.a, aValue, 'string keyed value is defined'); | |
121 | t.equal(obj[sym], bValue, 'symbol keyed value is defined'); | |
122 | ||
123 | t.end(); | |
124 | }); |