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

vega-format

v1.1.2

Published

JavaScript string formatting utilities for Vega.

Downloads

595,292

Readme

vega-format

String formatting utilities for number and date values.

API Reference

Number Format Locale

# vega.numberFormatLocale(definition) <>

Returns a locale object with methods for number formatting, based on the provided definition. The definition argument must match the format expected by d3-format. For examples of definition files for a variety of languages, see the d3-format locale collection.

# locale.format([specifier]) <>

Returns a function that takes a number as input and returns a formatted string. If a string-valued format specifier is provided, it must follow the d3-format syntax. The returned function is akin to d3-format's format method.

# locale.formatPrefix(specifier, value) <>

Returns a function that takes a number as input and returns a formatted string, with a fixed SI prefix anchored at the provided value. The string-valued format specifier must follow the d3-format syntax. The returned function is akin to d3-format's formatPrefix method.

# locale.formatFloat([specifier]) <>

Returns a function that takes a number as input and returns a formatted string. This method is similar to the format method, except that if the specifier does not provide a precision, the returned formatter will use a variable (floating) precision depending on the number of significant digits. Vega uses this method to provide improved formatting for values plotted on a logarithmic scale.

# locale.formatSpan(start, stop, count[, specifier]) <>

Returns a function that takes a number as input and returns a formatted string appropriate for a specified span of numbers defined by start and stop values and a count of values in the range. Based on these values, the method will attempt to find an appropriate precision. For example, to format 20 numbers on the range [0, 10], a precision of 0.1 ('0.1f') will be used. An optional specifier can be used to further customize the format; if the specifier includes a numeric precision that value will override the span-based precision.

# vega.numberFormatDefaultLocale([definition]) <>

Get or set the default locale for number formatting. If no arguments are provided, returns the current default locale. Otherwise, sets the default locale based on the provided definition, and returns the resulting locale object. The input definitions should be of the same type accepted by the numberFormatLocale method.

# vega.resetNumberFormatDefaultLocale() <>

Resets the default locale for number formatting and returns the resulting locale object. The new default number locale for Vega will match the current default locale for the underlying d3-format library.

Time Format Locale

# vega.timeFormatLocale(definition) <>

Returns a locale object with methods for time formatting, based on the provided definition. The definition argument must match the format expected by d3-time-format. For examples of definition files for a variety of languages, see the d3-time-format locale collection.

# locale.timeFormat([specifier]) <>

Returns a function that takes a date or timestamp as input and returns a formatted string in the local timezone. If a string-valued format specifier is provided, it must follow the d3-time-format syntax. The returned function is akin to d3-time-format's timeFormat method.

If an object-valued specifier is provided, a multi-format function will be generated, which selects among different format specifiers based on the granularity of the input date value (that is, values residing on a year, month, date, etc., boundary can all be formatted differently). The input object should use proper time unit strings for keys. If no time format specifier is provided, a default multi-format function is returned, equivalent to using the following specifier:

{
  "year": "%Y",
  "quarter": "%B",
  "month": "%B",
  "week": "%b %d",
  "date": "%a %d",
  "hours": "%I %p",
  "minutes": "%I:%M",
  "seconds": ":%S",
  "milliseconds": ".%L"
}

If an input specifier object omits any of these key values, a default value will be used. Note that for this method the "date" and "day" units are interchangeable; if both are defined the "date" entry take precedence.

# locale.utcFormat([specifier]) <>

Returns a function that takes a date or timestamp as input and returns a formatted string in Coordinated Universal Time (UTC). If a string-valued format specifier is provided, it must follow the d3-time-format syntax. The returned function is akin to d3-time-format's utcFormat method.

This method also accepts object-valued specifiers for creating multi-format functions. If no argumennts are provided, a defualt multi-format function will be returned. For more details, see the timeFormat method documentation.

# locale.timeParse(specifier) <>

Returns a function that takes a string as input and returns a date. The string-valued format specifier must follow the d3-time-format syntax. The returned function is akin to d3-time-format's timeParse method.

# locale.utcParse(specifier) <>

Returns a function that takes a string as input and returns a date in Coordinated Universal Time (UTC). The string-valued format specifier must follow the d3-time-format syntax. The returned function is akin to d3-time-format's utcParse method.

# vega.timeFormatDefaultLocale([definition]) <>

Get or set the default locale for time formatting. If no arguments are provided, returns the current default locale. Otherwise, sets the default locale based on the provided definition, and returns the resulting locale object. The input definitions should be of the same type accepted by the timeFormatLocale method.

# vega.resetTimeFormatDefaultLocale() <>

Resets the default locale for time formatting and returns the resulting locale object. The new default time locale for Vega will match the current default locale for the underlying d3-time-format library.

Combined Locale

Combined locale objects provide a convenient abstraction for both number and time formatting methods defined on a single object. A combined locale object contains the methods of both a number format locale object and a time format locale object.

# vega.locale(numberDefinition, timeDefinition) <>

Returns a combined locale object with methods for both number and time formatting, based on the provided numberDefinition and timeDefinition. The definition arguments must match the format expected by d3-format and d3-time-format. If either argument is null or unspecified, the corresponding default locale is used instead. For examples of definition files for a variety of languages, see the d3-format locale collection and d3-time-format locale collection.

# vega.defaultLocale([numberDefinition, timeDefinition]) <>

Get or set the default locale for both number and time formatting. If no arguments are provided, returns the current default locale. Otherwise, sets the default locales based on the provided numberDefinition and timeDefinition, and returns the resulting combined locale object. The input definitions should be of the same type accepted by the locale method.

# vega.resetDefaultLocale() <>

Resets the default locale for both number and time formatting and returns the resulting comgined locale object. The new default locales for Vega will match the current default locales for the underlying d3-format and d3-time-format libraries.