# dollar.template

> Using $.template() like _.template()

Latest version **0.0.6** (published 2017-03-30) · MIT license · 0 weekly downloads

## Install

```sh
npm install dollar.template
pnpm add dollar.template
yarn add dollar.template
bun add dollar.template
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support; pre 1.0.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.0.6 |
| Published | 2017-03-30 |
| First published | 2016-11-05 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 0 |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 2 |
| Author | 7anshuai |
| Maintainers | 7anshuai |
| Keywords | template, underscore.template, jQuery.template, Zepto.template, $.template |

## Links

- npm: https://www.npmjs.com/package/dollar.template
- Repository: https://github.com/7anshuai/dollar.template
- Homepage: https://github.com/7anshuai/dollar.template#readme
- Issues: https://github.com/7anshuai/dollar.template/issues
- npm.io page: https://npm.io/package/dollar.template

## Alternatives

- [gamedig](https://npm.io/package/gamedig.md) — 29.3K weekly downloads
- [join-monster](https://npm.io/package/join-monster.md) — 12.8K weekly downloads
- [masked](https://npm.io/package/masked.md) — 5.5K weekly downloads
- [@comunica/actor-query-process-explain-logical](https://npm.io/package/@comunica/actor-query-process-explain-logical.md) — 4.7K weekly downloads
- [@veracity/vui](https://npm.io/package/@veracity/vui.md) — 4.6K weekly downloads

## Recent versions

- 0.0.6 (latest) — 2017-03-30
- 0.0.5 — 2016-11-16
- 0.0.4 — 2016-11-07
- 0.0.3 — 2016-11-05
- 0.0.2 — 2016-11-05
- 0.0.1 — 2016-11-05

## README

# $.template() [![Build Status](https://travis-ci.org/7anshuai/dollar.template.svg?branch=master)](https://travis-ci.org/7anshuai/dollar.template)

[![NPM](https://nodei.co/npm/dollar.template.png?downloads=true)](https://nodei.co/npm/dollar.template/)

Use $.template() like _.template(), compiles JavaScript templates into functions that can be evaluated for rendering.

Code copied from [Underscore.js](http://underscorejs.org), just renamed `_.template` to `$.template`, and exports some dependency methods to $. You can use it as a jQuery or Zepto plugin, or use directly in Node.js. 


## Installation

### NPM

```
npm install dollar.template
```

### Bower

```
bower install dollar.template
```

## Usage

### Node.js

```javascript
var template = require('dollar.template').template;

var compiled = template("hello: <%= name %>");
compiled({name: 'moe'}); // "hello: moe"

var tmpl = template("<b><%- value %></b>");
tmpl({value: '<script>'}); // "<b>&lt;script&gt;</b>"
```

### Browser

```html
<script src="/js/jquery.js"></script> <!-- also works with zepto -->
<script src="/js/dollar.template.js"></script>
```

```javascript
var compiled = $.template("hello: <%= name %>");
compiled({name: 'moe'}); // "hello: moe"
```

### Require.js

```html
<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <title>$.template()</title>
</head>
<body>
  <div></div>
  <script src="bower_components/requirejs/require.js"></script>
  <script>
    requirejs.config({
      baseUrl: "./",
      paths: {
        jquery: "bower_components/jquery/dist/jquery", // set jquery path to zepto if we want to use zepto
      }
    });
  </script>
  <script>
    require(['jquery'], ["bower_components/dollar.template/dollar.template"], function ($, template){
      var compiled = template("hello: <%= name %>"); // you can use $.template directly
      $("div").text(compiled({name: "moe"})); // "hello: moe"
    });
  </script>
</body>
</html>
```

## Testing

```
npm test
```

## API

- $.isObject - `$.isObject({});` => `true`
- $.keys - `$.keys({one: 1, two: 2, three: 3});` => `["one", "two", "three"]`
- $.allkeys - See [_.allkeys](http://underscorejs.org/#allKeys)
- $.invert - `$.invert({Moe: "Moses", Larry: "Louis", Curly: "Jerome"});` => `{Moses: "Moe", Louis: "Larry", Jerome: "Curly"};`
- $.has - `$.has({a: 1, b: 2, c: 3}, "b");` => `true`
- $.escape - `$.escape('Curly, Larry & Moe');` => `"Curly, Larry &amp; Moe"`
- $.unescape - `$.unescape('Curly, Larry &amp; Moe');` => `"Curly, Larry & Moe"`
- $.defaults - See [_.defaults](http://underscorejs.org/#defaults)
- $.template - See [_.template](http://underscorejs.org/#template)

## License

[MIT](/LICENSE)

---
_Source: https://npm.io/package/dollar.template · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
