JSPM

  • Created
  • Published
  • Downloads 3
  • Score
    100M100P100Q45048F
  • License MIT

c like printf and sprintf

Package Exports

  • cprintf

This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (cprintf) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

cprintf

cprintf supported this env

  • nodejs
  • broswer
  • webchat app

install via npm

npm install cprintf --save

this lib include two functions

string sprintf(strFormat , ...);
void printf(strFormat , ...);

usage

// import function
const sprintf = require('cprintf').sprintf;
const printf = require('cprintf').printf;

// c-like printf
printf('hellp prinf %d\n' , 1 );

// c-like sprintf
var strText = sprintf('hellp prinf %d\n' , 1 );
printf( strText );
console.log( strText );

// direct printf a JSON object
var xxObj = {a : 1 , b : 2};
printf( "%s" , xxObj);

support formats just like c printf and sprintf

  • %c -- ascii value
  • %d -- signed number
  • %s -- string
  • %x -- number in hex
  • %i -- signed number
  • %f -- float
  • %o -- octal number
  • %u -- unsigned number