0.0.2 • Published 4 months ago

find-npm-packages v0.0.2

Weekly downloads
-
License
MIT
Repository
github
Last release
4 months ago

find-npm-packages

CI NPM VERSION NPM DOWNLOADS CODECOV LICENSE

Find npm packages from given source code.

Install

npm install find-npm-packages
yarn add find-npm-packages
pnpm add find-npm-packages

Usage

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

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 © 2025-PRESENT ntnyq

0.0.2

4 months ago

0.0.1

4 months ago