@deque/dot

中文文档
1.1.5发布于 2019/11/07MITCommonJS零依赖近 30 天下载 9181

Concise and fast javascript templating compatible with nodejs and other javascript environments

原始使用文档
文档目录7 节
  1. Features
  2. Docs, live playground and samples
  3. New in version 1.0.0
  4. Example for express
  5. Notes
  6. Author
  7. License

doT

Created in search of the fastest and concise JavaScript templating function with emphasis on performance under V8 and nodejs. It shows great performance for both nodejs and browsers.

doT.js is fast, small and has no dependencies.

Build Status npm version Coverage Status

Features

custom delimiters
runtime evaluation
runtime interpolation
compile-time evaluation
partials support
conditionals support
array iterators
encoding
control whitespace - strip or preserve
streaming friendly
use it as logic-less or with logic, it is up to you

Docs, live playground and samples

http://olado.github.com/doT (todo: update docs with new features added in version 1.0.0)

New in version 1.0.0

Added parameters support in partials

{{##def.macro:param:
    <div>{{=param.foo}}</div>
#}}

{{#def.macro:myvariable}}

Node module now supports auto-compilation of dot templates from specified path

var dots = require("dot").process({ path: "./views"});

This will compile .def, .dot, .jst files found under the specified path. Details

  • It ignores sub-directories.
  • Template files can have multiple extensions at the same time.
  • Files with .def extension can be included in other files via {{#def.name}}
  • Files with .dot extension are compiled into functions with the same name and can be accessed as renderer.filename
  • Files with .jst extension are compiled into .js files. Produced .js file can be loaded as a commonJS, AMD module, or just installed into a global variable (default is set to window.render)
  • All inline defines defined in the .jst file are compiled into separate functions and are available via _render.filename.definename

Basic usage:

       var dots = require("dot").process({path: "./views"});
       dots.mytemplate({foo:"hello world"});

The above snippet will: * Compile all templates in views folder (.dot, .def, .jst) * Place .js files compiled from .jst templates into the same folder These files can be used with require, i.e. require("./views/mytemplate") * Return an object with functions compiled from .dot templates as its properties * Render mytemplate template

CLI tool to compile dot templates into js files

./bin/dot-packer -s examples/views -d out/views

Example for express

Many people are using doT with express. I added an example of the best way of doing it examples/express:

doT with express

Notes

doU.js is here only so that legacy external tests do not break. Use doT.js.
doT.js with doT.templateSettings.append=false provides the same performance as doU.js.

Author

Laura Doktorova @olado

License

doT is licensed under the MIT License. (See LICENSE-DOT)

logo by Kevin Kirchner

Thank you @KevinKirchner for the logo.

版本与发布记录

@deque/dot 共发布 3 个版本,首次发布于 2019/07/18;过去 12 个月发布了 0 个版本。

版本发布日期距今
1.1.5latest2019/11/077 年前
1.1.42019/07/187 年前
1.1.32019/07/187 年前

关于 @deque/dot 的常见问题

@deque/dot 是什么?

Concise and fast javascript templating compatible with nodejs and other javascript environments

如何安装 @deque/dot?

在项目目录运行 npm install @deque/dot,或使用 pnpm add / yarn add / bun add。它还提供命令行工具 dottojs,可以用 npx dottojs 直接运行。

@deque/dot 支持 TypeScript 吗?

该包的 package.json 没有声明类型入口。需要类型提示时,可以在 npm 上查找社区维护的 @types/deque__dot 是否存在。

@deque/dot 支持 ESM 还是 CommonJS?

以 CommonJS 形式发布,可以直接 require();在 ES Module 项目中也可以用 import 引入(Node.js 会把 module.exports 作为默认导出)。

@deque/dot 可以商用吗?

@deque/dot 使用 MIT 许可。宽松许可:允许商业使用、修改和再分发,通常只需在分发时保留原版权与许可声明。以上为概括,不构成法律意见,请以许可原文为准。

@deque/dot 的下载量有多少?

根据 npm 官方下载统计,@deque/dot 在 2026/10/12 – 2026/11/10 这 30 天内被下载 9,181 次,日均约 306 次。下载量会把 CI 构建、镜像同步和作为其他包依赖的安装一并计入,适合横向比较热度,不能直接等同于使用人数。

@deque/dot 还在维护吗?

最新版本 1.1.5 发布于 2019/11/07(7 年前);至今共发布 3 个版本,其中过去 12 个月发布了 0 个;首次发布于 2019/07/18。发布频率只是参考信号:功能稳定的工具可能很少需要更新,建议结合源码仓库的 issue 和提交记录判断。