Options
All
  • Public
  • Public/Protected
  • All
Menu

BytesBUCK 💲🚀

Don't have any better name for it :p

It simply helps in calculating bytes and humanizing them.

⚡ Usage

yarn add bytes-buck
# OR npm install bytes-buck

Example:-

import byteBuck from 'bytes-buck'

let result = byteBuck(
  // Bytes you want to sum
  ["5 GiB", "12 MiB", "5 GB"],

  // Places after decimal, ex. 4.5678 KB
  4,

  // If true, 4...KB will eb converted to 4...KiB
  true
)

📃 Docs

Docs can be found here

🤟 Contributions

Contributions, issues and feature requests are welcome!

if you feel that something is missing, feel free to create an Issue.

❤ Support

Almost all the project I make are Open Source.

Do ⭐ this Project.


Made with ❤ and TypeScript.

Index

Functions

convertToBytes

  • convertToBytes(value?: number, type?: string, binaryUnits?: boolean): number
  • Converts a Given Human readable byte to Bytes.

    Parameters

    • value: number = 1

      Byte No. ex. from "12.3 MiB" give 12.3

    • type: string = "KiB"

      Byte Type ex. from "12.3 MiB" give "MiB"

    • binaryUnits: boolean = true

      Will return TiB (true) or TB (false)

    Returns number

default

  • default(values: string[], decimal?: number, wantBinaryUnit?: boolean): string
  • Adds the given Bytes...

    author

    GitHub.com/PiyushSuthar

    Parameters

    • values: string[]

      Values you would like to add.

    • decimal: number = 4

      No.s after decimal point.

    • wantBinaryUnit: boolean = false

      True, if You want output like GiB, TiB, KiB, etc... Else false.

    Returns string

    Sum of the given bytes

formatBytes

  • formatBytes(bytes: number, decimals?: number, binaryUnits: boolean): string
  • Converts the Bytes to Human Readable Form

    Parameters

    • bytes: number

      bytes to convert

    • decimals: number = 2

      No.s after decimal point

    • binaryUnits: boolean

      TiB (true) or TB (false)

    Returns string

    ex. 12.2 MiB or MB

isBinaryUnit

  • isBinaryUnit(value?: string): boolean
  • Returns True, if value is GiB, TiB or similar... else false

    Parameters

    • value: string = 'GiB'

    Returns boolean

seperateNoAndStr

  • seperateNoAndStr(str: string): { storageValue: number; type: string }
  • Seperates a Number and String from a give String. ex. "12 MiB", it'll return 12 and MiB

    Parameters

    • str: string

    Returns { storageValue: number; type: string }

    • storageValue: number
    • type: string

Legend

Generated using TypeDoc