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

node-string-format

v0.0.3

Published

本模块的目的是用于扩展node自带的util.format

Downloads

54

Readme

node-string-format

本模块的目的是用于扩展node自带的util.format

#1 安装 npm install node-string-format

#2 特性 ###* 索引占位符 var format = require("node-string-format"); format("Hi, guys, I'm {0}", "node-string-format"); 这段代码的结果是

Hi, guys, I'm node-string-format

###* 名称占位符 例如下面这个很生硬的例子

var student = {
	studentName : "Mike",
	age : 18
};

var mathClass = {
	className : "Math",
	score : 100
};

为了得到下面的输出

"My name is Mike, I got 100 marks in mathematics"

通过名称占位符,可以这样做

var composedEntity = {
	studentName : student.studentName,
	mathScore : mathClass.score
};

format("My name is {studentName}, I got {mathScore} marks in mathematics", composedEntity);

在上面的代码里,两个实体上需要用到的属性被事先合并到了一个实体里。但是node-string-format允许你省略掉这一步,它支持从不同的实体中获取信息:

format("My name is {studentName}, I got {score} marks in mathematics", student, mathClass);

注:如果在多个实体上有名称相同的属性,前面的优先

###* 如果想在格式化的时候输出"{"和"}",需要转义

format("{{");//{
format("}}");//}

node-string-format

this is a module to extend node's builtin util.format

#1 Install npm install node-string-format

#2 Features ###* Index Placeholder var format = require("node-string-format"); format("Hi, guys, I'm {0}", "node-string-format"); will outputs

Hi, guys, I'm node-string-format

###* Name Placeholder Look at this small, weird example:

var student = {
	studentName : "Mike",
	age : 18
};

var mathClass = {
	className : "Math",
	score : 100
};

In order to get this

"My name is Mike, I got 100 marks in mathematics"

We can do like this with name placeholder

var composedEntity = {
	studentName : student.studentName,
	mathScore : mathClass.score
};

format("My name is {studentName}, I got {mathScore} marks in mathematics", composedEntity);

In above code, we made a new entity contains properties we want at first, but this is not necessary.node-string-format can exact infomation from different entities.

format("My name is {studentName}, I got {score} marks in mathematics", student, mathClass);

note:if property with the same name exists in multiple entities, the foremost will be used

###* If "{" or "}" is wanted when formatting, you can do like this:

format("{{");//{
format("}}");//}