https://github.com/ozum/read-package-names
Read package names (including scoped packages) from a directory.
https://github.com/ozum/read-package-names
Last synced: about 2 months ago
JSON representation
Read package names (including scoped packages) from a directory.
- Host: GitHub
- URL: https://github.com/ozum/read-package-names
- Owner: ozum
- License: mit
- Created: 2021-02-20T18:29:28.000Z (about 4 years ago)
- Default Branch: master
- Last Pushed: 2021-02-21T18:47:51.000Z (about 4 years ago)
- Last Synced: 2025-02-09T18:24:40.673Z (3 months ago)
- Language: JavaScript
- Size: 403 KB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# read-package-names
Read package names (including scoped packages) from a directory.
- [Synopsis](#synopsis)
- [Details](#details)
- [API](#api)
- [Functions](#functions)
- [default](#default)# Synopsis
```ts
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_
Reads all package names from a directory.
#### Example
```typescript
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_
the list of package names including scoped packages.
Defined in: [read-package-names.ts:95](https://github.com/ozum/read-package-names/blob/f33d5dd/src/read-package-names.ts#L95)