Giter Site home page Giter Site logo

luistak / pkg-usage Goto Github PK

View Code? Open in Web Editor NEW
13.0 3.0 2.0 223 KB

A library that helps you understand how a package is being used in your projects and what APIs are used

License: MIT License

TypeScript 90.71% JavaScript 9.29%
hacktoberfest npm node package usage resources

pkg-usage's Introduction

๐Ÿ“ฆ pkg-usage

npm

Installation

npm install pkg-usage

# or

yarn add pkg-usage

Introduction

Have you ever wondered how your library is being used in other repositories? It's your lucky day because this package aims to solve it.

Given a few options you can gets details about how your library is being imported along with its version

Usage

import { getPackagesUsages } from 'pkg-usage';

const usages: PackageUsage[] = getPackagesUsages({
  packages: ['react'],
  fileGlobs: `**/**.ts`,
  packageJsonCWD: './package.json',
  analyzeImportUsages: false,
});

console.log(usages);

Package Usage types

export type JSXElementUsage = {
  line: number;
  props: string[];
  text: string;
};

export type CallExpressionUsage = {
  line: number;
  text: string;
};

export type ValueUsage = {
  line: number;
  text: string;
};

export type PropertyAccessExpressionUsage = {
  line: number;
  property: string;
  text: string;
};

export type Usages =
  | JSXElementUsage[]
  | (CallExpressionUsage | PropertyAccessExpressionUsage | ValueUsage)[];

export type Import = {
  name: string;
  type: ExportType;
  usages?: Usages;
};

export type FileUsage = {
  name: string;
  filePath: string;
  imports: Import[];
};

export type PackageUsage = {
  name: string;
  count: number;
  files?: FileUsage[];
  version?: string;
};

CLI usage

Options Description Example
-p, --packages Packages to analyze -p vue,vuex or --packages="react,redux"
-f, --file-globs Files to analyze based on file globs -f ".(ts|tsx)" or --file-globs=".(js|jsx)"
-u, --analyze-import-usages (Experimental) Analyzes import usages -u
-cwd, --package-json-CWD Directory to start from -cwd "/path/to/start/from"

npx

npx is a package runner tool

npx pkg-usage -p "react,redux" -f "**/*.(ts|tsx)"

Or

npx pkg-usage --packages="vue,vuex" --file-globs="**/*.(js|vue)"

If you use npm 5.1 or earlier, you can't use npx. Instead, install it globally:

npm install -g pkg-usage

Now you can run:

pkg-usage -p "react,redux" --f "**/*.(ts|tsx)"

pkg-usage's People

Contributors

alan-pazetto-ifood avatar imteekay avatar luistak avatar matheusdc avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.