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 🙏

© 2026 – Pkg Stats / Ryan Hefner

line-json-formatter

v1.2.0

Published

A weirdly specific tool designed to help me build my app.

Readme

Line JSON Formatter

What is this?

It's a weird tool that I made to help me with a specific task while creating my app, STB Logger. I'll use it to convert and format multiple GPX files that I created. They represent every path between two public transport stops in Bucharest. This tool helps me convert them into GeoJSON, add properties (lines, id, length) and save them all in a MySQL database.

How does it work?

LineJSONFormatter

It uses a database with all the stops in Bucharest to find the closest stops to the start and end of each path and saves the ids in the json's properties.

The user is asked whether they would like to use automatic detection of the lines that use the paths. They can also choose to input them manually.

The user is also prompted to choose which paths are in which direction.

Path length is calculated using a npm module.

SubwayJSONFormatter

It takes a GeoJSON file with paths and stops corresponding to subway lines as input. I created it so that it uses a format I already have. The program uses the coordinates of the stops from the GeoJSON file, but uses the ids of stops in the stopJSON file. In order to avoid duplicates, stops whose ids have been used are deleted from the stopJSON file.

The paths are processed in the same way as the LineJSONFormatter function does. The only difference is the format of the input.

ReplaceLineIDs

It takes an ordinary JSON file as input and replaces the values of the indicated field with values from another JSON file.

Why?

I thought that instead of doing this task manually, it's faster to make a script. This way, I also practice JavaScript.

Installation and usage

Install from npm

npm intall --save line-json-formatter

Link to npm module:

Use in a node.js script

import { LineJSONFormatter, SubwayJSONFormatter } from "./app.js";

const formattedJSON = await LineJSONFormatter("input/", "stops.json");
const formattedSubwayJSON = await SubwayJSONFormatter("input/Metrou 2.geojson", "stb-stops.json", true);

function removeRange(line) {
    if(line === undefined) return false;
    else return RegExp("4[0-9][0-9]B*").test(line)
}

const replacedJSON = ReplaceLineIDs('stop_times_4.json', 'line', 'routes_2.json', (line) => { return removeRange(line) });

Documentation

The function LineJSONFormatter has 2 parameters: | Parameter | Type | Description | | ------------ | -------- | --------------- | | inputPath | String | The path where input gpx files are situated | | stopJSONFile | String | The JSON file that contains formatted stops | | linesJSONFile | String | The JSON file that contains information about other lines' paths |

The function SubwayJSONFormatter has 4 parameters:

| Parameter | Type | Required | Description | |----------------|----------|--------------------------------|----------------------------------------------------------------------| | inputFile | String | Yes | The file that contains the paths to be formatted | | stopJSONFile | String | Yes | The JSON file that contains formatted stops | | modifyDb | Boolean | No, default value is true | Whether the function should add paths to database or not | | returnStopJSON | Boolean | No, default value is false | Whether the function should return the modified stopJSON file or not |

The function ReplaceLineIDs has 4 parameters:

| Parameter | Type | Required | Description | |----------------| -------- |--------------------------------|------------------------------------------------------------------------------------------| | inputFile | String | Yes | The JSON file that has the values that are to be replaced | | fieldToReplace | String | Yes | The field within the input JSON that is to be replaced | | linesFile | String | Yes | The JSON file that has the replacement lines | | removeRange | Boolean | No, default value is false | Function that takes a line as input and returns whether the line shoud be removed or not |

The module also requires 3 environmental variables. You must define these in your .env file! | Variable name | Description | | ----------------- | --------------- | | LJF_DB_USER | The MySQL database user | | LJF_DB_PASSWORD | The database password | | LJF_DB_HOST | The ip address where the database is hosted (if hosted locally, should be 127.0.0.1) |

Stop JSON format

The stop JSON must contain an array of objects, each with the following properties: id, name, latitude, longitude.

Example:

[
  {
    "id": 3654,
    "name": "1 Mai",
    "latitude": 44.419407,
    "longitude": 26.047092
  },
  {
    "id": 8682,
    "name": "1 Martie",
    "latitude": 44.422333,
    "longitude": 25.878494
  }
}

LinesJSON format

The linesJSON file must contain an array of objects, each with the following properties: line, path_direction, startId. They represent each stop that every line stops at.

Example:

[
    {"line":5,"path_direction":1,"startId":12067,"path_order":0},
    {"line":5,"path_direction":1,"startId":3617,"path_order":1}
]

Subway GeoJSON format

The subway GeoJSON file has to be of type FeatureCollection and has to only contain features of types Point and LineString.

Points must have the following properties:

  • name - String - The name of the stop.
  • line - String - Stores the lines that stop there. Lines must be separated by "/".

LineStrings must have the following properties:

  • line - String - Stores the lines that stop there. Lines must be separated by "/".
  • end1 - Int - One of the stops that the path connects.
  • end2 - Int - The other stop.

Features may have other properties besides the required ones.

Example:

{
  "features": [
    {
      "type": "Feature",
      "properties": {
        "id": 49,
        "name": "1 Mai",
        "line": "M4"
      },
      "geometry": {
        "coordinates": [
          26.050627,
          44.470534,
          91.580843
        ],
        "type": "Point"
      },
      "id": "0598478d0b02151caba0b3d7813a2df9"
    },
    {
      "type": "Feature",
      "properties": {
        "line": "M1",
        "end1": 8,
        "end2": 9
      },
      "geometry": {
        "coordinates": [
          [
            26.068367,
            44.450738,
            81.30971
          ],
          [
            26.067905,
            44.451043,
            81.163368
          ]
        ],
        "type": "LineString"
      },
      "id": "07c9e42a96d13b687ed7b3d69647570c"
    }
  ]
}

Lines file format

The lines file has to be a JSON object containing objects with the following fields:

  • from - The value to be replaced
  • to - The replacement value

AI Usage

I used AI to help me with the closest distance algorithm.

Demo videos

LineJSONFormatter (New)

Screencast_20260419_163509.webm

LineJSONFormatter (Old)

Screencast_20260322_232538.webm

SubwayJSONFormatter

Screencast_20260329_213430.webm

ReplaceLineIDs

Screencast_20260419_164218.webm