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

freestring

v1.0.1

Published

template string

Downloads

4

Readme

freestring

自由书写string 轮子

无意中看到了sindresorhus的multiline,觉得很实用,逻辑很简单,所以就自己加了点东西造了个轮子;除了multiline的写法外,加了一个简单的模板变量功能。

freestring就是用于模拟ES6的template string,让书写string更自由。可以直接复制一段html保持原来的格式粘贴使用,而不需要用js拼接,还可以使用简单的模板变量。

如果需要复杂的模板变量,那就引入ejs或者mustache吧,直接使用最简单的用法把html转成字符,再通过ejs.render渲染

How To Use

nodejs : npm install freestring browser : <script src="freestring"> or use seajs : require("freestring")

最简单用法

var str = freestring(function(){
	/*
           <ul class="name">
               <li class="id1"></li>
               <li class="id2"></li>
               <li class="id3"></li>
           </ul>
	*/
})

可以添加参数

var str = freestring(function(){
	/*
           <ul class="name">
               <li class="id1">${data}</li>
               <li class="id1">${yo.hllo}</li>
               <li class="id2">${data2.0}</li>
               <li class="id3">${data2[1]}</li>
           </ul>
	*/
} , {data:"ss" , yo : {hllo : 'asd'}, data2:[0 , 2 , 3]});

或者

var str = freestring(function(){
    /*
         <ul class="name">
             <li class="id1">${0}</li>
             <li class="id2">${1}</li>
             <li class="id3">${2}</li>
         </ul>
     */
} , ['asd' , '123' , 12344]);

在浏览器使用时,如果使用uglify压缩代码会将注释删除,导致代码失效。 解决办法: 1、添加@preserve,同时要在方法体里加点内容,才不会被当成空函数 2、设置uglify的压缩参数:preserveComments:'some',即可保留@preserve的注释

var str = freestring(function(){
    /*@preserve
         <ul class="name"></ul>
     */console.log
} , ['asd' , '123' , 12344]);