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

printf-ts

v2.0.1

Published

printf for typescript

Downloads

36

Readme

printf-ts

codecov

pure typescript implementation of printf-family with type checking

preview

Usage

import { printf } from 'printf-ts';

// Hello printf 1 1.20
printf("Hello %s %d %.2lf", "printf", 1, 1.2)

Features

1. vsprintf(format, args: [...]): string

2. sprintf(format, ...args: [...]): string

3. vprintf(format, args: [...]): number

4. printf(format, ...args: [...]): number

5. vprintfln(format, args: [...]): number

6. printfln(format, ...args: [...]): number

  • 1 ~ 2 Returns the result as a string
  • 3 ~ 4 Writes the results to the stdout, returns the number of characters printed
  • 5 ~ 6 Writes the results to the stdout, returns the number of characters printed. if nodejs, append \n to the end(not affect to return value)

Supported format specifiers

see cppreference-printf for each description of specifier

  • flags: +, -, , #, 0
  • width, precision
    • support wildcard(*)
  • length modifier: h, hh, l, ll, L, j, z, t
  • conversion specifier: %c, %s, %d, %i, %u, %o, %x, %X, %f, %F, %e, %E, %g, %G, %p, %%

types

  • if argument is negative and format specifier is unsigned, it will not convert to unsigned type
  • argument is not converted to a number of specific bits
  • if origin type was unsigned, find it in signed type

| specifier | argument type | description | | :---: | :---: | :--- | | %c | string | str[0] ?? '' | | %c | number | utf8 code point | | %s | string | | | %n | null | please use sprintf(...).length |

integer

%d, %i, %u, %o, %x, %X

  • short|int -> number
  • long|long long|intmax_t|ssize_t|ptrdiff_t -> bigint

Floating point

%f, %F, %e, %E, %g, %G

  • double|long double -> number
    • if value in [infinity, -infinity, NaN]
      • if specifier is uppercase(F,E,G,A) => "INF", "-INF", "NAN"
      • else => "inf", "-inf", "nan"
  • NaN always treated as a positive value

Pointer

%p

  • void* -> bigint
    • if value is 0n => "(nil)"
    • else => "0x" + value.toString(16)

Wildcard

*

  • int -> number