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

@poorest/ejs

v2.1.0

Published

my ejs.

Downloads

10

Readme

@poorest/ejs

my ejs

install

	 npm i -S @poorest/ejs

API 说明

  • EJS.configure(options, [fixContext])修改内置Context,第一个参数是配置项, 第二个参数可选函数,可以对Context进行补充修改
  • EJS.inject(name: string, handle: any, replace: boolean = false)为模板注入一些功能, name在模板中名称,handle在模板中name变量对应的值或函数,replace是否替换已经注入的
  • EJS.complie(path: string, options?: EJS.IOptions) 翻译模板,返回一个render函数
  • EJS.render(path: string, data: any, options?: EJS.IOptions) 渲染指定path的模板,path为模板路径,data为传递给渲染函数的数据,options为配置项,可以修改Context
  • EJS.clearCache 清空现有缓存
	// 所有API都绑定在 EJS 这个对象上 
	const { EJS } = require('@poorest/ejs');

	// 一些可选配置项
	EJS.configure({
	})
	
	// 注入一些
	EJS.inject(name, handle, replace)

	// 渲染模板
	EJS.render(path, data, options?)

	// 翻译模板,返回一个render函数
	EJS.complie(path: string, options?: EJS.IOptions)

配置项说明

  • strict boolean 类型,是否在模板翻译之后的函数内部使用"use strict";
  • debug boolean 类型, 是否在模版翻译时输出行号
  • rmWhitespace boolean 类型,是否移除模板每一行行首的的空格与换行符
  • scope 自定义类型,翻译模板得到的函数的内部this指针
  • delimiter string类型,模板标签的标志性字符,默认是%, 如:<%- %>
  • cache boolean类型,是否启用翻译缓存,将模板的翻译后的函数缓存起来,下次翻译时直接使用
  • cacheScheduler 内置Map类型,缓存管理的调度对象,可使用LRU算法替换
	const LRU = require('lru-cache');
    const cacheScheduler = new LRU(Object.assign({ max: 100 }, cacheOptions));
  • suffix string类型,模板文件的后缀名
  • root string类型,模板文件的根目录
  • locals string类型,默认为locals,即在模版中的全局变量的名称
  • viewLoader 函数类型,返回模版的内容,这个函数具有两个参数,第一个是模板文件的相对路径;第二个是模板翻译时的context,上面存储了翻译过程中使用的量,请不要在该函数中修改这些量
  • inject 对象数组类型, 注入到模板的函数或这变量,该对象包含namehandle两个属性,name即注入到模板中时使用的名称,handle即该对应的处理方式,可以是一个函数,也可以是变量,同时还可以使用API给模版中注入,默认注入:include功能