{"id":12149,"library":"tmpl","title":"tmpl JavaScript Micro Templating","description":"The `tmpl` package, version 1.0.5, is a minimalist JavaScript micro-templating utility last updated in 2013. Its primary function is basic string interpolation, replacing `{}` placeholders in a template string with corresponding values from a provided data object. This library offers a very limited feature set compared to more robust templating engines like Handlebars or EJS, lacking control flow, iteration, or helper functions. Developed before the widespread availability of native JavaScript template literals (ES6 backticks), `tmpl` is now largely superseded by built-in language features for new development. The project is considered abandoned, with no active maintenance, security updates, or new releases since its last version over a decade ago. While still accumulating significant weekly downloads, this is primarily due to its presence as a transitive dependency in older projects. It functions exclusively within CommonJS environments and offers no native support for ECMAScript Modules (ESM) or TypeScript.","status":"abandoned","version":"1.0.5","language":"javascript","source_language":"en","source_url":"https://github.com/daaku/nodejs-tmpl","tags":["javascript"],"install":[{"cmd":"npm install tmpl","lang":"bash","label":"npm"},{"cmd":"yarn add tmpl","lang":"bash","label":"yarn"},{"cmd":"pnpm add tmpl","lang":"bash","label":"pnpm"}],"dependencies":[],"imports":[{"note":"The `tmpl` package is a CommonJS module. Direct ESM imports will fail in native ESM environments without a bundler or transpiler.","wrong":"import tmpl from 'tmpl';","symbol":"tmpl","correct":"const tmpl = require('tmpl');"},{"note":"`tmpl` exports a single function as its default, not a named export. Destructuring will assign `undefined`.","wrong":"const { tmpl } = require('tmpl');","symbol":"tmpl (destructuring)","correct":"const renderTemplate = require('tmpl');"}],"quickstart":{"code":"const tmpl = require('tmpl');\n\nconst templateString = 'Hello, {name}! Your age is {age}.';\nconst data = { name: 'Alice', age: 30 };\n\nconst result = tmpl(templateString, data);\n\nconsole.log(result);\n// Expected output: Hello, Alice! Your age is 30.\n\n// Example with missing data - placeholders are left as is\nconst incompleteResult = tmpl('Missing: {missingKey}', { name: 'Bob' });\nconsole.log(incompleteResult);\n// Expected output: Missing: {missingKey}","lang":"javascript","description":"Demonstrates basic string interpolation using a template string and a data object, showing how placeholders are replaced or retained if data is missing."},"warnings":[{"fix":"It is strongly recommended to migrate away from `tmpl`. Replace its usage with native JavaScript template literals (`` `string ${variable}` ``) or a well-maintained, modern templating library. Conduct a dependency audit to identify if `tmpl` is a direct or transitive dependency and plan for its removal.","message":"The `tmpl` package is abandoned, with its last release (1.0.5) over a decade ago in 2013. This poses significant security risks due to unpatched vulnerabilities and ensures incompatibility with modern JavaScript features and environments.","severity":"breaking","affected_versions":">=1.0.0"},{"fix":"For direct usage in CommonJS, use `const tmpl = require('tmpl');`. In ESM projects, either use a bundler that can transpile CommonJS to ESM, or ideally, replace `tmpl` with native template literals.","message":"This package is designed for CommonJS environments and does not provide native ECMAScript Module (ESM) support. Attempting to `import tmpl from 'tmpl'` in a Node.js project configured for native ESM (`'type': 'module'` in `package.json`) will result in a runtime error.","severity":"gotcha","affected_versions":">=1.0.0"},{"fix":"You will need to create a custom declaration file (e.g., `tmpl.d.ts`) to provide types. For example: `declare module 'tmpl' { function tmpl(template: string, data?: object): string; export = tmpl; }`.","message":"No TypeScript type definitions (`.d.ts` files) are shipped with the `tmpl` package, nor are they available on DefinitelyTyped. Using `tmpl` in a TypeScript project will result in type errors.","severity":"gotcha","affected_versions":">=1.0.0"},{"fix":"For new code, always prefer native template literals. For existing code, refactor to use template literals wherever possible.","message":"Native JavaScript template literals (introduced in ES6/ES2015) provide a more idiomatic, performant, and secure way to achieve string interpolation (e.g., `` `Hello ${name}!` `` vs. `tmpl('Hello {name}!', { name })`).","severity":"deprecated","affected_versions":">=1.0.0"}],"env_vars":null,"last_verified":"2026-04-19T00:00:00.000Z","next_check":"2026-07-18T00:00:00.000Z","problems":[{"fix":"Ensure your project is configured for CommonJS or use a bundler that can handle CommonJS modules within an ESM context. For new code, prefer native ES module `import` statements and template literals.","cause":"Attempting to use `require()` in a native ES module environment (e.g., when `package.json` has `\"type\": \"module\"`).","error":"ReferenceError: require is not defined"},{"fix":"`tmpl` exports a single function as its default. Ensure you are importing it correctly as a default CommonJS export and calling it directly: `const result = tmpl('...', data);`.","cause":"Incorrectly attempting to invoke `tmpl` as a constructor (`new tmpl(...)`) or destructuring it incorrectly (e.g., `const { tmpl } = require('tmpl');`).","error":"TypeError: tmpl is not a function"}],"ecosystem":"npm"}