Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Angular 2, sprintf in TypeScript

Can someone tell me all the steps I need to do to use a complete sprintf library (with zero padding and all other features typically present in a standard sprintf) in Angular 2 Typescript component? Thanks.

like image 487
Massimo Magliani Avatar asked Apr 08 '16 09:04

Massimo Magliani


3 Answers

Install sprintf-js

npm install sprintf-js --save

Install TypeScript Definition

typings install dt~sprintf-js --global --save

Import and use in code

import {sprintf} from "sprintf-js";

console.log(sprintf("%s %s!", "Hello", "Massimo"));
like image 59
ANEKHERo Avatar answered Nov 16 '22 20:11

ANEKHERo


npm i sprintf-js --save

npm i --save_dev @types/sprintf-js

import {sprintf} from "sprintf-js";

like image 41
headbozo Avatar answered Nov 16 '22 20:11

headbozo


As typings is now deprecated:

$ npm install --save @types/sprintf

Then in your typescript source:

import { sprintf } from 'sprintf';

like image 7
matthewmcneely Avatar answered Nov 16 '22 21:11

matthewmcneely