@cjser/npm-keyword 8.0.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.
- package/dist-cjser/index.cjs +70 -0
- package/index.d.ts +63 -0
- package/index.js +37 -0
- package/license +9 -0
- package/package.json +79 -0
- package/readme.md +96 -0
|
@@ -0,0 +1,70 @@
|
|
|
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-keyword.tmp-26-1778153805526/index.js
|
|
30
|
+
var index_exports = {};
|
|
31
|
+
__export(index_exports, {
|
|
32
|
+
npmKeyword: () => npmKeyword,
|
|
33
|
+
npmKeywordCount: () => npmKeywordCount,
|
|
34
|
+
npmKeywordNames: () => npmKeywordNames
|
|
35
|
+
});
|
|
36
|
+
module.exports = __toCommonJS(index_exports);
|
|
37
|
+
var import_ky_v1_14_3 = __toESM(require("@cjser/ky__v1_14_3"), 1);
|
|
38
|
+
var import_registry_url_v6_0_1 = __toESM(require("@cjser/registry-url__v6_0_1"), 1);
|
|
39
|
+
var get = async (keyword, { size = 250 } = {}) => {
|
|
40
|
+
if (typeof keyword !== "string" && !Array.isArray(keyword)) {
|
|
41
|
+
throw new TypeError("The keyword must be either a string or an array of strings");
|
|
42
|
+
}
|
|
43
|
+
if (size === 0 || size > 250) {
|
|
44
|
+
throw new TypeError("The `size` option must be in the range 1...250");
|
|
45
|
+
}
|
|
46
|
+
keyword = encodeURIComponent(keyword).replace("%2C", "+");
|
|
47
|
+
const url = `${(0, import_registry_url_v6_0_1.default)()}-/v1/search?text=keywords:${keyword}&size=${size}`;
|
|
48
|
+
return (0, import_ky_v1_14_3.default)(url).json();
|
|
49
|
+
};
|
|
50
|
+
async function npmKeyword(keyword, options) {
|
|
51
|
+
const { objects } = await get(keyword, options);
|
|
52
|
+
return objects.map((element) => ({
|
|
53
|
+
name: element.package.name,
|
|
54
|
+
description: element.package.description
|
|
55
|
+
}));
|
|
56
|
+
}
|
|
57
|
+
async function npmKeywordNames(keyword, options) {
|
|
58
|
+
const { objects } = await get(keyword, options);
|
|
59
|
+
return objects.map((element) => element.package.name);
|
|
60
|
+
}
|
|
61
|
+
async function npmKeywordCount(keyword) {
|
|
62
|
+
const { total } = await get(keyword, { size: 1 });
|
|
63
|
+
return total;
|
|
64
|
+
}
|
|
65
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
66
|
+
0 && (module.exports = {
|
|
67
|
+
npmKeyword,
|
|
68
|
+
npmKeywordCount,
|
|
69
|
+
npmKeywordNames
|
|
70
|
+
});
|
package/index.d.ts
ADDED
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
export type Options = {
|
|
2
|
+
/**
|
|
3
|
+
Limits the amount of results.
|
|
4
|
+
|
|
5
|
+
@default 250
|
|
6
|
+
*/
|
|
7
|
+
readonly size?: number;
|
|
8
|
+
};
|
|
9
|
+
|
|
10
|
+
export type PackageDescriptor = {
|
|
11
|
+
readonly name: string;
|
|
12
|
+
readonly description: string;
|
|
13
|
+
};
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
Get a list of npm packages with certain keywords.
|
|
17
|
+
|
|
18
|
+
@param keyword - One or more keywords. Only matches packages that have *all* the given keywords.
|
|
19
|
+
@returns A list of packages having the specified keywords in their package.json `keyword` property.
|
|
20
|
+
|
|
21
|
+
@example
|
|
22
|
+
```
|
|
23
|
+
import {npmKeyword} from '@cjser/npm-keyword';
|
|
24
|
+
|
|
25
|
+
console.log(await npmKeyword('gulpplugin'));
|
|
26
|
+
//=> [{name: 'gulp-autoprefixer', description: '…'}, …]
|
|
27
|
+
```
|
|
28
|
+
*/
|
|
29
|
+
export function npmKeyword(keyword: string | readonly string[], options?: Options): Promise<PackageDescriptor[]>;
|
|
30
|
+
|
|
31
|
+
/**
|
|
32
|
+
Get a list of npm package names with certain keywords.
|
|
33
|
+
|
|
34
|
+
@param keyword - One or more keywords. Only matches packages that have *all* the given keywords. Example: `['string', 'camelcase']`.
|
|
35
|
+
@returns A list of package names. Use this if you don't need the description as it's faster.
|
|
36
|
+
|
|
37
|
+
@example
|
|
38
|
+
```
|
|
39
|
+
import {npmKeywordNames} from '@cjser/npm-keyword';
|
|
40
|
+
|
|
41
|
+
console.log(await npmKeywordNames('gulpplugin'));
|
|
42
|
+
//=> ['gulp-autoprefixer', …]
|
|
43
|
+
```
|
|
44
|
+
*/
|
|
45
|
+
export function npmKeywordNames(keyword: string | readonly string[], options?: Options): Promise<string[]>;
|
|
46
|
+
|
|
47
|
+
/**
|
|
48
|
+
Get the count of npm packages names with certain keywords.
|
|
49
|
+
|
|
50
|
+
@param keyword - One or more keywords. Only matches packages that have *all* the given keywords. Example: `['string', 'camelcase']`.
|
|
51
|
+
@returns The count of packages.
|
|
52
|
+
|
|
53
|
+
@example
|
|
54
|
+
```
|
|
55
|
+
import {npmKeywordCount} from '@cjser/npm-keyword';
|
|
56
|
+
|
|
57
|
+
console.log(await npmKeywordCount('gulpplugin'));
|
|
58
|
+
//=> 3457
|
|
59
|
+
```
|
|
60
|
+
*/
|
|
61
|
+
export function npmKeywordCount(keyword: string | readonly string[]): Promise<number>;
|
|
62
|
+
|
|
63
|
+
export default npmKeyword;
|
package/index.js
ADDED
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import ky from '@cjser/ky__v1_14_3';
|
|
2
|
+
import registryUrl from '@cjser/registry-url__v6_0_1';
|
|
3
|
+
|
|
4
|
+
const get = async (keyword, {size = 250} = {}) => {
|
|
5
|
+
if (typeof keyword !== 'string' && !Array.isArray(keyword)) {
|
|
6
|
+
throw new TypeError('The keyword must be either a string or an array of strings');
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
if (size === 0 || size > 250) {
|
|
10
|
+
throw new TypeError('The `size` option must be in the range 1...250');
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
keyword = encodeURIComponent(keyword).replace('%2C', '+');
|
|
14
|
+
|
|
15
|
+
const url = `${registryUrl()}-/v1/search?text=keywords:${keyword}&size=${size}`;
|
|
16
|
+
|
|
17
|
+
return ky(url).json();
|
|
18
|
+
};
|
|
19
|
+
|
|
20
|
+
export async function npmKeyword(keyword, options) {
|
|
21
|
+
const {objects} = await get(keyword, options);
|
|
22
|
+
|
|
23
|
+
return objects.map(element => ({
|
|
24
|
+
name: element.package.name,
|
|
25
|
+
description: element.package.description,
|
|
26
|
+
}));
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
export async function npmKeywordNames(keyword, options) {
|
|
30
|
+
const {objects} = await get(keyword, options);
|
|
31
|
+
return objects.map(element => element.package.name);
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
export async function npmKeywordCount(keyword) {
|
|
35
|
+
const {total} = await get(keyword, {size: 1});
|
|
36
|
+
return total;
|
|
37
|
+
}
|
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,79 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@cjser/npm-keyword",
|
|
3
|
+
"version": "8.0.0-cjser.2",
|
|
4
|
+
"description": "Get a list of npm packages with keywords",
|
|
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
|
+
"keyword",
|
|
37
|
+
"package",
|
|
38
|
+
"packages",
|
|
39
|
+
"pkg",
|
|
40
|
+
"registry",
|
|
41
|
+
"find",
|
|
42
|
+
"search"
|
|
43
|
+
],
|
|
44
|
+
"dependencies": {
|
|
45
|
+
"@cjser/ky__v1_14_3": "1.14.3-cjser.2",
|
|
46
|
+
"@cjser/registry-url__v6_0_1": "6.0.1-cjser.2"
|
|
47
|
+
},
|
|
48
|
+
"devDependencies": {
|
|
49
|
+
"ava": "^6.1.1",
|
|
50
|
+
"tsd": "^0.30.7",
|
|
51
|
+
"xo": "^0.57.0"
|
|
52
|
+
},
|
|
53
|
+
"types": "./index.d.ts",
|
|
54
|
+
"main": "./dist-cjser/index.cjs",
|
|
55
|
+
"cjser": {
|
|
56
|
+
"sourceVersion": "8.0.0",
|
|
57
|
+
"cjserVersion": 2,
|
|
58
|
+
"original": {
|
|
59
|
+
"name": "npm-keyword",
|
|
60
|
+
"version": "8.0.0",
|
|
61
|
+
"exports": {
|
|
62
|
+
"types": "./index.d.ts",
|
|
63
|
+
"default": "./index.js"
|
|
64
|
+
},
|
|
65
|
+
"repository": "sindresorhus/npm-keyword",
|
|
66
|
+
"dependencies": {
|
|
67
|
+
"ky": "^1.2.1",
|
|
68
|
+
"registry-url": "^6.0.1"
|
|
69
|
+
},
|
|
70
|
+
"files": [
|
|
71
|
+
"index.js",
|
|
72
|
+
"index.d.ts"
|
|
73
|
+
],
|
|
74
|
+
"scripts": {
|
|
75
|
+
"test": "xo && ava && tsd"
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
}
|
package/readme.md
ADDED
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
# npm-keyword
|
|
2
|
+
|
|
3
|
+
> Get a list of npm packages with keywords
|
|
4
|
+
|
|
5
|
+
## Install
|
|
6
|
+
|
|
7
|
+
```sh
|
|
8
|
+
npm install npm-keyword
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
## Usage
|
|
12
|
+
|
|
13
|
+
```js
|
|
14
|
+
import {npmKeyword, npmKeywordNames, npmKeywordCount} from 'npm-keyword';
|
|
15
|
+
|
|
16
|
+
console.log(await npmKeyword('gulpplugin'));
|
|
17
|
+
//=> [{name: 'gulp-autoprefixer', description: '…'}, …]
|
|
18
|
+
|
|
19
|
+
console.log(await npmKeywordNames('gulpplugin'));
|
|
20
|
+
//=> ['gulp-autoprefixer', …]
|
|
21
|
+
|
|
22
|
+
console.log(await npmKeywordCount('gulpplugin'));
|
|
23
|
+
//=> 3457
|
|
24
|
+
```
|
|
25
|
+
|
|
26
|
+
## Caveat
|
|
27
|
+
|
|
28
|
+
The list of packages will contain a maximum of 250 packages matching the keywords. This limitation is caused by the [npm registry API](https://github.com/npm/registry/blob/master/docs/REGISTRY-API.md#get-v1search).
|
|
29
|
+
|
|
30
|
+
## API
|
|
31
|
+
|
|
32
|
+
### npmKeyword(keywords, options?)
|
|
33
|
+
|
|
34
|
+
Returns a promise for a list of packages having the specified keyword in their package.json `keywords` property.
|
|
35
|
+
|
|
36
|
+
#### keywords
|
|
37
|
+
|
|
38
|
+
Type: `string | string[]`\
|
|
39
|
+
Example: `['string', 'camelcase']`
|
|
40
|
+
|
|
41
|
+
One or more keywords. Only matches packages that have *all* the given keywords.
|
|
42
|
+
|
|
43
|
+
#### options
|
|
44
|
+
|
|
45
|
+
Type: `object`
|
|
46
|
+
|
|
47
|
+
##### size
|
|
48
|
+
|
|
49
|
+
Type: `number`\
|
|
50
|
+
Default: `250`
|
|
51
|
+
|
|
52
|
+
Limits the amount of results.
|
|
53
|
+
|
|
54
|
+
### npmKeywordNames(keywords, options?)
|
|
55
|
+
|
|
56
|
+
Returns a promise for a list of package names.
|
|
57
|
+
|
|
58
|
+
#### keywords
|
|
59
|
+
|
|
60
|
+
Type: `string | string[]`\
|
|
61
|
+
Example: `['string', 'camelcase']`
|
|
62
|
+
|
|
63
|
+
One or more keywords. Only matches packages that have *all* the given keywords.
|
|
64
|
+
|
|
65
|
+
#### options
|
|
66
|
+
|
|
67
|
+
Type: `object`
|
|
68
|
+
|
|
69
|
+
##### size
|
|
70
|
+
|
|
71
|
+
Type: `number`\
|
|
72
|
+
Default: `250`
|
|
73
|
+
|
|
74
|
+
Limits the amount of results.
|
|
75
|
+
|
|
76
|
+
### npmKeywordCount(keywords)
|
|
77
|
+
|
|
78
|
+
Returns a promise for the count of packages.
|
|
79
|
+
|
|
80
|
+
#### keywords
|
|
81
|
+
|
|
82
|
+
Type: `string | string[]`\
|
|
83
|
+
Example: `['string', 'camelcase']`
|
|
84
|
+
|
|
85
|
+
One or more keywords. Only matches packages that have *all* the given keywords.
|
|
86
|
+
|
|
87
|
+
## Related
|
|
88
|
+
|
|
89
|
+
- [package-json](https://github.com/sindresorhus/package-json) - Get the package.json of a package from the npm registry
|
|
90
|
+
- [npm-user](https://github.com/sindresorhus/npm-user) - Get user info of an npm user
|
|
91
|
+
- [npm-email](https://github.com/sindresorhus/npm-email) - Get the email of an npm user
|
|
92
|
+
|
|
93
|
+
## cjser
|
|
94
|
+
|
|
95
|
+
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.
|
|
96
|
+
Original repository: https://github.com/sindresorhus/npm-keyword
|