npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

git-changed-files

v1.0.0

Published

Get the change between any of your branch and current branch of a `git` repository

Downloads

52,818

Readme

git-changed-files

Get the committed and uncommitted files list between your any of your branch and current branch of a git repository

  • Filter based on file type.
  • Promise API
  • Filter files based on the type of change(Example: modified or added or ...)
  • Filter the files with status.
  • Filter files based on files stage (Ex: committed, uncommitted(staged and working directory files)).

Installing

To add it to devDependencies

yarn add git-changed-files --dev

or

npm install --save-dev git-changed-files

Usage

const gitChangedFiles = require('git-changed-files');

(async() => {
  let committedGitFiles = await gitChangedFiles();
  console.log(committedGitFiles);
})().catch((err) => {
    console.log(err);
  });

/* Expected: { committedFiles: [ '.editorconfig', '.travis.yml', 'destroy.js', 'index.js' ],
               unCommittedFiles: ['index.js'] }
*/

(async() => {
  let committedGitFiles = await gitChangedFiles({ formats: ['*.yml'] });
  console.log(committedGitFiles);
})().catch((err) => {
    console.log(err);
  });

/* Expected: { committedFiles: [ '.travis.yml'],
               unCommittedFiles: [] }
*/

(async() => {
  let committedGitFiles = await gitChangedFiles({ formats: ['!*.yml'] });
  console.log(committedGitFiles);
})().catch((err) => {
    console.log(err);
  });

/* Expected: { committedFiles: [ '.editorconfig', 'destroy.js', 'index.js' ],
               unCommittedFiles: ['index.js'] }
*/

(async() => {
  let committedGitFiles = await gitChangedFiles({ diffFilter: 'A' });
  console.log(committedGitFiles);
})().catch((err) => {
    console.log(err);
  });

/* Expected: { committedFiles: ['destroy.js'],
               unCommittedFiles: [] }
*/

(async() => {
  let committedGitFiles = await gitChangedFiles({ showStatus: true });
  console.log(committedGitFiles);
})().catch((err) => {
    console.log(err);
  });

/*
Expected:
{ 
  committedFiles: [ 
    {
      fileName: '.editorconfig',
      status: 'Modified'
    },
    {
      fileName: '.travis.yml'
      status: 'Modified'
    },
    {
      fileName: 'destroy.js'
      status: 'Added'
    },
    {
      fileName: 'index.js'
      status: 'Modified'
    }
  ],
  unCommittedFiles: [
    {
      fileName: 'index.js'
      status: 'Modified'
    }
  ]
 }
 */
 
(async() => {
  let uncommittedGitFiles = await gitChangedFiles({ showCommitted: false });
  console.log(uncommittedGitFiles);
})().catch((err) => {
  console.log(err);
  });
  
// Expected: { unCommittedFiles: ['index.js'] }

(async() => {
  let committedGitFiles = await gitChangedFiles({ showUnCommitted: false });
  console.log(committedGitFiles);
})().catch((err) => {
  console.log(err);
  });
  
// Expected: { committedFiles: [ '.editorconfig', '.travis.yml', 'destroy.js', 'index.js' ] }

API

gitChangedFiles([options])

Returns Promise<Array[]|String>.

options

Type: Object

baseBranch

Type: string Default: master

baseBranch to compare with you current HEAD.

Example: if baseBranch is master, then the list of files that are changed from master to your current HEAD in local will be displayed.

formats

Type: string | string[] Default: false

Filters passed filetypes. If need all filetypes pass false or specify the filetypes in array.

Example:

  • All js files -> [*.js]
  • no need js files -> [!*.js]
diffFilter

Type: string Default: ACDMRTUXB

Diff filters :

  • Added (A),
  • Copied (C),
  • Deleted (D),
  • Modified (M),
  • Renamed (R),
  • changed (T),
  • Unmerged (U),
  • Unknown (X),
  • Broken (B)

Refer More here

showStatus

Type: boolean Default: false

To show the type of file change in the result.

Example: If showStatus is true then output will be

[{ filename: '.editorconfig', status: 'Deleted' }]

showCommitted & showUnCommitted

Type: boolean Default: true

Examples:

Case 1:

By default, it lists all the changed files.

{ committedFiles: [ '.editorconfig', '.travis.yml', 'destroy.js', 'index.js' ], unCommittedFiles: ['index.js'] }

Case 2:

If showUnCommitted is false then output will be

{ committedFiles: [ '.editorconfig', '.travis.yml', 'destroy.js', 'index.js' ] }

Case 3:

If showCommitted is false then output will be

{ unCommittedFiles: ['index.js'] }

Case 4:

If both options are false then it will throw an error.

Either showCommitted or showUnCommitted must be true

Note:

If you changed a file and committed then again if you changed the same file, it will be present in both committed and uncommitted files list.

Built With

  • NodeJs - Framework used
  • NPM - Dependency Management
  • Atom - Code Editor

Contributing

  • If you have any ideas, just open an issue and tell me what you think.
  • Pull requests are warmly welcome, If you would like to contribute to this Project.

License

MIT