@cjser/npm-email 5.1.0-cjser.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.
@@ -0,0 +1,68 @@
1
+ var __create = Object.create;
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __getProtoOf = Object.getPrototypeOf;
6
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
7
+ var __export = (target, all) => {
8
+ for (var name in all)
9
+ __defProp(target, name, { get: all[name], enumerable: true });
10
+ };
11
+ var __copyProps = (to, from, except, desc) => {
12
+ if (from && typeof from === "object" || typeof from === "function") {
13
+ for (let key of __getOwnPropNames(from))
14
+ if (!__hasOwnProp.call(to, key) && key !== except)
15
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
16
+ }
17
+ return to;
18
+ };
19
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
20
+ // If the importer is in node compatibility mode or this is not an ESM
21
+ // file that has been converted to a CommonJS file using a Babel-
22
+ // compatible transform (i.e. "__esModule" has not been set), then set
23
+ // "default" to the CommonJS "module.exports" for node compatibility.
24
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
25
+ mod
26
+ ));
27
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
28
+
29
+ // packages/@cjser/npm-email.tmp-26-1778153776826/index.js
30
+ var index_exports = {};
31
+ __export(index_exports, {
32
+ default: () => npmEmail
33
+ });
34
+ module.exports = __toCommonJS(index_exports);
35
+ var import_ky_v1_14_3 = __toESM(require("@cjser/ky__v1_14_3"), 1);
36
+ async function npmEmail(username) {
37
+ var _a;
38
+ if (typeof username !== "string") {
39
+ throw new TypeError("Username required");
40
+ }
41
+ const url = new URL(`https://registry.npmjs.com/-/v1/search?&text=maintainer:${encodeURIComponent(username)}`);
42
+ try {
43
+ const { objects: results, total } = await (0, import_ky_v1_14_3.default)(url).json();
44
+ if (total === 0) {
45
+ return;
46
+ }
47
+ results.sort((a, b) => b.package.date.localeCompare(a.package.date));
48
+ for (const { package: package_ } of results) {
49
+ const users = [
50
+ package_.author,
51
+ package_.publisher,
52
+ ...package_.maintainers
53
+ ];
54
+ for (const user of users) {
55
+ if ((user == null ? void 0 : user.username) === username && typeof (user == null ? void 0 : user.email) === "string" && (user == null ? void 0 : user.email) !== "") {
56
+ return user.email;
57
+ }
58
+ }
59
+ }
60
+ } catch (error) {
61
+ if (((_a = error == null ? void 0 : error.response) == null ? void 0 : _a.status) === 404) {
62
+ const notFoundError = new Error(`User \`${username}\` could not be found`, { cause: error });
63
+ notFoundError.code = "ERR_NO_NPM_USER";
64
+ throw notFoundError;
65
+ }
66
+ throw error;
67
+ }
68
+ }
package/index.d.ts ADDED
@@ -0,0 +1,15 @@
1
+ /**
2
+ Get the email of an npm user.
3
+
4
+ @param username - The npm username to look up.
5
+ @returns The user's email address, or `undefined` if the user does not exist or the email could not be found.
6
+
7
+ @example
8
+ ```
9
+ import npmEmail from npm-email';
10
+
11
+ console.log(await npmEmail('sindresorhus'));
12
+ //=> 'sindresorhus@gmail.com'
13
+ ```
14
+ */
15
+ export default function npmEmail(username: string): Promise<string | undefined>;
package/index.js ADDED
@@ -0,0 +1,41 @@
1
+ import ky from '@cjser/ky__v1_14_3';
2
+
3
+ export default async function npmEmail(username) {
4
+ if (typeof username !== 'string') {
5
+ throw new TypeError('Username required');
6
+ }
7
+
8
+ const url = new URL(`https://registry.npmjs.com/-/v1/search?&text=maintainer:${encodeURIComponent(username)}`);
9
+
10
+ try {
11
+ const {objects: results, total} = await ky(url).json();
12
+
13
+ if (total === 0) {
14
+ return;
15
+ }
16
+
17
+ results.sort((a, b) => b.package.date.localeCompare(a.package.date));
18
+
19
+ for (const {package: package_} of results) {
20
+ const users = [
21
+ package_.author,
22
+ package_.publisher,
23
+ ...package_.maintainers,
24
+ ];
25
+
26
+ for (const user of users) {
27
+ if (user?.username === username && typeof user?.email === 'string' && user?.email !== '') {
28
+ return user.email;
29
+ }
30
+ }
31
+ }
32
+ } catch (error) {
33
+ if (error?.response?.status === 404) {
34
+ const notFoundError = new Error(`User \`${username}\` could not be found`, {cause: error});
35
+ notFoundError.code = 'ERR_NO_NPM_USER';
36
+ throw notFoundError;
37
+ }
38
+
39
+ throw error;
40
+ }
41
+ }
package/license ADDED
@@ -0,0 +1,9 @@
1
+ MIT License
2
+
3
+ Copyright (c) Sindre Sorhus <sindresorhus@gmail.com> (https://sindresorhus.com)
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
6
+
7
+ The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
8
+
9
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
package/package.json ADDED
@@ -0,0 +1,77 @@
1
+ {
2
+ "name": "@cjser/npm-email",
3
+ "version": "5.1.0-cjser.2",
4
+ "description": "Get the email of an npm user",
5
+ "license": "MIT",
6
+ "repository": {
7
+ "type": "git",
8
+ "url": "https://code.moenext.com/3rdeye/cjser.git"
9
+ },
10
+ "funding": "https://github.com/sponsors/sindresorhus",
11
+ "author": {
12
+ "name": "Sindre Sorhus",
13
+ "email": "sindresorhus@gmail.com",
14
+ "url": "https://sindresorhus.com"
15
+ },
16
+ "type": "module",
17
+ "exports": {
18
+ "types": "./index.d.ts",
19
+ "require": "./dist-cjser/index.cjs",
20
+ "default": "./index.js"
21
+ },
22
+ "sideEffects": false,
23
+ "engines": {
24
+ "node": ">=18"
25
+ },
26
+ "scripts": {
27
+ "test": "xo && ava && tsd"
28
+ },
29
+ "files": [
30
+ "index.js",
31
+ "index.d.ts",
32
+ "dist-cjser"
33
+ ],
34
+ "keywords": [
35
+ "npm",
36
+ "email",
37
+ "address",
38
+ "user",
39
+ "username",
40
+ "registry",
41
+ "json",
42
+ "get"
43
+ ],
44
+ "dependencies": {
45
+ "@cjser/ky__v1_14_3": "1.14.3-cjser.2"
46
+ },
47
+ "devDependencies": {
48
+ "ava": "^6.1.1",
49
+ "tsd": "^0.30.7",
50
+ "xo": "^0.57.0"
51
+ },
52
+ "types": "./index.d.ts",
53
+ "main": "./dist-cjser/index.cjs",
54
+ "cjser": {
55
+ "sourceVersion": "5.1.0",
56
+ "cjserVersion": 2,
57
+ "original": {
58
+ "name": "npm-email",
59
+ "version": "5.1.0",
60
+ "exports": {
61
+ "types": "./index.d.ts",
62
+ "default": "./index.js"
63
+ },
64
+ "repository": "sindresorhus/npm-email",
65
+ "dependencies": {
66
+ "ky": "^1.2.1"
67
+ },
68
+ "files": [
69
+ "index.js",
70
+ "index.d.ts"
71
+ ],
72
+ "scripts": {
73
+ "test": "xo && ava && tsd"
74
+ }
75
+ }
76
+ }
77
+ }
package/readme.md ADDED
@@ -0,0 +1,42 @@
1
+ # npm-email
2
+
3
+ > Get the email of an npm user
4
+
5
+ ## Install
6
+
7
+ ```sh
8
+ npm install npm-email
9
+ ```
10
+
11
+ ## Usage
12
+
13
+ ```js
14
+ import npmEmail from 'npm-email';
15
+
16
+ console.log(await npmEmail('sindresorhus'));
17
+ //=> 'sindresorhus@gmail.com'
18
+ ```
19
+
20
+ ## API
21
+
22
+ ### npmEmail(username)
23
+
24
+ Returns a promise for the user's email address, or `undefined` if the user does not exist or the email could not be found.
25
+
26
+ #### username
27
+
28
+ Type: `string`
29
+
30
+ The npm username to look up.
31
+
32
+ ## Related
33
+
34
+ - [npm-email-cli](https://github.com/sindresorhus/npm-email-cli) - CLI for this module
35
+ - [npm-keyword](https://github.com/sindresorhus/npm-keyword) - Get a list of npm packages with a certain keyword
36
+ - [package-json](https://github.com/sindresorhus/package-json) - Get the package.json of a package from the npm registry
37
+ - [npm-user](https://github.com/sindresorhus/npm-user) - Get user info of an npm user
38
+
39
+ ## cjser
40
+
41
+ This package is a CommonJS-compatible build generated by cjser for projects that still need `require()` support. The source version matches the original npm package version, with a cjser prerelease suffix for this generated build.
42
+ Original repository: https://github.com/sindresorhus/npm-email