https://github.com/ntnyq/find-npm-packages
:package: Find npm packages from given source code.
https://github.com/ntnyq/find-npm-packages
Last synced: 7 months ago
JSON representation
:package: Find npm packages from given source code.
- Host: GitHub
- URL: https://github.com/ntnyq/find-npm-packages
- Owner: ntnyq
- License: mit
- Created: 2025-02-25T12:28:20.000Z (8 months ago)
- Default Branch: main
- Last Pushed: 2025-02-27T23:41:07.000Z (8 months ago)
- Last Synced: 2025-03-08T23:51:43.941Z (7 months ago)
- Language: TypeScript
- Size: 89.8 KB
- Stars: 1
- Watchers: 1
- Forks: 0
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# find-npm-packages
[](https://github.com/ntnyq/find-npm-packages/actions)
[](https://www.npmjs.com/package/find-npm-packages)
[](https://www.npmjs.com/package/find-npm-packages)
[](https://codecov.io/github/ntnyq/find-npm-packages)
[](https://github.com/ntnyq/find-npm-packages/blob/main/LICENSE)Find npm packages from given source code.
## Install
```shell
npm install find-npm-packages
``````shell
yarn add find-npm-packages
``````shell
pnpm add find-npm-packages
```## Usage
```ts
import { findNpmPackages } from 'find-npm-packages'const code = `import findNpmPackages from 'find-npm-packages'`
const result = findNpmPackages(code)
console.log(result)
// [
// {
// "name": "find-npm-packages",
// "start": 29,
// "end": 46,
// "loc": {
// "end": {
// "column": 46,
// "index": 46,
// "line": 1,
// },
// "start": {
// "column": 29,
// "index": 29,
// "line": 1,
// },
// },
// },
// ]
```## API
### `findNpmPackages`
- **Type**: `(code: string, options: Options = {}) => NpmPackage[]`
## Interface
```ts
import type { ParserOptions } from '@babel/parser'export interface NpmPackage {
name: string
end: number
start: number
loc: {
end: Position
start: Position
}
}export interface Options extends ParserOptions {
/**
* Parse code cache
*/
cache?: boolean/**
* Code language
*
* @default `js`
*/
language?: 'dts' | 'js' | 'jsx' | 'ts'
}interface Position {
column: number
index: number
line: number
}
```## License
[MIT](./LICENSE) License © 2025-PRESENT [ntnyq](https://github.com/ntnyq)