lohand

0.5.2 • Public • Published

Lohand

npm version Build Status Dependency Status devDependency Status

A library for wrapping many Lodash functions into Handlebars.

Installation

npm install lohand

Basic Setup

var handlebars = require('handlebars');
require('lohand')
  .registerAll(handlebars);

Individual Helpers

var lohand = require('lohand');
 
lohand.helpers; // a dictionary of helpers { name: fn() {} }

Testing

npm test

Helpers

Iterators

every

{{#every 3 [1, 2, 3]}}
  <!-- index % 3 === 0 -->
{{else}}
  <!-- otherwise -->
{{/every}}

iter

{{#iter items}}
    {{i}} // index
    {{iPlus1}} // index + 1
{{/iter}}

Collection

at

{{at [1, 2, 3] 1}}
→ 2

pluck

{{at {foo: 'bar'} 'foo'}}
→ bar

sample

{{#each (sample [1, 2, 3], 2)}}
  {{this}};
{{/each}}
1;3;

shuffle

{{#each (shuffle [1, 2, 3])}}
  {{this}};
{{/each}}
3;1;2;

size

{{size [1, 2, 3]}}
→ 3

Comparisons

endsWith

{{#endsWith 'abc' 'c'}}
  <!-- string starts with 'c' -->
{{else}}
  <!-- string does not start with 'c' -->
{{/endsWith}}

eq

{{#eq val1 val2}}
  <!-- === -->
{{else}}
  <!-- !== -->
{{/eq}}

greaterThan

{{#greaterThan left right}}
  <!-- left > right -->
{{else}}
  <!-- left <= right -->
{{/greaterThan}}

lessThan

{{#lessThan left right}}
  <!-- left < right -->
{{else}}
  <!-- left >= right -->
{{/lessThan}}

startsWith

{{#startsWith 'abc' 'a'}}
  // if 'abc' starts with 'a'
{{else}}
  // if 'abc' does not start with 'a'
{{/startsWith}}

Strings

camelCase

Utilizes Lodash’s camelCase.

{{camelCase 'Foo Bar'}}
→ fooBar

capitalize

{{capitalize 'foo bar'}}
→ Foo Bar

deburr

{{deburr 'déjà vu'}}
→ deja vu

encodeURIComponent

{{encodeURIComponent 'Foo Bar'}}
→ Foo%20Bar

kebabCase

{{kebabCase 'Foo Bar'}} // 'foo-bar'

markdown

Utilizes Showdown to transform text into Markdown.

{{{markdown '# Foo'}}}
→ <h1>Foo</h1>

encodeURIComponent

{{encodeURIComponent 'Foo Bar'}}
→ Foo%20Bar

kebabCase

{{kebabCase 'Foo Bar'}} // 'foo-bar'

markdown

{{{markdown '# Foo'}}}

pad

{{pad 'abc' 8}} // '  abc   '
{{pad 'abc' 8 '_-'}} // _-abc_-_

padLeft

{{padLeft 'abc' 6}} // '   abc'
{{padLeft 'abc' 6 '_-'}} // _-_abc

padRight

{{padRight 'abc' 6}} // 'abc   '
{{padRight 'abc' 6 '_-'}} // abc_-_

parseInt

{{parseInt '08'}} // 8

possessive

{{possessive 'Susan'}} // Susan’s
{{possessive 'Chris'}} // Chris’

repeat

{{repeat '*' 3}} // ***

snakeCase

{{snakeCase 'Foo Bar'}} // foo_bar

startCase

A naive version of “Title Case” which simply upper cases the first letter of each word.

{{startCase '--foo-bar'}}
<!-- Foo Bar -->

trim

{{trim '  abc  '}}
<!-- abc -->
 
{{trim '-_-abc-_-' '_-'}}
<!-- abc -->

trimLeft

{{trimLeft '  abc  '}}
<!-- 'abc  ' -->
 
{{trimLeft '-_-abc-_-' '_-'}}
<!-- abc-_- -->

trimRight

{{trimRight '  abc  '}}
<!-- '  abc' -->
 
{{trimRight '-_-abc-_-' '_-'}}
<!-- -_-abc -->

trunc

{{trunc 'hi-diddly-ho there, neighborino'}}
<!-- hi-diddly-ho there, neighbo... -->
 
{{trunc 'hi-diddly-ho there, neighborino' 24}}
<!-- hi-diddly-ho there, n... -->

unescape

{{unescape 'fred, barney, &amp; pebbles'}}
<!-- fred, barney, & pebbles -->

words

{{#each (words 'foo bar')}}
  <div>{{this}}</div>
{{/each}}
 
<div>foo</div>
<div>bar</div>

union

{{union [1, 2, 3] [4, 5]}}
// → [1, 2, 3, 4, 5]

Package Sidebar

Install

npm i lohand

Weekly Downloads

12

Version

0.5.2

License

GNU

Last publish

Collaborators

  • alexsomeoddpilot
  • kamil.kecki
  • megrymo