{"id":10759,"library":"dot","title":"doT.js Templating Engine","description":"doT.js (pronounced \"dot\") is a lightweight, concise, and exceptionally fast JavaScript templating engine. It is designed to work seamlessly in both Node.js and browser environments, distinguishing itself by compiling templates into pure JavaScript functions, which contributes to its minimal overhead and high performance. The current stable release series is 1.x, with version 1.1.3 being the latest maintenance release, offering robust CommonJS and global browser compatibility. Development is active on version 2.x, currently in beta (2.0.0-beta.1), which introduces significant enhancements such as ES6 code generation, official TypeScript typings, and improved argument handling. doT.js maintains a conservative release cadence for major versions, prioritizing stability and efficiency. Its primary differentiators are its speed, minimal footprint, and lack of external dependencies, making it a strong choice for performance-sensitive applications where simplicity is key.","status":"maintenance","version":"1.1.3","language":"javascript","source_language":"en","source_url":"git://github.com/olado/doT","tags":["javascript","template","fast","simple","templating"],"install":[{"cmd":"npm install dot","lang":"bash","label":"npm"},{"cmd":"yarn add dot","lang":"bash","label":"yarn"},{"cmd":"pnpm add dot","lang":"bash","label":"pnpm"}],"dependencies":[],"imports":[{"note":"v2.x introduces official ESM exports. For v1.x, `require('dot')` returns the doT object, and `doT.template` is accessed from there.","wrong":"const doT = require('dot');\nconst template = doT.template;","symbol":"template","correct":"import { template } from 'dot';"},{"note":"The `process` utility is part of the core doT object. In v2.x, it's a named export, while in v1.x, it's accessed via the default CommonJS import.","wrong":"const doT = require('dot');\ndoT.process(...);","symbol":"process","correct":"import { process } from 'dot';"},{"note":"Available since v2.x, which ships with official TypeScript declaration files. Provides type safety for compiled template functions.","symbol":"DoTTemplateFunction","correct":"import type { DoTTemplateFunction } from 'dot';"}],"quickstart":{"code":"import { template } from 'dot';\n\n// Basic usage with 'it' context\nconst basicTmpl = template('Hello, {{=it.name}}!');\nconsole.log(basicTmpl({ name: 'World' }));\n\n// Usage with explicit argName (v2.x feature, fallback for v1.x)\nconst multiArgTmpl = template(\n  'User ID: {{=id}}, Username: {{=username}}',\n  { argName: ['id', 'username'] } // This option is 'varname' in v1.x\n);\nconsole.log(multiArgTmpl({ id: 123, username: 'jsuser' }));\n\n// A more complex example with conditionals and loops\nconst listTmpl = template(`\n  <h2>{{=it.title}}</h2>\n  <ul>\n    {{~it.items :item:idx}}\n      <li>{{=idx + 1}}. {{=item}}</li>\n    {{~}}\n  </ul>\n  {{? it.footer}}\n    <p>{{=it.footer}}</p>\n  {{?}}\n`);\n\nconst data = {\n  title: 'My Shopping List',\n  items: ['Apples', 'Milk', 'Bread'],\n  footer: 'Happy shopping!'\n};\nconsole.log(listTmpl(data));","lang":"typescript","description":"Demonstrates basic template compilation and rendering using the `template` function, including both `it` context and multi-argument destructuring, as well as a more complex example with control flow."},"warnings":[{"fix":"Update any usage of the `varname` option to `argName` when migrating to v2.x.","message":"The template option `varname` was renamed to `argName` in v2.0.0-beta.1. Templates created with `varname` in v1.x will not work as expected if this option is used in v2.x.","severity":"breaking","affected_versions":">=2.0.0-beta.1"},{"fix":"Review import/require statements and update to `import { template } from 'dot';` for ESM environments, or ensure proper CommonJS interop is configured for mixed environments.","message":"Version 2.x of doT.js generates ES6 code by default and ships with official TypeScript typings, shifting towards ESM. While CJS is still supported, users migrating from v1.x (which is primarily CJS-focused) might need to adjust import statements for optimal compatibility.","severity":"breaking","affected_versions":">=2.0.0-beta.0"},{"fix":"For production systems, continue using the stable 1.x branch. Evaluate v2.x betas for future migration planning and testing only.","message":"doT.js v2.0.0-beta.x versions are currently pre-release. They introduce new features and breaking changes, but should not be used in production environments without thorough testing due to potential instability or further API changes.","severity":"gotcha","affected_versions":">=2.0.0-beta.0"},{"fix":"Ensure you are using doT.js version 1.1.3 or higher to mitigate the prototype pollution vulnerability. Upgrade immediately if on an older 1.x version.","message":"Version 1.1.3 patched a code injection vulnerability related to prototype pollution (#291). Older versions are susceptible to this security issue.","severity":"gotcha","affected_versions":"<1.1.3"}],"env_vars":null,"last_verified":"2026-04-19T00:00:00.000Z","next_check":"2026-07-18T00:00:00.000Z","problems":[{"fix":"For CommonJS (v1.x), ensure `const doT = require('dot');` is at the top of your file. For ESM (v2.x), use `import * as doT from 'dot';` or `import { template } from 'dot';` if only needing specific exports.","cause":"Attempting to use `doT.template` directly in an environment where `doT` is not globally available or correctly imported/required.","error":"ReferenceError: doT is not defined"},{"fix":"Verify your import statement matches your module system (CommonJS `require` for v1.x, ESM `import` for v2.x). Ensure you're accessing `template` from the correct object returned by the import.","cause":"This typically occurs when `doT` is imported incorrectly, resulting in `doT` being undefined or an object without the `template` property, or attempting to use `require` on an ESM-only build.","error":"TypeError: doT.template is not a function"},{"fix":"Replace `varname` with `argName` in your template options object to align with the v2.x API. Example: `{ argName: ['foo', 'bar'] }`.","cause":"Using the deprecated `varname` option for template arguments with doT.js v2.x in a TypeScript environment.","error":"Property 'varname' does not exist on type '{ argName: string[]; }'"}],"ecosystem":"npm"}