![Oracle Drags Its Feet in the JavaScript Trademark Dispute](https://cdn.sanity.io/images/cgdhsj6q/production/919c3b22c24f93884c548d60cbb338e819ff2435-1024x1024.webp?w=400&fit=max&auto=format)
Security News
Oracle Drags Its Feet in the JavaScript Trademark Dispute
Oracle seeks to dismiss fraud claims in the JavaScript trademark dispute, delaying the case and avoiding questions about its right to the name.
detective-typescript
Advanced tools
The detective-typescript npm package is designed to analyze TypeScript files to extract dependencies, such as import and require statements. It can be used to understand the structure of a TypeScript project, identify unused dependencies, or automate tasks that involve analyzing the dependency graph of a project.
Extract import statements
This feature allows you to extract all the import statements from a given TypeScript file content. The code sample demonstrates how to use detective-typescript to parse a string containing TypeScript code and return an array of the imported modules.
const detective = require('detective-typescript');
const content = `import { join } from 'path';
import * as fs from 'fs';`;
const dependencies = detective(content);
Extract require statements
In addition to import statements, detective-typescript can also extract require statements from TypeScript files. This is useful for projects that use a mix of ES6 and CommonJS modules. The code sample shows how to extract dependencies from a string of TypeScript code that uses require.
const detective = require('detective-typescript');
const content = `const express = require('express');
const app = express();`;
const dependencies = detective(content);
Precinct is a more general-purpose dependency detection tool that supports multiple file types, including JavaScript, TypeScript, and CSS. While detective-typescript focuses specifically on TypeScript, Precinct provides a broader range of functionality but might be less specialized for TypeScript-specific nuances.
Madge is a tool for generating a visual graph of module dependencies, and it can analyze TypeScript files among others. Unlike detective-typescript, which is focused on extracting dependencies from file content, Madge provides a higher-level overview of the project structure and can be used for visualizing and analyzing the dependency graph.
Get the dependencies of TypeScript module
npm install detective-typescript typescript
const fs = require('fs');
const detective = require('detective-typescript');
const mySourceCode = fs.readFileSync('myfile.ts', 'utf8');
// Pass in a file's content or an AST
const dependencies = detective(mySourceCode);
skipTypeImports
(default: false
) Skips imports that only imports typesmixedImports
: (default: false
) Include CJS imports in dependency listskipAsyncImports
: (default: false
) Whether or not to omit async imports (import('foo'))jsx
: (default: false
) Enable parsing of JSXonFile
: A callback that will be called before the file is processed. Intended for use with dependency-tree
. Passed an object argument with properties options
(echoing any options passed in, e.g., by precinct
), src
(source code for file as string), ast
(parsed AST object for the file source), and walker
(a Walker
instance from node-source-walk
configured for TypeScript to which you can pass the ast
or src
).onAfterFile
: Similar to onFile
, but the callback is also passed an object property dependencies
, a string array with the extracted dependencies.MIT
FAQs
Get the dependencies of a TypeScript module
The npm package detective-typescript receives a total of 301,202 weekly downloads. As such, detective-typescript popularity was classified as popular.
We found that detective-typescript demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 4 open source maintainers collaborating on the project.
Did you know?
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.
Security News
Oracle seeks to dismiss fraud claims in the JavaScript trademark dispute, delaying the case and avoiding questions about its right to the name.
Security News
The Linux Foundation is warning open source developers that compliance with global sanctions is mandatory, highlighting legal risks and restrictions on contributions.
Security News
Maven Central now validates Sigstore signatures, making it easier for developers to verify the provenance of Java packages.