read-package-names
TypeScript icon, indicating that this package has built-in type declarations

1.1.1 • Public • Published

read-package-names

Read package names (including scoped packages) from a directory.

Synopsis

await readPackageNames("node_modules"); // ["pg-structure", "@babel/runtime", ...]
await readPackageNames("node_modules", { scope: "babel" }); // ["@babel/runtime", "@babel/template", ...]
await readPackageNames("node_modules", { prefix: "pg" }); // ["pg-structure", "pg-generator", "@user/pg-promise", ...]
await readPackageNames("node_modules", { scope: "user", prefix: "pg" }); // ["@user/pg-promise", ...]

Details

Reads all package names in a directory by reading all entries in the given directory and all sub entries in directories starting with the "@" sign.

API

Functions

default

default(cwd: string, options?: { prefix?: string | string[] ; scope?: string | string[] ; silent?: boolean }): Promise<string[]>

Reads all package names from a directory.

Example

await readPackageNames("node_modules"); // ["pg-structure", "@babel/runtime", ...]
await readPackageNames("node_modules", { scope: "babel" }); // ["@babel/runtime", "@babel/template", ...]
await readScopedPackageNames("node_modules", { scope: "not-found" }); // []
await readScopedPackageNames("node_modules", { scope: "not-found", silent: false }); // Throws `ENOENT`
await readPackageNames("node_modules", { prefix: "pg" }); // ["pg-structure", "pg-generator", "@user/pg-promise", ...]

Parameters:

Name Type Description
cwd string is the directory to read package names from.
options object are options.
options.prefix? string | string[] reads only packages beginning with a prefix or one of the prefixes. Prefix is joined with a dash (e.g. "pg" -> "pg-structure").
options.scope? string | string[] reads only packages from a scope or one of the scopes.
options.silent? boolean prevents errors caused by not-found directories.

Returns: Promise<string[]>

the list of package names including scoped packages.

Defined in: read-package-names.ts:95

Package Sidebar

Install

npm i read-package-names

Weekly Downloads

3

Version

1.1.1

License

MIT

Unpacked Size

105 kB

Total Files

20

Last publish

Collaborators

  • ozum