program story

node.js에 해당하는 sprintf가 있습니까?

inputbox 2020. 11. 18. 09:02
반응형

node.js에 해당하는 sprintf가 있습니까?


node.js에서 출력 형식 지정 (sprintf 유형 기능)을 찾고 있지만 직접 작성하기 전에 비슷한 내장 기능이 있는지 (문서를 아무 소용이 없었는지) 또는 누군가가 이미 모듈을 작성했는지 궁금합니다.

많은 감사


지금이 printf의 -like 지원 util.format().

예:

util.format('hello %s', 'world');
// Returns: 'hello world'

npm 레지스트리 에는 매우 기본적인 지원 만 sprintf있기 때문에 실제 구현 인 몇 가지가 있습니다 util.format.


다음은 자바 스크립트 버전입니다 sprintf.

http://phpjs.org/functions/sprintf:522


console.log 잘 작동합니다.

console.log('%d hours', 4); // 4 hours
console.log('The %2$s contains %1$d monkeys', 4, 'tree'); // The tree contains 4 monkeys

참고 URL : https://stackoverflow.com/questions/2697899/is-there-a-sprintf-equivalent-for-node-js

반응형