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

razor

v1.1.1

Published

razor style javascript template tool

Downloads

52

Readme

kino.razor - an easy to use,razor style javascript template tool

How to use

use bower

    bower install razor --save

use on a webpage

	<script type="text/javascript" src="kino.razor.js"></script>
	//or minjs
	<script type="text/javascript" src="kino.razor.min.js"></script>

install in node.js

	npm install razor

require js

var razor = require("razor");

you can pass two parameters to kino.razor then get a converted string:

	var str = kino.razor("Hey, @name!", { name: 'kino' });
	//result: "Hey, kino!"

pass one parameter to kino.razor() should return a template function

    var r = kino.razor("hello!@name");
	//type of r is function

and automatic handle missing parameters

	var templateStr = "Hey, @xxx";
    var str = kino.razor(templateStr, {});
	//result: "Hey, "

given a template function to kino.razor() then it should return a convented string(recommond,and get good performance)

    var tf = kino.razor("hello!@name");
    var str = kino.razor(tf, { name: 'kino' });
	//result: "hello!kino"

set javascript code block

    var templateStr = "@{var fname='kino';}this is @fname @lname";
    var str = kino.razor(templateStr, {lname:'jack'});
	//result: "this is kino jack"

use condition syntax

    var templateStr = "@if(1==0){<span>if you see this word,your test is failed</span>}";
    var str = kino.razor(templateStr, {});
	//result: ""

loop, like while and for

    var templateStr = "@for(var i = 0; i < 3; i++){<span>@i</span>}";
    var str = kino.razor(templateStr, {});
	//result: "<span>0</span><span>1</span><span>2</span>"

    templateStr = "@{var i = 3;}@while(i--){<span>@i</span>}";
    str = kino.razor(templateStr, {});
	//result: "<span>2</span><span>1</span><span>0</span>"

use @Html.escape for escape string to html

    var templateStr = "<input yyy='@Html.escape(test)' xxx=\"@Html.escape(otherAttr)\" />";
    var str = kino.razor(templateStr, { test: "kino's test", otherAttr: "\"one more test\"" });
	//result: "<input yyy='kino&#x27;s test' xxx=\"&quot;one more test&quot;\" />"

@@ and @} will be escaped as @ and }

    var templateStr = "{@name@@gmail.com@}";
    var str = kino.razor(templateStr, { name: 'kino' });
	//result: '{[email protected]}'

use custom symbol instead of '@'

    kino.razor.use("&");
    var str = kino.razor("&name@&email", { name: "kinogam", email: "gmail.com" });
    //"[email protected]"

	kino.razor.use("$");
    var str = kino.razor("$name@$email", { name: "kinogam", email: "gmail.com" });
    //"[email protected]"

support style @(name):

	var str = kino.razor("Hey, zz@(name)zz!", { name: 'kino' });
	//result: "Hey, zzkinozz!"