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

@baurine/grafana-value-formats

v1.0.5

Published

grafana value formats

Downloads

142

Readme

Grafana Value Formats

Extract code about value formats from grafana repo and did some slight changes.

How to use

Install

$ npm install @baurine/grafana-value-formats
// or
$ yarn add @baurine/grafana-value-formats

(I publish this package to npm registry and GitHub Packages both.)

Use

The main function is function getValueFormat(unitFormat: string): string {...}, it will return a function whose signature is below:

export type ValueFormatter = (
  value: number,
  decimals?: DecimalCount,
  scaledDecimals?: DecimalCount,
  isUtc?: boolean
) => string

Samples: (copy from valueForamts.test.ts)

// if scaledDecimals is null, use decimals
const str = getValueFormat('ms')(10000086.123, 0, null)
expect(str).toBe('3 hour')

const str = getValueFormat('ms')(10000086.123, 1, null)
expect(str).toBe('2.8 hour')

const str = getValueFormat('kbytes')(10000000, 3, null)
expect(str).toBe('9.537 GiB')

const str = getValueFormat('deckbytes')(10000000, 3, null)
expect(str).toBe('10.000 GB')

// if scaledDecimals is not null, use scaledDecimals, ignore decimals
const str = getValueFormat('ms')(1200, 0, 0)
expect(str).toBe('1.200 s')

You can find all unitFormat we can use in the categories.ts, or exported getValueFormats() function.

Release Notes

1.0.4

  • Add IEC units for Data rate
  • Update id of Data rate in SI units

1.0.3

  • Use dayjs to replace momentjs

1.0.2

  • Nothing changes, just bump version

1.0.1

  • Add "qps" unit (#4)

1.0.0

Breaking Changes

  1. Change a part implementation of scaledUnits() method in src/valueFormats/valueFormats.ts line 126:

    if (steps > 0 && scaledDecimals !== null && scaledDecimals !== undefined) {
      // old logic
      // decimals = scaledDecimals + 3 * steps; // 为什么是乘以 3,大概是以 factor = 1000 为准,1000 表示 3 个小数点
    
      // current logic
      // related issue: https://github.com/grafana/grafana/issues/23561
      decimals = scaledDecimals
    }

    So at before

    expect(scaler(98765, 0, 2)).toBe('98.76500K')
    // because the decimals = 1*3 + 2

    and now

    expect(scaler(98765, 0, 2)).toBe('98.77K')
    // because the decimals = 2