[go: up one dir, main page]

@gladney/convert

1.0.4 • Public • Published

↔️ @gladney/convert

Utility library that performs commonly needed conversions.

Helpful tips

  • All methods that return numerical values can accept {float: n} as a parameter in the last method of the chain, where n is the number of float places.

    Example:
convertLength(2).miles().toKilometers() // 3.218688

convertLength(2).miles().toKilometers({ float: 2 }) // 3.22

convertLength(2).miles().toKilometers({ float: 0 }) // 3

Methods

convertString

String from one casing to another. Starting case is detected automatically.

Supported cases
  • camelCase
  • CONST_CASE
  • kabob-case
  • PascalCase
  • snake_case
  • string case

Example:

convertCase("helloWorld").toPascalCase() // "HelloWorld"

convertTemperature

Temperature from/to Celsius/Fahrenheit

Example:

convertTemperature(100).celsius().toFahrenheit() // 212
convertTemperature(32).fahrenheit().toCelsius() // 0

convertLength

Length from one unit to another (metric or imperial)

Supported units

  • Metric
    • millimeters
    • centimeters
    • meters
    • kilometers

  • Imperial
    • inches
    • feet
    • yards
    • miles

Example:

convertLength(2).miles().toKilometers() // 3.218688

convertTime

Length from one unit to another (metric or imperial)

Supported units
  • seconds
  • minutes
  • hours
  • days
  • weeks
  • years

Example:

convertTime(2).weeks().toMinutes() // 20160

Package Sidebar

Install

npm i @gladney/convert

Weekly Downloads

0

Version

1.0.4

License

ISC

Unpacked Size

38.6 kB

Total Files

10

Last publish

Collaborators

  • gladney