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

node-git-2-json

v1.10.0

Published

Simple tool to get a JSON from your git log. Inspired by @fabien0102/git2json

Downloads

18

Readme

About

Simple tool to get a JSON from your git log. Inspired by @fabien0102/git2json

Use-Cases

  • gitgraph.js
  • analytics
  • repository history
  • problem tracking

Basic Usage

import { generateJson } from 'node-git-2-json';

let json = await generateJson('path-to-repository');

By default your will be returned the entire history as a JSON string.

Intermediate Usage

// To return less history
let json = await generateJson('path-to-repository', 50);
// Returns only last 50 commits as JSON string

// To return a JS/TS Object
let json = await generateJson('path-to-repository', -1, 'Object');
// Returns all history as an Object

Note: If you need to specify all commits you can pass -1 for all.

Note2: The last n commits is across all branches not currently checked out branch.

Advanced Usage

let cleanOptions = {
	keys: [
		'body',
		'notes'
	]
}
let json = await generateJson('path-to-repository', -1, 'Object', cleanOptions);
// Returns an Object for the entire history and
// removes the "body" and "notes" keys from every commit

let cleanOptions = {
	sanitize: 'light'
}
let json = await generateJson('path-to-repository', -1, 'Object', cleanOptions);
// Returns an Object for the entire history and
// performs a light sanitize on strings known to contain problematic characters. 

let cleanOptions = {
	sanitize: 'heavy'
}
let json = await generateJson('path-to-repository', -1, 'Object', cleanOptions);
// Returns an Object for the entire history and
// performs a heavy sanitize on strings known to contain problematic characters. 
// Warning this is highly aggressive and basically removes all non-printable characters.

let cleanOptions = {
	sanitize: 'custom',
	sanitizeRule: /[0-9]/g,
	sanitizeReplace: '!'
}
let json = await generateJson('path-to-repository', -1, 'Object', cleanOptions);
// Returns an Object for the entire history and
// performs a custom sanitize on strings known to contain problematic characters. 
// This uses a regex supplied by the user and replacement string
// Will in this case replace every digit with !

generateJson()

This is the only method needed in 95% of use. Helper functions are exported for extension but only needed if in specific use or modification is needed.

Returns: string|Array<object>

Parameters: repo: string, count?: number, output?: 'JSON | Object', clean?: cleanOptsInterface

|parameter|default|value|required|about| |---|---|---|---|---| |repo|N/A|string|yes|string of path to git repository (can be ./)| |count|-1|int (>-1)|no|number of commits in history to use. -1 is all| |output|JSON|JSON, Object|no|type of output to return| |clean|{}|cleanOptsInterface|no|options for post-processing of data/cleaning|

cleanOptsInterface

type: object

|key|type|notes| |---|---|---| |keys|Array<string>|top level keys in return data format| |sanitize|light\|heavy\|custom| string for level of sanitization| |sanitizeRule|RegExp|a global regex to use as replace filter for custom sanitize| |sanitizeReplace|string|the replacement string for custom rule|

All options are optional but if you choose custom for sanitize then you will recieve an error if you dont provide sanitizeRule or sanitizeReplace

git json format

[
    {
        "refs": [
            "tag: 1.0.0-b.4",
            "origin/dvt.xyz"
        ],
        "hash": "4c106c65ef3a92e5760fe7379300f9478853f0f7",
        "hashAbbrev": "4c106c65",
        "tree": "2283acd8f4019a7119ac303ed882e5d32424b127",
        "treeAbbrev": "2283acd8",
        "parents": [
            "fe2c48aad4b85311b4a19958559687c70b596f63"
        ],
        "parentsAbbrev": [
            "fe2c48aa"
        ],
        "author": {
            "name": "user",
            "email": "[email protected]",
            "timestamp": 1656708382000
        },
        "committer": {
            "name": "user",
            "email": "[email protected]",
            "timestamp": 1656708382000
        },
        "subject": "jenkins-1.0.0-b.4 [ci skip]",
        "body": "",
        "notes": "",
        "stats": [
            {
                "additions": 1,
                "deletions": 1,
                "file": "package.json"
            },
            {
                "additions": 1,
                "deletions": 1,
                "file": "src/app/test/file.xyz"
            }
        ]
    },
    {}....
]