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

repo-indexer

v0.0.10

Published

A tool for converting a repository into a static API.

Downloads

32

Readme

repo-indexer

npm code style: prettier

repo-indexer is a tool to generate an indexed representation of a folder.

This is useful if you want to share data using your repository as it was an API.

How to use?

Run this command inside the repository you want to index:

npx repo-indexer

If you're using npm before version 5.2, then you can do:

npm i -g repo-indexer
repo-indexer

How does it work?

The repo-indexer crawls your repository looking for files and folders, then it creates an _index folder in the root of the repository, containing an indexed representation of this repository. But instead of copying files inside the folder, it creates an api.json for each folder, containing information about the files inside that folder. Information like quantity of files, sub-folders and files links are present in a api.json file.

This can be very useful if you want to keep a public repository for sharing data across different clients. The _index folder can be used as an entry point for your data as a read-only Restful API.

Example

An imaginary repository

Imagine you have some repository like this:

  • en_pt/
    • hello.json
    • computer.json
  • pt_es/
    • futebol.json
    • escola.json

Indexing the repository data

Then inside this repository folder, you run:

npx repo-indexer

It will generate an _index folder in the root of your repository:

  • _index/
  • ...

The _index folder

The _index folder will have an structure which represents your repository structure, but instead of the real files, it will contain indexes files, called api.json:

  • _index/
    • api.json
    • en_pt/
      • api.json
    • pt_es/
      • api.json

The api.json file

For each folder in your repository, inside the _index folder will contain an api.json file which represents that folder. This file is what you can think as an API end point for your folder data.

For example, for the file _index/api.json you get a file like this:

{
  "size": 2,
  "items": {
    "en_pt": "_index/en_pt/",
    "pt_es": "_index/pt_es"
  }
}

You can see that this file contains information about the content inside your repository root folder.

With this file in hand, you can now access each part of your repository as it was a Restful API.

For the _index/en_pt/api.json file, you'll have:

{
  "size": 2,
  "items": {
    "hello.json": "en_pt/hello.json",
    "computer.json": "en_pt/computer.json"
  }
}

Notice that the items section contains links to the real location of the files inside your directory.

You can get the content of this file as it was an API end point, and then use this real content to get data.

End point

If the repository is hosted in GitHub, you can access it as an API, using URLs:

https://githubusercontent.com/<user>/<repository>/master/en_pt/api.json https://githubusercontent.com/<user>/<repository>/master/pt_es/api.json

License

MIT License