1.1.1 • Published 3 years ago

read-package-names v1.1.1

Weekly downloads
131
License
MIT
Repository
github
Last release
3 years ago

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:

NameTypeDescription
cwdstringis the directory to read package names from.
optionsobjectare 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?booleanprevents errors caused by not-found directories.

Returns: Promise<string[]>

the list of package names including scoped packages.

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