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

@maptrip/truck-tolls-germany

v1.0.0

Published

Toll rate information for trucks in Germany.

Downloads

16

Readme

Tolls for trucks in Germany

A TypeScript package to stay up to date on toll rates for trucks traveling routes within Germany. This package includes predefined variables (enums) which reflect the current rates from Toll Collect GmbH.

Stay up to date on the latest toll rates for trucks within Germany using this typescript package with predefined variables.

Table of Contents

Installation

Install the library from npm:

npm install @maptrip/truck-tolls-germany

Usage

To fetch the toll rate, you need values for the CO2 Class, Axle & Weight Class, and Euro Class of the truck. These values are provided using TypeScript enums and can be imported from the package.

Enums and their values:

enum CO2Class {
    One = 1,
    Two,
    Three,
    Four
}

enum AxleWeightClass {
    Over_3_5_Tons = "3,5-7,49",
    Over_7_5_Tons = "7,5-11,99",
    Over_12_Tons = "12-18",
    Over_18_Tons_3_Axles = "18&3",
    Over_18_Tons_4_Axles = "18&4",
    Over_18_Tons_5_Axles = "18&5",
}

enum EuroClass {
    Euro1AndZero = "euro1AndZero",
    Euro2 = "euro2",
    Euro3 = "euro3",
    Euro4 = "euro4",
    Euro5_EEV = "euro5_EEVClass1",
    Euro6 = "euro6",
}

Fetching Toll Rates

The TollRateProvider has one method getTollRate, which requires a value for each above enums. This method returns the toll rate in cents per kilometer (cent/km). You can use this rate in combination with the total kilometers of toll roads along a route to calculate the total toll cost.

import {
  AxleWeightClass,
  CO2Class,
  EuroClass,
  TollRateProvider,
} from "@maptrip/truck-tolls-germany";

const tollRateProvider = new TollRateProvider();

const truckOneTollRate = tollRateProvider.getTollRate(CO2Class.One, AxleWeightClass.Over_18_Tons_3_Axles, EuroClass.Euro6)

// returns number 30.3
// multiply this with your total toll roads length to get the total toll cost

Example with MapTrip Server API

To get the total kilometers of toll roads along a route, use the MapTrip API /route endpoint. The value is returned in meters.

As of the first published version of this package, 1.0.0, the provider parameter for the /route endpoint must be either provider=HERE or provider=TomTom. OpenStreetMap does not provide toll information for routes within Germany. OSM German toll data is planned for integration into the MapTrip Server API for a future release.


function getTollsFromRoute(start, destination, token){
  //Use HERE or TomTom for the provider to get tolls in Germany. 
    const url = `https://api.maptrip.de/v1/route?provider=HERE&from=${encodeURIComponent(
      start
    )}&to=${encodeURIComponent(start)}&vehicle=truck`;

    try {
        const response = await fetch(url, {
            headers: {
                Accept: "application/json",
                Authorization: token  //MapTrip token
            },
        });
        const data = await response.json()

        // Return the toll data in km 
        const tollRoadLengthInKm = (data[0].summary.toll / 1000).toFixed()
        return tollRoadLengthInKm
    } catch (error) {
      console.error("Error fetching data", error);
      throw error;
    }
}

async function calculateTotalTollCosts(cO2Class, axleWeightClass, euroClass, start, destination, token){
  try {
    const tollsInKm = await getTollsFromRoute(start, destination, token);
    const tollRateProvider = new TollRateProvider();
    const tollRate = tollRateProvider.getTollRate(cO2Class, axleWeightClass, euroClass);

    // divide by 100 to get a total in euros rather than cents
    const totalInEuro = ((tollsInKm * tollRate) / 100).toFixed();
  } catch (error) {
    console.error("Error calculating total toll costs", error);
    throw error;
  }

}

Questions

Any questions or comments, please direct a request to [email protected]

History

  • 1.0.0 Package released. Toll information up to date as of July 1, 2024.