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-parse

v3.0.1

Published

Turn a git repository into a javascript object.

Downloads

777,599

Readme

Git-Parse

NPM version NPM Downloads Bundlephobia

git-parse is a utility which generates an array of javascript objects representing the current branch of a local git repository's commit history.

Details

  • Support NodeJS >= 14

Installation

npm install git-parse

Usage

const { gitToJs } = require('git-parse');

const commitsPromise = gitToJs('path/to/repo/');

commitsPromise.then(commits => console.log(JSON.stringify(commits, null, 2)));
[
  {
    "hash": "7cedc121ee163d859dfdb9911e627d4b5933cc6d",
    "authorName": "[email protected]",
    "authorEmail": "[email protected]",
    "date": "Wed, 10 Jan 2018 16:44:52 -0500",
    "message": "initial setup",
    "filesAdded":[
        { "path": "packages/raspberry-popsicle/index.js" },
        { "path": "packages/raspberry-popsicle/package-lock.json" },
        { "path": "packages/raspberry-popsicle/package.json" }
    ],
    "filesDeleted": [],
    "filesModified": [],
    "filesRenamed": []
  },
  {
    "hash": "226f032eb87ac1eb18b7212eeaf1356980a9ae03",
    "authorName": "[email protected]",
    "authorEmail": "[email protected]",
    "date": "Wed, 10 Jan 2018 15:25:16 -0500",
    "message": "add README",
    "filesAdded": [
      { "path": "README.md" }
    ],
    "filesDeleted": [],
    "filesModified": [],
    "filesRenamed": []
  }
]

API

.gitToJs(pathToRepo, [options])

Returns a promise which resolves with a list of objects describing git commits on the current branch. pathToRepo is a string. options is an optional object with one property, sinceCommit, which is a commit hash. If sinceCommit is present, gitToJs will return logs for commits after the commit specified.

const { gitToJs } = require('git-parse');

const commitsPromise = gitToJs('path/to/repo/');

commitsPromise.then(commits => console.log(JSON.stringify(commits, null, 2)));

.checkOutCommit(pathToRepo, commitHash, [options])

Checks a repository out to a given commit. hash is the commit hash. Options is an optional object with one property, force. force adds --force to the underlying git checkout. Returns a promise.

.gitPull(pathToRepo)

Runs 'git pull' on the repository at the given path. Returns a promise.

.gitDiff(pathToRepo, commitHash1, [commitHash2], [file])

Returns a git diff given a path to the repo, a commit, an optional second commit, and an optional file path.

Returns a promise resolving with the diff as a string.

Development

Build

To generate a local distribution for the git-parse library run the following command:

yarn build

To build the library in the background on file changes, use:

yarn build:watch

Code Formatting

To automatically format the code using Prettier run:

yarn format

or

yarn format:check

Linting

To lint the project using ESLint run:

yarn lint

Tests

To run the project tests using the Jest framework run:

yarn test

Type Checking

To check the project for type errors using Typescript run:

yarn tsc

Use --watch to run the type checker in the background:

yarn tsc --watch

License

This project is licensed under the BSD-2-Clause license.