Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

depseek

Package Overview
Dependencies
Maintainers
1
Versions
13
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

depseek

Seeks for dependency references in JS/TS code

  • 0.2.0
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
13K
increased by11.84%
Maintainers
1
Weekly downloads
 
Created
Source

depseek

Seeks for dependency references in JS/TS code

lcov npm

Motivation

Dep extraction is a common task for many tools solved in different ways from regexps to AST parsing. This implementation relies on streams to make controllable memory consumption.

Status

PoC

Key features

  • Uses stream-based reader
  • Points exact dependency references by offset
  • Handles string literal and comments
  • Captures bound comments (optional)

Usage

npm i depseek

Usage

import fs from 'fs'
import {depseek} from 'depseek'

const stream = fs.createReadStream('index.js')
const deps = await depseek(stream)

// returns
[
  { type: 'dep', value: 'node:fs', index: 17 },
  { type: 'dep', value: 'foo', index: 34 },
  { type: 'dep', value: 'q', index: 92 }
  // ...
]

Options

By default depseek extracts only require and import arguments. You can also capture bound comments.

const depsAndComments = await depseek(stream, {comments: true})

[
  { type: 'dep', value: 'node:fs', index: 17 },
  { type: 'dep', value: 'foo', index: 34 },
  { type: 'comment', value: ' @1.0.0', index: 46 }
  //...
]

Stream buffer size set to 1000 by default. You can change the limit by passing bufferSize.

const deps = await depseek(stream, {bufferSize: 10000})

Sync

Streams are aimed at intensive bulk operations. If you need to process just a few files, you can use a pair of internal sync methods.

import fs from 'node:fs'
import { readify, extract } from 'depseek'

const contents = fs.readFileSync('index.js', 'utf8')
const deps = extract(readify(contents))

Refs

License

MIT

FAQs

Package last updated on 30 Dec 2023

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc