A simple npm package that provides functions to convert between kilometers per hour (kph) and minutes per kilometer (mpk) and to convert between different time units, such as seconds, minutes, hours, and days.
You can install this package using npm:
npm install time-units-converter
To use this package in your project, require it at the top of your file:
const converter = require('time-units-converter')
kilometersPerHourToMinutesPerKilometer This function takes a value in kilometers per hour and returns the equivalent value in minutes per kilometer.
const mpk = converter.kilometersPerHourToMinutesPerKilometer(10)
console.log(mpk) // 6
This is an alias for kilometersPerHourToMinutesPerKilometer.
const mpk = converter.kpuToMpk(10)
console.log(mpk) // 6
This function takes a value in minutes per kilometer and returns the equivalent value in kilometers per hour.
const kph = converter.minutesPerKilometerToKilometersPerHour(6)
console.log(kph) // 10
This is an alias for minutesPerKilometerToKilometersPerHour.
const kph = converter.mpkToKpu(6)
console.log(kph) // 10
This function takes an object representing a duration in different time units and converts it to an object or a string in a specified output format.
const duration = {
seconds: 45,
minutes: 32,
hours: 5,
days: 3,
}
const output = {
days: true,
hours: true,
minutes: true,
seconds: true,
}
const result = converter.timeUnitsToTimeUnitsConverter(duration, output)
console.log(result) // { days: 3, hours: 5, minutes: 32, seconds: 45 }
By default, the function returns an object with all time units, but you can specify the desired output format by setting the outputUnits parameter. You can also choose between returning the result as an object or a string by setting the returnType parameter.