@jaredwray/fumanchu 3.0.4 → 3.1.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (3) hide show
  1. package/README.md +27 -2422
  2. package/dist/index.js +2 -2
  3. package/package.json +7 -7
package/README.md CHANGED
@@ -10,16 +10,36 @@ Handlebars + Helpers Together
10
10
  [![GitHub license](https://img.shields.io/github/license/jaredwray/fumanchu)](https://github.com/jaredwray/fumanchu/blob/master/LICENSE)
11
11
  [![npm](https://img.shields.io/npm/dm/@jaredwray/fumanchu)](https://npmjs.com/package/@jaredwray/fumanchu)
12
12
 
13
- [Handlebars](https://github.com/handlebars-lang/handlebars.js) + [Handlebars-helpers](https://github.com/helpers/handlebars-helpers) (helpers are now maintained in this project) combined into a single package. Easily use it as a drop in replacement when using handlebars directly.
13
+ [Handlebars](https://github.com/handlebars-lang/handlebars.js) + [Handlebars-helpers](https://github.com/helpers/handlebars-helpers) (helpers are now maintained in this project) combined into a single package. Easily use it as a drop in replacement when using handlebars directly. More than 180 Handlebars helpers in ~20 categories. Helpers can be used with Assemble, Generate, Verb, Ghost, gulp-handlebars, grunt-handlebars, consolidate, or any node.js/Handlebars project. Currently **189 helpers** in **20 categories**! 🎉
14
14
 
15
15
  # Table of Contents
16
16
  * [Using in Nodejs](#using-in-nodejs)
17
17
  * [Just using Handlebar Helpers](#using-handlebars-helpers)
18
- * [Helpers](#helpers)
18
+ * [Helpers](https://fumanchu.org/docs/helpers/)
19
+ * [array](https://fumanchu.org/docs/helpers/array/)
20
+ * [code](https://fumanchu.org/docs/helpers/code/)
21
+ * [comparison](https://fumanchu.org/docs/helpers/comparison/)
22
+ * [collection](https://fumanchu.org/docs/helpers/collection/)
23
+ * [date](https://fumanchu.org/docs/helpers/date/)
24
+ * [fs](https://fumanchu.org/docs/helpers/fs/)
25
+ * [html](https://fumanchu.org/docs/helpers/html/)
26
+ * [i18n](https://fumanchu.org/docs/helpers/i18n/)
27
+ * [inflection](https://fumanchu.org/docs/helpers/inflection/)
28
+ * [logging](https://github.com/jonathas/logging-helpers)
29
+ * [markdown](https://fumanchu.org/docs/helpers/markdown/)
30
+ * [match](https://fumanchu.org/docs/helpers/match/)
31
+ * [math](https://fumanchu.org/docs/helpers/math/)
32
+ * [misc](https://fumanchu.org/docs/helpers/misc/)
33
+ * [number](https://fumanchu.org/docs/helpers/number/)
34
+ * [object](https://fumanchu.org/docs/helpers/object/)
35
+ * [path](https://fumanchu.org/docs/helpers/path/)
36
+ * [regex](https://fumanchu.org/docs/helpers/regex/)
37
+ * [string](https://fumanchu.org/docs/helpers/string/)
38
+ * [url](https://fumanchu.org/docs/helpers/url/)
39
+ * [utils](https://fumanchu.org/docs/helpers/utils/)
19
40
  * [How to Contribute](#how-to-contribute)
20
41
  * [License and Copyright](#license-and-copyright)
21
42
 
22
-
23
43
  # Usage Nodejs
24
44
 
25
45
  ```bash
@@ -63,7 +83,8 @@ If you only want to use handlebar helpers you can easily do that by doing the fo
63
83
  ```javascript
64
84
  var {helpers} = require('@jaredwray/fumanchu');
65
85
  var handlebars = require('handlebars');
66
- helpers({ handlebars: handlebars });
86
+ var helpersFunction = await helpers();
87
+ helpersFunction({ handlebars: handlebars });
67
88
  var fn = handlebars.compile('{{add value 5}}');
68
89
  console.log(fn); // 10
69
90
  ```
@@ -73,2429 +94,13 @@ If using it with es6 you can access `helpers` via destructuring:
73
94
  ```javascript
74
95
  import {helpers} from '@jaredwray/fumanchu';
75
96
  import handlebars from 'handlebars';
76
- helpers({ handlebars: handlebars });
97
+ const helpersFunction = await helpers();
98
+ helpersFunction({ handlebars: handlebars });
77
99
  const template = handlebars.compile('{{#if (eq foo "bar")}}<p>Foo is bar</p>{{/if}}');
78
100
  const html = template({foo: 'bar'});
79
101
  console.log(html); // <p>Foo is bar</p>
80
102
  ```
81
103
 
82
- # Helpers
83
- More than 180 Handlebars helpers in ~20 categories. Helpers can be used with Assemble, Generate, Verb, Ghost, gulp-handlebars, grunt-handlebars, consolidate, or any node.js/Handlebars project.
84
-
85
- ## Categories
86
-
87
- Currently **189 helpers** in **20 categories**:
88
-
89
- * **[array](#array)** ([code](lib/array.js) | [unit tests](test/array.js))
90
- * **[code](#code)** ([code](lib/code.js) | [unit tests](test/code.js))
91
- * **[collection](#collection)** ([code](lib/collection.js) | [unit tests](test/collection.js))
92
- * **[comparison](#comparison)** ([code](lib/comparison.js) | [unit tests](test/comparison.js))
93
- * **[date](#date)** ([code](lib/date.js) | [unit tests](test/date.js))
94
- * **[fs](#fs)** ([code](lib/fs.js) | [unit tests](test/fs.js))
95
- * **[html](#html)** ([code](lib/html.js) | [unit tests](test/html.js))
96
- * **[i18n](#i18n)** ([code](lib/i18n.js) | [unit tests](test/i18n.js))
97
- * **[inflection](#inflection)** ([code](lib/inflection.js) | [unit tests](test/inflection.js))
98
- * **[logging](#logging)** ([code](lib/logging.js) | [unit tests](test/logging.js))
99
- * **[markdown](#markdown)** ([code](lib/markdown.js) | [unit tests](test/markdown.js))
100
- * **[match](#match)** ([code](lib/match.js) | [unit tests](test/match.js))
101
- * **[math](#math)** ([code](lib/math.js) | [unit tests](test/math.js))
102
- * **[misc](#misc)** ([code](lib/misc.js) | [unit tests](test/misc.js))
103
- * **[number](#number)** ([code](lib/number.js) | [unit tests](test/number.js))
104
- * **[object](#object)** ([code](lib/object.js) | [unit tests](test/object.js))
105
- * **[path](#path)** ([code](lib/path.js) | [unit tests](test/path.js))
106
- * **[regex](#regex)** ([code](lib/regex.js) | [unit tests](test/regex.js))
107
- * **[string](#string)** ([code](lib/string.js) | [unit tests](test/string.js))
108
- * **[url](#url)** ([code](lib/url.js) | [unit tests](test/url.js))
109
-
110
- # All helpers
111
-
112
- ### [code helpers](#code)
113
-
114
- Visit the: [code](lib/code.js) | [unit tests](test/code.js) | [issues](https://github.com/jonathas/handlebars-helpers/issues?utf8=%E2%9C%93&q=is%3Aissue+is%3Aopen+code+helpers))
115
-
116
- * **[embed](#embed)** ([code](lib/code.js#L23) | [tests](test/code.js#L10))
117
- * **[gist](#gist)** ([code](lib/code.js#L45) | [tests](test/code.js#L62))
118
- * **[jsfiddle](#jsfiddle)** ([code](lib/code.js#L60) | [tests](test/code.js#L69))
119
-
120
- ### [collection helpers](#collection)
121
-
122
- Visit the: [code](lib/collection.js) | [unit tests](test/collection.js) | [issues](https://github.com/jonathas/handlebars-helpers/issues?utf8=%E2%9C%93&q=is%3Aissue+is%3Aopen+collection+helpers))
123
-
124
- * **[isEmpty](#isEmpty)** ([code](lib/collection.js#L31) | [tests](test/collection.js#L14))
125
- * **[iterate](#iterate)** ([code](lib/collection.js#L59) | [tests](test/collection.js#L68))
126
-
127
- ### [comparison helpers](#comparison)
128
-
129
- Visit the: [code](lib/comparison.js) | [unit tests](test/comparison.js) | [issues](https://github.com/jonathas/handlebars-helpers/issues?utf8=%E2%9C%93&q=is%3Aissue+is%3Aopen+comparison+helpers))
130
-
131
- * **[and](#and)** ([code](lib/comparison.js#L27) | [tests](test/comparison.js#L10))
132
- * **[compare](#compare)** ([code](lib/comparison.js#L57) | [tests](test/comparison.js#L41))
133
- * **[contains](#contains)** ([code](lib/comparison.js#L124) | [tests](test/comparison.js#L167))
134
- * **[default](#default)** ([code](lib/comparison.js#L143) | [tests](test/comparison.js#L204))
135
- * **[eq](#eq)** ([code](lib/comparison.js#L165) | [tests](test/comparison.js#L351))
136
- * **[gt](#gt)** ([code](lib/comparison.js#L188) | [tests](test/comparison.js#L214))
137
- * **[gte](#gte)** ([code](lib/comparison.js#L212) | [tests](test/comparison.js#L245))
138
- * **[has](#has)** ([code](lib/comparison.js#L232) | [tests](test/comparison.js#L260))
139
- * **[isFalsey](#isFalsey)** ([code](lib/comparison.js#L274) | [tests](test/comparison.js#L327))
140
- * **[isTruthy](#isTruthy)** ([code](lib/comparison.js#L289) | [tests](test/comparison.js#L339))
141
- * **[ifEven](#ifEven)** ([code](lib/comparison.js#L310) | [tests](test/comparison.js#L368))
142
- * **[ifNth](#ifNth)** ([code](lib/comparison.js#L327) | [tests](test/comparison.js#L380))
143
- * **[ifOdd](#ifOdd)** ([code](lib/comparison.js#L350) | [tests](test/comparison.js#L403))
144
- * **[is](#is)** ([code](lib/comparison.js#L274) | [tests](test/comparison.js#L327))
145
- * **[isnt](#isnt)** ([code](lib/comparison.js#L389) | [tests](test/comparison.js#L432))
146
- * **[lt](#lt)** ([code](lib/comparison.js#L411) | [tests](test/comparison.js#L449))
147
- * **[lte](#lte)** ([code](lib/comparison.js#L435) | [tests](test/comparison.js#L476))
148
- * **[neither](#neither)** ([code](lib/comparison.js#L456) | [tests](test/comparison.js#L511))
149
- * **[not](#not)** ([code](lib/comparison.js#L470) | [tests](test/comparison.js#L624))
150
- * **[or](#or)** ([code](lib/comparison.js#L492) | [tests](test/comparison.js#L523))
151
- * **[unlessEq](#unlessEq)** ([code](lib/comparison.js#L518) | [tests](test/comparison.js#L556))
152
- * **[unlessGt](#unlessGt)** ([code](lib/comparison.js#L538) | [tests](test/comparison.js#L567))
153
- * **[unlessLt](#unlessLt)** ([code](lib/comparison.js#L558) | [tests](test/comparison.js#L578))
154
- * **[unlessGteq](#unlessGteq)** ([code](lib/comparison.js#L578) | [tests](test/comparison.js#L589))
155
- * **[unlessLteq](#unlessLteq)** ([code](lib/comparison.js#L598) | [tests](test/comparison.js#L604))
156
-
157
- ### [date helpers](#date)
158
-
159
- Visit the: [code](lib/date.js) | [unit tests](test/date.js) | [issues](https://github.com/jonathas/handlebars-helpers/issues?utf8=%E2%9C%93&q=is%3Aissue+is%3Aopen+date+helpers))
160
-
161
- * **[year](#year)** ([code](lib/date.js#L15) | [no tests])
162
- * **[date](#date)** ([code](lib/date.js#Lundefined) | [no tests])
163
- * **[moment](#moment)** ([code](lib/date.js#L24) | [no tests])
164
-
165
- ### [fs helpers](#fs)
166
-
167
- Visit the: [code](lib/fs.js) | [unit tests](test/fs.js) | [issues](https://github.com/jonathas/handlebars-helpers/issues?utf8=%E2%9C%93&q=is%3Aissue+is%3Aopen+fs+helpers))
168
-
169
- * **[fileSize](#fileSize)** ([code](lib/fs.js#L14) | [no tests])
170
- * **[read](#read)** ([code](lib/fs.js#L29) | [tests](test/fs.js#L16))
171
- * **[readdir](#readdir)** ([code](lib/fs.js#L42) | [tests](test/fs.js#L23))
172
-
173
- ### [html helpers](#html)
174
-
175
- Visit the: [code](lib/html.js) | [unit tests](test/html.js) | [issues](https://github.com/jonathas/handlebars-helpers/issues?utf8=%E2%9C%93&q=is%3Aissue+is%3Aopen+html+helpers))
176
-
177
- * **[attr](#attr)** ([code](lib/html.js#L23) | [tests](test/html.js#L13))
178
- * **[css](#css)** ([code](lib/html.js#L45) | [tests](test/html.js#L21))
179
- * **[js](#js)** ([code](lib/html.js#L89) | [tests](test/html.js#L69))
180
- * **[sanitize](#sanitize)** ([code](lib/html.js#L121) | [tests](test/html.js#L98))
181
- * **[ul](#ul)** ([code](lib/html.js#L135) | [tests](test/html.js#L108))
182
- * **[ol](#ol)** ([code](lib/html.js#L154) | [tests](test/html.js#L115))
183
- * **[thumbnailImage](#thumbnailImage)** ([code](lib/html.js#L176) | [tests](test/html.js#L122))
184
-
185
- ### [i18n helpers](#i18n)
186
-
187
- Visit the: [code](lib/i18n.js) | [unit tests](test/i18n.js) | [issues](https://github.com/jonathas/handlebars-helpers/issues?utf8=%E2%9C%93&q=is%3Aissue+is%3Aopen+i18n+helpers))
188
-
189
- * **[i18n](#i18n)** ([code](lib/i18n.js#L18) | [tests](test/i18n.js#L11))
190
-
191
- ### [inflection helpers](#inflection)
192
-
193
- Visit the: [code](lib/inflection.js) | [unit tests](test/inflection.js) | [issues](https://github.com/jonathas/handlebars-helpers/issues?utf8=%E2%9C%93&q=is%3Aissue+is%3Aopen+inflection+helpers))
194
-
195
- * **[inflect](#inflect)** ([code](lib/inflection.js#L30) | [tests](test/inflection.js#L9))
196
- * **[ordinalize](#ordinalize)** ([code](lib/inflection.js#L58) | [tests](test/inflection.js#L22))
197
-
198
- ### [logging helpers](#logging)
199
-
200
- Visit the: [code](lib/logging.js) | [unit tests](test/logging.js) | [issues](https://github.com/jonathas/handlebars-helpers/issues?utf8=%E2%9C%93&q=is%3Aissue+is%3Aopen+logging+helpers))
201
-
202
- * **[log](#log)** ([code](lib/logging.js#Lundefined) | [no tests])
203
- * **[ok](#ok)** ([code](lib/logging.js#Lundefined) | [no tests])
204
- * **[success](#success)** ([code](lib/logging.js#Lundefined) | [no tests])
205
- * **[info](#info)** ([code](lib/logging.js#Lundefined) | [no tests])
206
- * **[warning](#warning)** ([code](lib/logging.js#Lundefined) | [no tests])
207
- * **[warn](#warn)** ([code](lib/logging.js#Lundefined) | [no tests])
208
- * **[error](#error)** ([code](lib/logging.js#Lundefined) | [no tests])
209
- * **[danger](#danger)** ([code](lib/logging.js#Lundefined) | [no tests])
210
- * **[bold](#bold)** ([code](lib/logging.js#Lundefined) | [no tests])
211
- * **[_debug](#_debug)** ([code](lib/logging.js#Lundefined) | [no tests])
212
- * **[_inspect](#_inspect)** ([code](lib/logging.js#Lundefined) | [no tests])
213
-
214
- ### [markdown helpers](#markdown)
215
-
216
- * **[markdown](#markdown)** ([code](lib/markdown.js#Lundefined) | [tests](test/markdown.js#L10))
217
- * **[md](#md)** ([code](lib/markdown.js#L55) | [tests](test/markdown.js#L18))
218
-
219
- ### [match helpers](#match)
220
-
221
- Visit the: [code](lib/match.js) | [unit tests](test/match.js) | [issues](https://github.com/jonathas/handlebars-helpers/issues?utf8=%E2%9C%93&q=is%3Aissue+is%3Aopen+match+helpers))
222
-
223
- * **[match](#match)** ([code](lib/match.js#L23) | [tests](test/match.js#L13))
224
- * **[isMatch](#isMatch)** ([code](lib/match.js#L47) | [tests](test/match.js#L61))
225
- * **[mm](#mm)** ([code](lib/match.js#L56) | [tests](test/match.js#L67))
226
-
227
- ### [math helpers](#math)
228
-
229
- Visit the: [code](lib/math.js) | [unit tests](test/math.js) | [issues](https://github.com/jonathas/handlebars-helpers/issues?utf8=%E2%9C%93&q=is%3Aissue+is%3Aopen+math+helpers))
230
-
231
- * **[abs](#abs)** ([code](lib/math.js#L15) | [test](test/math.js#L149))
232
- * **[add](#add)** ([code](lib/math.js#L31) | [tests](test/math.js#L10))
233
- * **[avg](#avg)** ([code](lib/math.js#L54) | [tests](test/math.js#L25))
234
- * **[ceil](#ceil)** ([code](lib/math.js#L69) | [tests](test/math.js#L29))
235
- * **[divide](#divide)** ([code](lib/math.js#L84) | [tests](test/math.js#L36))
236
- * **[floor](#floor)** ([code](lib/math.js#L102) | [tests](test/math.js#L43))
237
- * **[minus](#minus)** ([code](lib/math.js#L118) | [tests](test/math.js#L169))
238
- * **[modulo](#modulo)** ([code](lib/math.js#L137) | [tests](test/math.js#L191))
239
- * **[multiply](#multiply)** ([code](lib/math.js#L157) | [tests](test/math.js#L50))
240
- * **[plus](#plus)** ([code](lib/math.js#L175) | [tests](test/math.js#L231))
241
- * **[random](#random)** ([code](lib/math.js#L194) | [tests](test/math.js#L102))
242
- * **[remainder](#remainder)** ([code](lib/math.js#L212) | [tests](test/math.js#L57))
243
- * **[round](#round)** ([code](lib/math.js#L224) | [tests](test/math.js#L69))
244
- * **[subtract](#subtract)** ([code](lib/math.js#L241) | [tests](test/math.js#L76))
245
- * **[sum](#sum)** ([code](lib/math.js#L263) | [tests](test/math.js#L83))
246
- * **[times](#times)** ([code](lib/math.js#L286) | [tests](test/math.js#L299))
247
-
248
- ### [misc helpers](#misc)
249
-
250
- Visit the: [code](lib/misc.js) | [unit tests](test/misc.js) | [issues](https://github.com/jonathas/handlebars-helpers/issues?utf8=%E2%9C%93&q=is%3Aissue+is%3Aopen+misc+helpers))
251
-
252
- * **[frame](#frame)** ([code](lib/misc.js#L11) | [tests](test/misc.js#L1))
253
- * **[option](#option)** ([code](lib/misc.js#L26) | [tests](test/misc.js#L20))
254
- * **[noop](#noop)** ([code](lib/misc.js#L39) | [tests](test/misc.js#L13))
255
- * **[typeOf](#typeOf)** ([code](lib/misc.js#L59) | [tests](test/misc.js#L38))
256
- * **[withHash](#withHash)** ([code](lib/misc.js#L71) | [tests](test/misc.js#L38))
257
-
258
- ### [number helpers](#number)
259
-
260
- Visit the: [code](lib/number.js) | [unit tests](test/number.js) | [issues](https://github.com/jonathas/handlebars-helpers/issues?utf8=%E2%9C%93&q=is%3Aissue+is%3Aopen+number+helpers))
261
-
262
- * **[bytes](#bytes)** ([code](lib/number.js#L24) | [tests](test/number.js#L10))
263
- * **[addCommas](#addCommas)** ([code](lib/number.js#L61) | [tests](test/number.js#L84))
264
- * **[phoneNumber](#phoneNumber)** ([code](lib/number.js#L74) | [tests](test/number.js#L30))
265
- * **[toAbbr](#toAbbr)** ([code](lib/number.js#L92) | [tests](test/number.js#L91))
266
- * **[toExponential](#toExponential)** ([code](lib/number.js#L130) | [tests](test/number.js#L59))
267
- * **[toFixed](#toFixed)** ([code](lib/number.js#L153) | [tests](test/number.js#L37))
268
- * **[toFloat](#toFloat)** ([code](lib/number.js#L169) | [tests](test/number.js#L77))
269
- * **[toInt](#toInt)** ([code](lib/number.js#L179) | [tests](test/number.js#L70))
270
- * **[toPrecision](#toPrecision)** ([code](lib/number.js#L196) | [tests](test/number.js#L48))
271
-
272
- ### [object helpers](#object)
273
-
274
- Visit the: [code](lib/object.js) | [unit tests](test/object.js) | [issues](https://github.com/jonathas/handlebars-helpers/issues?utf8=%E2%9C%93&q=is%3Aissue+is%3Aopen+object+helpers))
275
-
276
- * **[extend](#extend)** ([code](lib/object.js#L18) | [tests](test/object.js#L15))
277
- * **[forIn](#forIn)** ([code](lib/object.js#L55) | [tests](test/object.js#L33))
278
- * **[forOwn](#forOwn)** ([code](lib/object.js#L81) | [tests](test/object.js#L50))
279
- * **[toPath](#toPath)** ([code](lib/object.js#L106) | [tests](test/object.js#L87))
280
- * **[get](#get)** ([code](lib/object.js#L128) | [tests](test/object.js#L77))
281
- * **[getObject](#getObject)** ([code](lib/object.js#L149) | [tests](test/object.js#L77))
282
- * **[hasOwn](#hasOwn)** ([code](lib/object.js#L167) | [tests](test/object.js#L126))
283
- * **[isObject](#isObject)** ([code](lib/object.js#L183) | [tests](test/object.js#L144))
284
- * **[JSONparse](#JSONparse)** ([code](lib/object.js#L201) | [tests](test/object.js#L164))
285
- * **[JSONstringify](#JSONstringify)** ([code](lib/object.js#L218) | [no tests])
286
- * **[merge](#merge)** ([code](lib/object.js#L235) | [tests](test/object.js#L156))
287
- * **[parseJSON](#parseJSON)** ([code](lib/object.js#L254) | [no tests])
288
- * **[pick](#pick)** ([code](lib/object.js#L267) | [tests](test/object.js#L171))
289
- * **[stringify](#stringify)** ([code](lib/object.js#L290) | [tests](test/object.js#L199))
290
-
291
- ### [path helpers](#path)
292
-
293
- Visit the: [code](lib/path.js) | [unit tests](test/path.js) | [issues](https://github.com/jonathas/handlebars-helpers/issues?utf8=%E2%9C%93&q=is%3Aissue+is%3Aopen+path+helpers))
294
-
295
- * **[absolute](#absolute)** ([code](lib/path.js#L20) | [tests](test/path.js#L13))
296
- * **[dirname](#dirname)** ([code](lib/path.js#L40) | [tests](test/path.js#L25))
297
- * **[relative](#relative)** ([code](lib/path.js#L59) | [tests](test/path.js#L32))
298
- * **[basename](#basename)** ([code](lib/path.js#L81) | [tests](test/path.js#L47))
299
- * **[stem](#stem)** ([code](lib/path.js#L100) | [tests](test/path.js#L58))
300
- * **[extname](#extname)** ([code](lib/path.js#L119) | [tests](test/path.js#L69))
301
- * **[resolve](#resolve)** ([code](lib/path.js#L138) | [tests](test/path.js#L145))
302
- * **[segments](#segments)** ([code](lib/path.js#L166) | [tests](test/path.js#L80))
303
-
304
- ### [regex helpers](#regex)
305
-
306
- Visit the: [code](lib/regex.js) | [unit tests](test/regex.js) | [issues](https://github.com/jonathas/handlebars-helpers/issues?utf8=%E2%9C%93&q=is%3Aissue+is%3Aopen+regex+helpers))
307
-
308
- * **[toRegex](#toRegex)** ([code](lib/regex.js#L19) | [tests](test/regex.js#10))
309
- * **[test](#test)** ([code](lib/regex.js#L42) | [tests](test/regex.js#15))
310
-
311
- ### [string helpers](#string)
312
-
313
- Visit the: [code](lib/string.js) | [unit tests](test/string.js) | [issues](https://github.com/jonathas/handlebars-helpers/issues?utf8=%E2%9C%93&q=is%3Aissue+is%3Aopen+string+helpers))
314
-
315
- * **[append](#append)** ([code](lib/string.js#L22) | [tests](test/string.js#L9))
316
- * **[camelcase](#camelcase)** ([code](lib/string.js#L41) | [tests](test/string.js#L10))
317
- * **[capitalize](#capitalize)** ([code](lib/string.js#L60) | [tests](test/string.js#L25))
318
- * **[capitalizeAll](#capitalizeAll)** ([code](lib/string.js#L77) | [tests](test/string.js#L36))
319
- * **[center](#center)** ([code](lib/string.js#L95) | [tests](test/string.js#L47))
320
- * **[chop](#chop)** ([code](lib/string.js#L125) | [tests](test/string.js#L58))
321
- * **[dashcase](#dashcase)** ([code](lib/string.js#L143) | [tests](test/string.js#L73))
322
- * **[dotcase](#dotcase)** ([code](lib/string.js#L162) | [tests](test/string.js#L88))
323
- * **[downcase](#downcase)** ([code](lib/string.js#L182) | [tests](test/string.js#L391))
324
- * **[ellipsis](#ellipsis)** ([code](lib/string.js#L202) | [tests](test/string.js#L103))
325
- * **[hyphenate](#hyphenate)** ([code](lib/string.js#L223) | [tests](test/string.js#L118))
326
- * **[isString](#isString)** ([code](lib/string.js#L240) | [tests](test/string.js#L129))
327
- * **[lowercase](#lowercase)** ([code](lib/string.js#L256) | [tests](test/string.js#L151))
328
- * **[occurrences](#occurrences)** ([code](lib/string.js#L278) | [tests](test/string.js#L162))
329
- * **[pascalcase](#pascalcase)** ([code](lib/string.js#L303) | [tests](test/string.js#L173))
330
- * **[pathcase](#pathcase)** ([code](lib/string.js#L323) | [tests](test/string.js#L188))
331
- * **[plusify](#plusify)** ([code](lib/string.js#L343) | [tests](test/string.js#L203))
332
- * **[prepend](#prepend)** ([code](lib/string.js#L363) | [tests](test/string.js#L409))
333
- * **[raw](#raw)** ([code](lib/string.js#L385) | [tests](test/string.js#L465))
334
- * **[remove](#remove)** ([code](lib/string.js#L413) | [tests](test/string.js#L416)
335
- * **[removeFirst](#removeFirst)** ([code](lib/string.js#L432) | [tests](test/string.js#L422))
336
- * **[replace](#replace)** ([code](lib/string.js#L452) | [tests](test/string.js#L222))
337
- * **[replaceFirst](#replaceFirst)** ([code](lib/string.js#L473) | [tests](test/string.js#L428))
338
- * **[reverse](#reverse)** ([code](lib/string.js#L492) | [tests](test/string.js#L241))
339
- * **[sentence](#sentence)** ([code](lib/string.js#L509) | [tests](test/string.js#L252))
340
- * **[snakecase](#snakecase)** ([code](lib/string.js#L528) | [tests](test/string.js#L263))
341
- * **[split](#split)** ([code](lib/string.js#L547) | [tests](test/string.js#L278))
342
- * **[startsWith](#startsWith)** ([code](lib/string.js#L572) | [tests](test/string.js#L293))
343
- * **[titleize](#titleize)** ([code](lib/string.js#L596) | [tests](test/string.js#L312))
344
- * **[trim](#trim)** ([code](lib/string.js#L623) | [tests](test/string.js#L323))
345
- * **[trimLeft](#trimLeft)** ([code](lib/string.js#L639) | [tests](test/string.js#L436))
346
- * **[trimRight](#trimRight)** ([code](lib/string.js#L657) | [tests](test/string.js#L441))
347
- * **[truncate](#truncate)** ([code](lib/string.js#L680) | [tests](test/string.js#L338))
348
- * **[truncateWords](#truncateWords)** ([code](lib/string.js#L712) | [tests](test/string.js#L447)))
349
- * **[upcase](#upcase)** ([code](lib/string.js#L742) | [tests](test/string.js#458))
350
- * **[uppercase](#uppercase)** ([code](lib/string.js#L763) | [tests](test/string.js#L362))
351
-
352
- ### [url helpers](#url)
353
-
354
- Visit the: [code](lib/url.js) | [unit tests](test/url.js) | [issues](https://github.com/jonathas/handlebars-helpers/issues?utf8=%E2%9C%93&q=is%3Aissue+is%3Aopen+url+helpers))
355
-
356
- * **[encodeURI](#encodeURI)** ([code](lib/url.js#L19) | [tests](test/url.js#L31))
357
- * **[escape](#escape)** ([code](lib/url.js#L34) | [tests](test/url.js#L81))
358
- * **[decodeURI](#decodeURI)** ([code](lib/url.js#L48) | [tests](test/url.js#L38))
359
- * **[url_encode](#url_encode)** ([code](lib/url.js#L59) | [tests](test/url.js#L89))
360
- * **[url_decode](#url_decode)** ([code](lib/url.js#L68) | [tests](test/url.js#L93))
361
- * **[urlResolve](#urlResolve)** ([code](lib/url.js#L82) | [tests](test/url.js#L11))
362
- * **[urlParse](#urlParse)** ([code](lib/url.js#L94) | [tests](test/url.js#L45))
363
- * **[stripQuerystring](#stripQuerystring)** ([code](lib/url.js#L106) | [tests](test/url.js#L24))
364
- * **[stripProtocol](#stripProtocol)** ([code](lib/url.js#L126) | [tests](test/url.js#L53))
365
-
366
-
367
-
368
- ### [{{embed}}](lib/code.js#L23)
369
-
370
- Embed code from an external file as preformatted text.
371
-
372
- **Params**
373
-
374
- * `filepath` **{String}**: filepath to the file to embed.
375
- * `language` **{String}**: Optionally specify the language to use for syntax highlighting.
376
- * `returns` **{String}**
377
-
378
- **Example**
379
-
380
- ```html
381
- {{embed 'path/to/file.js'}}
382
- <!-- optionally specify the language to use -->
383
- {{embed 'path/to/file.hbs' 'html')}}
384
- ```
385
-
386
- ### [{{gist}}](lib/code.js#L45)
387
-
388
- Embed a GitHub Gist using only the id of the Gist
389
-
390
- **Params**
391
-
392
- * `id` **{String}**
393
- * `returns` **{String}**
394
-
395
- **Example**
396
-
397
- ```html
398
- {{gist "12345"}}
399
- ```
400
-
401
- ### [{{jsfiddle}}](lib/code.js#L60)
402
-
403
- Generate the HTML for a jsFiddle link with the given `params`
404
-
405
- **Params**
406
-
407
- * `params` **{Object}**
408
- * `returns` **{String}**
409
-
410
- **Example**
411
-
412
- ```html
413
- {{jsfiddle id="0dfk10ks" tabs="true"}}
414
- ```
415
-
416
- ## collection
417
-
418
- ### [{{isEmpty}}](lib/collection.js#L31)
419
-
420
- Inline, subexpression, or block helper that returns true (or the block) if the given collection is empty, or false (or the inverse block, if supplied) if the colleciton is not empty.
421
-
422
- **Params**
423
-
424
- * `collection` **{Object}**
425
- * `options` **{Object}**
426
- * `returns` **{String}**
427
-
428
- **Example**
429
-
430
- ```html
431
- <!-- array: [] -->
432
- {{#isEmpty array}}AAA{{else}}BBB{{/isEmpty}}
433
- <!-- results in: 'AAA' -->
434
-
435
- <!-- array: [] -->
436
- {{isEmpty array}}
437
- <!-- results in: true -->
438
- ```
439
-
440
- ### [{{iterate}}](lib/collection.js#L59)
441
-
442
- Block helper that iterates over an array or object. If
443
- an array is given, `.forEach` is called, or if an object
444
- is given, `.forOwn` is called, otherwise the inverse block
445
- is returned.
446
-
447
- **Params**
448
-
449
- * `collection` **{Object|Array}**: The collection to iterate over
450
- * `options` **{Object}**
451
- * `returns` **{String}**
452
-
453
- ## comparison
454
-
455
- ### [{{and}}](lib/comparison.js#L27)
456
-
457
- Helper that renders the block if **both** of the given values are truthy. If an inverse block is specified it will be rendered when falsy. Works as a block helper, inline helper or subexpression.
458
-
459
- **Params**
460
-
461
- * `a` **{any}**
462
- * `b` **{any}**
463
- * `options` **{Object}**: Handlebars provided options object
464
- * `returns` **{String}**
465
-
466
- **Example**
467
-
468
- ```html
469
- <!-- {great: true, magnificent: true} -->
470
- {{#and great magnificent}}A{{else}}B{{/and}}
471
- <!-- results in: 'A' -->
472
- ```
473
-
474
- ### [{{compare}}](lib/comparison.js#L57)
475
-
476
- Render a block when a comparison of the first and third
477
- arguments returns true. The second argument is
478
- the [arithemetic operator](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Arithmetic_Operators) to use. You may also
479
- optionally specify an inverse block to render when falsy.
480
-
481
- **Params**
482
-
483
- * `a` **{}**
484
- * `operator` **{}**: The operator to use. Operators must be enclosed in quotes: `">"`, `"="`, `"<="`, and so on.
485
- * `b` **{}**
486
- * `options` **{Object}**: Handlebars provided options object
487
- * `returns` **{String}**: Block, or if specified the inverse block is rendered if falsey.
488
-
489
- ### [{{contains}}](lib/comparison.js#L124)
490
-
491
- Block helper that renders the block if `collection` has the given `value`, using strict equality (`===`) for comparison, otherwise the inverse block is rendered (if specified). If a `startIndex` is specified and is negative, it is used as the offset from the end of the collection.
492
-
493
- **Params**
494
-
495
- * `collection` **{Array|Object|String}**: The collection to iterate over.
496
- * `value` **{any}**: The value to check for.
497
- * `[startIndex=0]` **{Number}**: Optionally define the starting index.
498
- * `options` **{Object}**: Handlebars provided options object.
499
-
500
- **Example**
501
-
502
- ```html
503
- <!-- array = ['a', 'b', 'c'] -->
504
- {{#contains array "d"}}
505
- This will not be rendered.
506
- {{else}}
507
- This will be rendered.
508
- {{/contains}}
509
- ```
510
-
511
- ### [`{{default}}`](lib/comparison.js#L143)
512
-
513
- Returns the first value that is not undefined, otherwise the `default` value is returned.
514
-
515
- **Params**
516
-
517
- * `value` **{any}**
518
- * `defaultValue` **{any}**
519
- * `returns` **{String}**
520
-
521
- ### [{{eq}}](lib/comparison.js#L165)
522
-
523
- Block helper that renders a block if `a` is **equal to** `b`.
524
- If an inverse block is specified it will be rendered when falsy.
525
- You may optionally use the `compare=""` hash argument for the
526
- second value.
527
-
528
- **Params**
529
-
530
- * `a` **{String}**
531
- * `b` **{String}**
532
- * `options` **{Object}**: Handlebars provided options object
533
- * `returns` **{String}**: Block, or inverse block if specified and falsey.
534
-
535
- ### [{{gt}}](lib/comparison.js#L188)
536
-
537
- Block helper that renders a block if `a` is **greater than** `b`.
538
-
539
- If an inverse block is specified it will be rendered when falsy.
540
- You may optionally use the `compare=""` hash argument for the
541
- second value.
542
-
543
- **Params**
544
-
545
- * `a` **{String}**
546
- * `b` **{String}**
547
- * `options` **{Object}**: Handlebars provided options object
548
- * `returns` **{String}**: Block, or inverse block if specified and falsey.
549
-
550
- ### [{{gte}}](lib/comparison.js#L212)
551
-
552
- Block helper that renders a block if `a` is **greater than or equal to** `b`.
553
-
554
- If an inverse block is specified it will be rendered when falsy.
555
- You may optionally use the `compare=""` hash argument for the
556
- second value.
557
-
558
- **Params**
559
-
560
- * `a` **{String}**
561
- * `b` **{String}**
562
- * `options` **{Object}**: Handlebars provided options object
563
- * `returns` **{String}**: Block, or inverse block if specified and falsey.
564
-
565
- ### [{{has}}](lib/comparison.js#L232)
566
-
567
- Block helper that renders a block if `value` has `pattern`.
568
- If an inverse block is specified it will be rendered when falsy.
569
-
570
- **Params**
571
-
572
- * `val` **{any}**: The value to check.
573
- * `pattern` **{any}**: The pattern to check for.
574
- * `options` **{Object}**: Handlebars provided options object
575
- * `returns` **{String}**
576
-
577
- ### [{{isFalsey}}](lib/comparison.js#L274)
578
-
579
- Returns true if the given `value` is falsey. Uses the [falsey](https://github.com/jonschlinkert/falsey)
580
- library for comparisons. Please see that library for more information
581
- or to report bugs with this helper.
582
-
583
- **Params**
584
-
585
- * `val` **{any}**
586
- * `options` **{Options}**
587
- * `returns` **{Boolean}**
588
-
589
- ### [{{isTruthy}}](lib/comparison.js#L289)
590
-
591
- Returns true if the given `value` is truthy. Uses the [falsey](https://github.com/jonschlinkert/falsey)
592
- library for comparisons. Please see that library for more information
593
- or to report bugs with this helper.
594
-
595
- **Params**
596
-
597
- * `val` **{any}**
598
- * `options` **{Options}**
599
- * `returns` **{Boolean}**
600
-
601
- ### [{{ifEven}}](lib/comparison.js#L310)
602
-
603
- Return true if the given value is an even number.
604
-
605
- **Params**
606
-
607
- * `number` **{Number}**
608
- * `options` **{Object}**: Handlebars provided options object
609
- * `returns` **{String}**: Block, or inverse block if specified and falsey.
610
-
611
- **Example**
612
-
613
- ```html
614
- {{#ifEven value}}
615
- render A
616
- {{else}}
617
- render B
618
- {{/ifEven}}
619
- ```
620
-
621
- ### [{{ifNth}}](lib/comparison.js#L327)
622
-
623
- Conditionally renders a block if the remainder is zero when
624
- `a` operand is divided by `b`. If an inverse block is specified
625
- it will be rendered when the remainder is **not zero**.
626
-
627
- **Params**
628
-
629
- * **{}**: {Number}
630
- * **{}**: {Number}
631
- * `options` **{Object}**: Handlebars provided options object
632
- * `returns` **{String}**: Block, or inverse block if specified and falsey.
633
-
634
- ### [{{ifOdd}}](lib/comparison.js#L350)
635
-
636
- Block helper that renders a block if `value` is **an odd number**. If an inverse block is specified it will be rendered when falsy.
637
-
638
- **Params**
639
-
640
- * `value` **{Object}**
641
- * `options` **{Object}**: Handlebars provided options object
642
- * `returns` **{String}**: Block, or inverse block if specified and falsey.
643
-
644
- **Example**
645
-
646
- ```html
647
- {{#ifOdd value}}
648
- render A
649
- {{else}}
650
- render B
651
- {{/ifOdd}}
652
- ```
653
-
654
- ### [`{{is}}`](lib/comparison.js#L367)
655
-
656
- Block helper that renders a block if `a` is **equal to** `b`.
657
- If an inverse block is specified it will be rendered when falsy.
658
- Similar to [eq](#eq) but does not do strict equality.
659
-
660
- **Params**
661
-
662
- * `a` **{any}**
663
- * `b` **{any}**
664
- * `options` **{Object}**: Handlebars provided options object
665
- * `returns` **{String}**
666
-
667
- ### [`{{isnt}}`](lib/comparison.js#L389)
668
-
669
- Block helper that renders a block if `a` is **not equal to** `b`.
670
- If an inverse block is specified it will be rendered when falsy.
671
- Similar to [unlessEq](#unlesseq) but does not use strict equality for
672
- comparisons.
673
-
674
- **Params**
675
-
676
- * `a` **{String}**
677
- * `b` **{String}**
678
- * `options` **{Object}**: Handlebars provided options object
679
- * `returns` **{String}**
680
-
681
- ### [`{{lt}}`](lib/comparison.js#L411)
682
-
683
- Block helper that renders a block if `a` is **less than** `b`.
684
-
685
- If an inverse block is specified it will be rendered when falsy.
686
- You may optionally use the `compare=""` hash argument for the
687
- second value.
688
-
689
- **Params**
690
-
691
- * `context` **{Object}**
692
- * `options` **{Object}**: Handlebars provided options object
693
- * `returns` **{String}**: Block, or inverse block if specified and falsey.
694
-
695
- ### [`{{lte}}`](lib/comparison.js#L435)
696
-
697
- Block helper that renders a block if `a` is **less than or equal to** `b`.
698
-
699
- If an inverse block is specified it will be rendered when falsy.
700
- You may optionally use the `compare=""` hash argument for the
701
- second value.
702
-
703
- **Params**
704
-
705
- * `a` **{Sring}**
706
- * `b` **{Sring}**
707
- * `options` **{Object}**: Handlebars provided options object
708
- * `returns` **{String}**: Block, or inverse block if specified and falsey.
709
-
710
- ### [`{{neither}}`](lib/comparison.js#L456)
711
-
712
- Block helper that renders a block if **neither of** the given values
713
- are truthy. If an inverse block is specified it will be rendered
714
- when falsy.
715
-
716
- **Params**
717
-
718
- * `a` **{any}**
719
- * `b` **{any}**
720
- * `options` **{}**: Handlebars options object
721
- * `returns` **{String}**: Block, or inverse block if specified and falsey.
722
-
723
- ### [`{{not}}`](lib/comparison.js#L470)
724
-
725
- Returns true if `val` is falsey. Works as a block or inline helper.
726
-
727
- **Params**
728
-
729
- * `val` **{String}**
730
- * `options` **{Object}**: Handlebars provided options object
731
- * `returns` **{String}**
732
-
733
- ### [`{{or}}`](lib/comparison.js#L492)
734
-
735
- Block helper that renders a block if **any of** the given values is truthy. If an inverse block is specified it will be rendered when falsy.
736
-
737
- **Params**
738
-
739
- * `args` **{any}**: Variable number of arguments
740
- * `options` **{Object}**: Handlebars options object
741
- * `returns` **{String}**: Block, or inverse block if specified and falsey.
742
-
743
- **Example**
744
-
745
- ```html
746
- {{#or a b c}}
747
- If any value is true this will be rendered.
748
- {{/or}}
749
- ```
750
-
751
- ### [{{unlessEq}}](lib/comparison.js#L518)
752
-
753
- Block helper that always renders the inverse block **unless `a` is
754
- is equal to `b`**.
755
-
756
- **Params**
757
-
758
- * `a` **{String}**
759
- * `b` **{String}**
760
- * `options` **{Object}**: Handlebars provided options object
761
- * `returns` **{String}**: Inverse block by default, or block if falsey.
762
-
763
- ### [{{unlessGt}}](lib/comparison.js#L538)
764
-
765
- Block helper that always renders the inverse block **unless `a` is
766
- is greater than `b`**.
767
-
768
- **Params**
769
-
770
- * `a` **{Object}**: The default value
771
- * `b` **{Object}**: The value to compare
772
- * `options` **{Object}**: Handlebars provided options object
773
- * `returns` **{String}**: Inverse block by default, or block if falsey.
774
-
775
- ### [{{unlessLt}}](lib/comparison.js#L558)
776
-
777
- Block helper that always renders the inverse block **unless `a` is
778
- is less than `b`**.
779
-
780
- **Params**
781
-
782
- * `a` **{Object}**: The default value
783
- * `b` **{Object}**: The value to compare
784
- * `options` **{Object}**: Handlebars provided options object
785
- * `returns` **{String}**: Block, or inverse block if specified and falsey.
786
-
787
- ### [{{unlessGteq}}](lib/comparison.js#L578)
788
-
789
- Block helper that always renders the inverse block **unless `a` is
790
- is greater than or equal to `b`**.
791
-
792
- **Params**
793
-
794
- * `a` **{any}**
795
- * `b` **{any}**
796
- * `options` **{Object}**: Handlebars provided options object
797
- * `returns` **{String}**: Block, or inverse block if specified and falsey.
798
-
799
- ### [{{unlessLteq}}](lib/comparison.js#L598)
800
-
801
- Block helper that always renders the inverse block **unless `a` is
802
- is less than or equal to `b`**.
803
-
804
- **Params**
805
-
806
- * `a` **{any}**
807
- * `b` **{any}**
808
- * `options` **{Object}**: Handlebars provided options object
809
- * `returns` **{String}**: Block, or inverse block if specified and falsey.
810
-
811
- ## date
812
-
813
- ### [{{year}}](lib/date.js#L15)
814
-
815
- Get the current year.
816
-
817
- **Example**
818
-
819
- ```html
820
- {{year}}
821
- <!-- 2017 -->
822
- ```
823
-
824
- ### [{{moment}}](lib/date.js#L24)
825
-
826
- Use [moment](http://momentjs.com) as a helper. See [helper-date](https://github.com/helpers/helper-date) for more details.
827
-
828
- ## fs
829
-
830
- ### [{{read}}](lib/fs.js#L29)
831
-
832
- Read a file from the file system. This is useful in composing "include"-style helpers using sub-expressions.
833
-
834
- **Params**
835
-
836
- * `filepath` **{String}**
837
- * `returns` **{String}**
838
-
839
- **Example**
840
-
841
- ```html
842
- {{read "a/b/c.js"}}
843
- {{someHelper (read "a/b/c.md")}}
844
- ```
845
-
846
- ### [{{readdir}}](lib/fs.js#L42)
847
-
848
- Return an array of files from the given
849
- directory.
850
-
851
- **Params**
852
-
853
- * `directory` **{String}**
854
- * `returns` **{Array}**
855
-
856
- ## html
857
-
858
- ### [{{attr}}](lib/html.js#L23)
859
-
860
- Stringify attributes on the options `hash`.
861
-
862
- **Params**
863
-
864
- * `options` **{Object}**
865
- * `returns` **{String}**
866
-
867
- **Example**
868
-
869
- ```html
870
- <!-- value = 'bar' -->
871
- <div{{attr foo=value}}></div>
872
- <!-- results in: <div foo="bar"></div>
873
- ```
874
-
875
- ### [{{css}}](lib/html.js#L45)
876
-
877
- Add an array of `<link>` tags. Automatically resolves relative paths to `options.assets` if passed on the context.
878
-
879
- **Params**
880
-
881
- * `list` **{String|Array}**: One or more stylesheet urls.
882
- * `returns` **{String}**
883
-
884
- **Example**
885
-
886
- ```html
887
- <!-- {stylesheets: ['foo.css', 'bar.css']} -->
888
- {{css stylesheets}}
889
-
890
- <!-- results in: -->
891
- <!-- <link type="text/css" rel="stylesheet" href="foo.css"> -->
892
- <!-- <link type="text/css" rel="stylesheet" href="bar.css"> -->
893
- ```
894
-
895
- ### [{{js}}](lib/html.js#L89)
896
-
897
- Generate one or more `<script></script>` tags with paths/urls to javascript or coffeescript files.
898
-
899
- **Params**
900
-
901
- * `context` **{Object}**
902
- * `returns` **{String}**
903
-
904
- **Example**
905
-
906
- ```html
907
- {{js scripts}}
908
- ```
909
-
910
- ### [{{sanitize}}](lib/html.js#L121)
911
-
912
- Strip HTML tags from a string, so that only the text nodes are preserved.
913
-
914
- **Params**
915
-
916
- * `str` **{String}**: The string of HTML to sanitize.
917
- * `returns` **{String}**
918
-
919
- **Example**
920
-
921
- ```html
922
- {{sanitize "<span>foo</span>"}}
923
- <!-- results in: 'foo' -->
924
- ```
925
-
926
- ### [{{ul}}](lib/html.js#L135)
927
-
928
- Block helper for creating unordered lists (`<ul></ul>`)
929
-
930
- **Params**
931
-
932
- * `context` **{Object}**
933
- * `options` **{Object}**
934
- * `returns` **{String}**
935
-
936
- ### [{{ol}}](lib/html.js#L154)
937
-
938
- Block helper for creating ordered lists (`<ol></ol>`)
939
-
940
- **Params**
941
-
942
- * `context` **{Object}**
943
- * `options` **{Object}**
944
- * `returns` **{String}**
945
-
946
- ### [{{thumbnailImage}}](lib/html.js#L176)
947
-
948
- Returns a `<figure>` with a thumbnail linked to a full picture
949
-
950
- **Params**
951
-
952
- * `context` **{Object}**: Object with values/attributes to add to the generated elements:
953
- * `context.alt` **{String}**
954
- * `context.src` **{String}**
955
- * `context.width` **{Number}**
956
- * `context.height` **{Number}**
957
- * `returns` **{String}**: HTML `<figure>` element with image and optional caption/link.
958
-
959
- ## i18n
960
-
961
- ### [{{i18n}}](lib/i18n.js#L18)
962
-
963
- i18n helper. See [button-i18n](https://github.com/assemble/buttons)
964
- for a working example.
965
-
966
- **Params**
967
-
968
- * `key` **{String}**
969
- * `options` **{Object}**
970
- * `returns` **{String}**
971
-
972
- ## inflection
973
-
974
- ### [{{inflect}}](lib/inflection.js#L30)
975
-
976
- Returns either the `singular` or `plural` inflection of a word based on the given `count`.
977
-
978
- **Params**
979
-
980
- * `count` **{Number}**
981
- * `singular` **{String}**: The singular form
982
- * `plural` **{String}**: The plural form
983
- * `includeCount` **{String}**
984
- * `returns` **{String}**
985
-
986
- **Example**
987
-
988
- ```html
989
- {{inflect 0 "string" "strings"}}
990
- <!-- "strings" -->
991
- {{inflect 1 "string" "strings"}}
992
- <!-- "string" -->
993
- {{inflect 1 "string" "strings" true}}
994
- <!-- "1 string" -->
995
- {{inflect 2 "string" "strings"}}
996
- <!-- "strings" -->
997
- {{inflect 2 "string" "strings" true}}
998
- <!-- "2 strings" -->
999
- ```
1000
-
1001
- ### [{{ordinalize}}](lib/inflection.js#L58)
1002
-
1003
- Returns an ordinalized number as a string.
1004
-
1005
- **Params**
1006
-
1007
- * `val` **{String}**: The value to ordinalize.
1008
- * `returns` **{String}**: The ordinalized number
1009
-
1010
- **Example**
1011
-
1012
- ```html
1013
- {{ordinalize 1}}
1014
- <!-- '1st' -->
1015
- {{ordinalize 21}}
1016
- <!-- '21st' -->
1017
- {{ordinalize 29}}
1018
- <!-- '29th' -->
1019
- {{ordinalize 22}}
1020
- <!-- '22nd' -->
1021
- ```
1022
-
1023
- ## logging
1024
-
1025
- [logging-helpers](https://github.com/jonathas/logging-helpers).
1026
-
1027
- ## markdown
1028
-
1029
- ### [{{markdown}}](lib/markdown.js#L28)
1030
-
1031
- Block helper that converts a string of inline markdown to HTML.
1032
-
1033
- **Params**
1034
-
1035
- * `context` **{Object}**
1036
- * `options` **{Object}**
1037
- * `returns` **{String}**
1038
-
1039
- **Example**
1040
-
1041
- ```html
1042
- {{#markdown}}
1043
- # Foo
1044
- {{/markdown}}
1045
- <!-- results in: <h1>Foo</h1> -->
1046
- ```
1047
-
1048
- ### [{{md}}](lib/markdown.js#L55)
1049
-
1050
- Read a markdown file from the file system and inject its contents after converting it to HTML.
1051
-
1052
- **Params**
1053
-
1054
- * `context` **{Object}**
1055
- * `options` **{Object}**
1056
- * `returns` **{String}**
1057
-
1058
- **Example**
1059
-
1060
- ```html
1061
- {{md "foo/bar.md"}}
1062
- ```
1063
-
1064
- ## match
1065
-
1066
- ### [{{match}}](lib/match.js#L23)
1067
-
1068
- Returns an array of strings that match the given glob pattern(s). Options may be passed on the options hash or locals.
1069
-
1070
- **Params**
1071
-
1072
- * `files` **{Array|String}**
1073
- * `patterns` **{Array|String}**: One or more glob patterns.
1074
- * `locals` **{Object}**
1075
- * `options` **{Object}**
1076
- * `returns` **{Array}**: Array of matches
1077
-
1078
- **Example**
1079
-
1080
- ```html
1081
- {{match (readdir "foo") "*.js"}}
1082
- {{match (readdir "foo") (toRegex "\\.js$")}}
1083
- ```
1084
-
1085
- ### [{{isMatch}}](lib/match.js#L47)
1086
-
1087
- Returns true if a filepath contains the given pattern. Options may be passed on the options hash or locals.
1088
-
1089
- **Params**
1090
-
1091
- * `filepath` **{String}**
1092
- * `pattern` **{String}**
1093
- * `options` **{Object}**
1094
- * `returns` **{Boolean}**
1095
-
1096
- **Example**
1097
-
1098
- ```html
1099
- {{isMatch "foo.md" "*.md"}}
1100
- <!-- results in: true -->
1101
- ```
1102
-
1103
- ## math
1104
-
1105
- ### [{{abs}}](lib/math.js#L15)
1106
-
1107
- Return the magnitude of `a`.
1108
-
1109
- **Params**
1110
-
1111
- * `a` **{Number}**
1112
- * `returns` **{Number}**
1113
-
1114
- ### [{{add}}](lib/math.js#L31)
1115
-
1116
- Return the sum of `a` plus `b`.
1117
-
1118
- **Params**
1119
-
1120
- * `a` **{Number}**
1121
- * `b` **{Number}**
1122
- * `returns` **{Number}**
1123
-
1124
- ### [{{avg}}](lib/math.js#L54)
1125
-
1126
- Returns the average of all numbers in the given array.
1127
-
1128
- **Params**
1129
-
1130
- * `array` **{Array}**: Array of numbers to add up.
1131
- * `returns` **{Number}**
1132
-
1133
- **Example**
1134
-
1135
- ```html
1136
- {{avg "[1, 2, 3, 4, 5]"}}
1137
- <!-- results in: '3' -->
1138
- ```
1139
-
1140
- ### [{{ceil}}](lib/math.js#L69)
1141
-
1142
- Get the `Math.ceil()` of the given value.
1143
-
1144
- **Params**
1145
-
1146
- * `value` **{Number}**
1147
- * `returns` **{Number}**
1148
-
1149
- ### [{{divide}}](lib/math.js#L84)
1150
-
1151
- Divide `a` by `b`
1152
-
1153
- **Params**
1154
-
1155
- * `a` **{Number}**: numerator
1156
- * `b` **{Number}**: denominator
1157
-
1158
- ### [{{floor}}](lib/math.js#L102)
1159
-
1160
- Get the `Math.floor()` of the given value.
1161
-
1162
- **Params**
1163
-
1164
- * `value` **{Number}**
1165
- * `returns` **{Number}**
1166
-
1167
- ### [{{minus}}](lib/math.js#L118)
1168
-
1169
- Return the difference of `a` minus `b`.
1170
-
1171
- **Params**
1172
-
1173
- * `a` **{Number}**
1174
- * `b` **{Number}**
1175
-
1176
- ### [{{modulo}}](lib/math.js#L137)
1177
-
1178
- Get the remainder of a division operation.
1179
-
1180
- **Params**
1181
-
1182
- * `a` **{Number}**
1183
- * `b` **{Number}**
1184
- * `returns` **{Number}**
1185
-
1186
- ### [{{multiply}}](lib/math.js#L157)
1187
-
1188
- Return the product of `a` times `b`.
1189
-
1190
- **Params**
1191
-
1192
- * `a` **{Number}**: factor
1193
- * `b` **{Number}**: multiplier
1194
- * `returns` **{Number}**
1195
-
1196
- ### [{{plus}}](lib/math.js#L175)
1197
-
1198
- Add `a` by `b`.
1199
-
1200
- **Params**
1201
-
1202
- * `a` **{Number}**: factor
1203
- * `b` **{Number}**: multiplier
1204
-
1205
- ### [{{random}}](lib/math.js#L194)
1206
-
1207
- Generate a random number between two values
1208
-
1209
- **Params**
1210
-
1211
- * `min` **{Number}**
1212
- * `max` **{Number}**
1213
- * `returns` **{String}**
1214
-
1215
- ### [{{remainder}}](lib/math.js#L212)
1216
-
1217
- Get the remainder when `a` is divided by `b`.
1218
-
1219
- **Params**
1220
-
1221
- * `a` **{Number}**: a
1222
- * `b` **{Number}**: b
1223
-
1224
- ### [{{round}}](lib/math.js#L224)
1225
-
1226
- Round the given number.
1227
-
1228
- **Params**
1229
-
1230
- * `number` **{Number}**
1231
- * `returns` **{Number}**
1232
-
1233
- ### [{{subtract}}](lib/math.js#L241)
1234
-
1235
- Return the product of `a` minus `b`.
1236
-
1237
- **Params**
1238
-
1239
- * `a` **{Number}**
1240
- * `b` **{Number}**
1241
- * `returns` **{Number}**
1242
-
1243
- ### [{{sum}}](lib/math.js#L263)
1244
-
1245
- Returns the sum of all numbers in the given array.
1246
-
1247
- **Params**
1248
-
1249
- * `array` **{Array}**: Array of numbers to add up.
1250
- * `returns` **{Number}**
1251
-
1252
- **Example**
1253
-
1254
- ```html
1255
- {{sum "[1, 2, 3, 4, 5]"}}
1256
- <!-- results in: '15' -->
1257
- ```
1258
-
1259
- ### [{{times}}](lib/math.js#L286)
1260
-
1261
- Multiply number `a` by number `b`.
1262
-
1263
- **Params**
1264
-
1265
- * `a` **{Number}**: factor
1266
- * `b` **{Number}**: multiplier
1267
- * `returns` **{Number}**
1268
-
1269
- ## misc
1270
-
1271
- ### [{{option}}](lib/misc.js#L26)
1272
-
1273
- Return the given value of `prop` from `this.options`.
1274
-
1275
- **Params**
1276
-
1277
- * `prop` **{String}**
1278
- * `returns` **{any}**
1279
-
1280
- **Example**
1281
-
1282
- ```html
1283
- <!-- context = {options: {a: {b: {c: 'ddd'}}}} -->
1284
- {{option "a.b.c"}}
1285
- <!-- results => `ddd` -->
1286
- ```
1287
-
1288
- ### [{{noop}}](lib/misc.js#L39)
1289
-
1290
- Block helper that renders the block without taking any arguments.
1291
-
1292
- **Params**
1293
-
1294
- * `options` **{Object}**
1295
- * `returns` **{String}**
1296
-
1297
- ### [{{typeOf}}](lib/misc.js#L59)
1298
-
1299
- Get the native type of the given `value`
1300
-
1301
- **Params**
1302
-
1303
- * `value` **{any}**
1304
- * `returns` **{String}**: Returns the type of value.
1305
-
1306
- **Example**
1307
-
1308
- ```html
1309
- {{typeOf 1}}
1310
- //=> 'number'
1311
- {{typeOf "1"}}
1312
- //=> 'string'
1313
- {{typeOf "foo"}}
1314
- //=> 'string'
1315
- ```
1316
-
1317
- ### [{{withHash}}](lib/misc.js#L71)
1318
-
1319
- Block helper that builds the context for the block
1320
- from the options hash.
1321
-
1322
- **Params**
1323
-
1324
- * `options` **{Object}**: Handlebars provided options object.
1325
-
1326
- ## number
1327
-
1328
- ### [{{bytes}}](lib/number.js#L24)
1329
-
1330
- Format a number to it's equivalent in bytes. If a string is passed, it's length will be formatted and returned.
1331
-
1332
- **Examples:**
1333
-
1334
- * `'foo' => 3 B`
1335
- * `13661855 => 13.66 MB`
1336
- * `825399 => 825.39 kB`
1337
- * `1396 => 1.4 kB`
1338
-
1339
- **Params**
1340
-
1341
- * `number` **{Number|String}**
1342
- * `returns` **{String}**
1343
-
1344
- ### [{{addCommas}}](lib/number.js#L61)
1345
-
1346
- Add commas to numbers
1347
-
1348
- **Params**
1349
-
1350
- * `num` **{Number}**
1351
- * `returns` **{Number}**
1352
-
1353
- ### [{{phoneNumber}}](lib/number.js#L74)
1354
-
1355
- Convert a string or number to a formatted phone number.
1356
-
1357
- **Params**
1358
-
1359
- * `num` **{Number|String}**: The phone number to format, e.g. `8005551212`
1360
- * `returns` **{Number}**: Formatted phone number: `(800) 555-1212`
1361
-
1362
- ### [{{toAbbr}}](lib/number.js#L92)
1363
-
1364
- Abbreviate numbers to the given number of `precision`. This is for
1365
- general numbers, not size in bytes.
1366
-
1367
- **Params**
1368
-
1369
- * `number` **{Number}**
1370
- * `precision` **{Number}**
1371
- * `returns` **{String}**
1372
-
1373
- ### [{{toExponential}}](lib/number.js#L130)
1374
-
1375
- Returns a string representing the given number in exponential notation.
1376
-
1377
- **Params**
1378
-
1379
- * `number` **{Number}**
1380
- * `fractionDigits` **{Number}**: Optional. An integer specifying the number of digits to use after the decimal point. Defaults to as many digits as necessary to specify the number.
1381
- * `returns` **{Number}**
1382
-
1383
- **Example**
1384
-
1385
- ```html
1386
- {{toExponential number digits}};
1387
- ```
1388
-
1389
- ### [{{toFixed}}](lib/number.js#L153)
1390
-
1391
- Formats the given number using fixed-point notation.
1392
-
1393
- **Params**
1394
-
1395
- * `number` **{Number}**
1396
- * `digits` **{Number}**: (Optional) The number of digits to appear after the decimal point; this may be a value between 0 and 20. If this argument is omitted, it is treated as 0.
1397
- * `returns` **{String}**: A string representing the given number using fixed-point notation.
1398
-
1399
- **Example**
1400
-
1401
- ```html
1402
- {{toFixed "1.1234" 2}}
1403
- //=> '1.12'
1404
- ```
1405
-
1406
- ### [{{toFloat}}](lib/number.js#L169)
1407
-
1408
- **Params**
1409
-
1410
- * `number` **{Number}**
1411
- * `returns` **{Number}**
1412
-
1413
- ### [{{toInt}}](lib/number.js#L179)
1414
-
1415
- **Params**
1416
-
1417
- * `number` **{Number}**
1418
- * `returns` **{Number}**
1419
-
1420
- ### [{{toPrecision}}](lib/number.js#L196)
1421
-
1422
- Returns a string representing the `Number` object to the specified precision.
1423
-
1424
- **Params**
1425
-
1426
- * `number` **{Number}**
1427
- * `precision` **{Number}**: (Optional) An integer specifying the number of significant digits. If precison is not between 1 and 100 (inclusive), it will be coerced to `0`.
1428
- * `returns` **{String}**: A string representing a Number object in fixed-point or exponential notation rounded to precision significant digits.
1429
-
1430
- **Example**
1431
-
1432
- ```html
1433
- {{toPrecision "1.1234" 2}}
1434
- //=> '1.1'
1435
- ```
1436
-
1437
- ## object
1438
-
1439
- ### [{{extend}}](lib/object.js#L18)
1440
-
1441
- Extend the context with the properties of other objects.
1442
- A shallow merge is performed to avoid mutating the context.
1443
-
1444
- **Params**
1445
-
1446
- * `objects` **{Object}**: One or more objects to extend.
1447
- * `returns` **{Object}**
1448
-
1449
- ### [{{forIn}}](lib/object.js#L55)
1450
-
1451
- Block helper that iterates over the properties of
1452
- an object, exposing each key and value on the context.
1453
-
1454
- **Params**
1455
-
1456
- * `context` **{Object}**
1457
- * `options` **{Object}**
1458
- * `returns` **{String}**
1459
-
1460
- ### [{{forOwn}}](lib/object.js#L81)
1461
-
1462
- Block helper that iterates over the **own** properties of
1463
- an object, exposing each key and value on the context.
1464
-
1465
- **Params**
1466
-
1467
- * `obj` **{Object}**: The object to iterate over.
1468
- * `options` **{Object}**
1469
- * `returns` **{String}**
1470
-
1471
- ### [{{toPath}}](lib/object.js#L106)
1472
-
1473
- Take arguments and, if they are string or number, convert them to a dot-delineated object property path.
1474
-
1475
- **Params**
1476
-
1477
- * `prop` **{String|Number}**: The property segments to assemble (can be multiple).
1478
- * `returns` **{String}**
1479
-
1480
- ### [{{get}}](lib/object.js#L128)
1481
-
1482
- Use property paths (`a.b.c`) to get a value or nested value from
1483
- the context. Works as a regular helper or block helper.
1484
-
1485
- **Params**
1486
-
1487
- * `prop` **{String}**: The property to get, optionally using dot notation for nested properties.
1488
- * `context` **{Object}**: The context object
1489
- * `options` **{Object}**: The handlebars options object, if used as a block helper.
1490
- * `returns` **{String}**
1491
-
1492
- ### [{{getObject}}](lib/object.js#L149)
1493
-
1494
- Use property paths (`a.b.c`) to get an object from
1495
- the context. Differs from the `get` helper in that this
1496
- helper will return the actual object, including the
1497
- given property key. Also, this helper does not work as a
1498
- block helper.
1499
-
1500
- **Params**
1501
-
1502
- * `prop` **{String}**: The property to get, optionally using dot notation for nested properties.
1503
- * `context` **{Object}**: The context object
1504
- * `returns` **{String}**
1505
-
1506
- ### [{{hasOwn}}](lib/object.js#L167)
1507
-
1508
- Return true if `key` is an own, enumerable property of the given `context` object.
1509
-
1510
- **Params**
1511
-
1512
- * `key` **{String}**
1513
- * `context` **{Object}**: The context object.
1514
- * `returns` **{Boolean}**
1515
-
1516
- **Example**
1517
-
1518
- ```html
1519
- {{hasOwn context key}}
1520
- ```
1521
-
1522
- ### [{{isObject}}](lib/object.js#L183)
1523
-
1524
- Return true if `value` is an object.
1525
-
1526
- **Params**
1527
-
1528
- * `value` **{String}**
1529
- * `returns` **{Boolean}**
1530
-
1531
- **Example**
1532
-
1533
- ```html
1534
- {{isObject "foo"}}
1535
- //=> false
1536
- ```
1537
-
1538
- ### [{{JSONparse}}](lib/object.js#L201)
1539
-
1540
- Parses the given string using `JSON.parse`.
1541
-
1542
- **Params**
1543
-
1544
- * `string` **{String}**: The string to parse
1545
-
1546
- **Example**
1547
-
1548
- ```html
1549
- <!-- string: '{"foo": "bar"}' -->
1550
- {{JSONparse string}}
1551
- <!-- results in: { foo: 'bar' } -->
1552
- ```
1553
-
1554
- ### [{{JSONstringify}}](lib/object.js#L218)
1555
-
1556
- Stringify an object using `JSON.stringify`.
1557
-
1558
- **Params**
1559
-
1560
- * `obj` **{Object}**: Object to stringify
1561
- * `returns` **{String}**
1562
-
1563
- **Example**
1564
-
1565
- ```html
1566
- <!-- object: { foo: 'bar' } -->
1567
- {{JSONstringify object}}
1568
- <!-- results in: '{"foo": "bar"}' -->
1569
- ```
1570
-
1571
- ### [{{merge}}](lib/object.js#L235)
1572
-
1573
- Deeply merge the properties of the given `objects` with the
1574
- context object.
1575
-
1576
- **Params**
1577
-
1578
- * `object` **{Object}**: The target object. Pass an empty object to shallow clone.
1579
- * `objects` **{Object}**
1580
- * `returns` **{Object}**
1581
-
1582
- ### [{{pick}}](lib/object.js#L267)
1583
-
1584
- Pick properties from the context object.
1585
-
1586
- **Params**
1587
-
1588
- * `properties` **{Array|String}**: One or more properties to pick.
1589
- * `context` **{Object}**
1590
- * `options` **{Object}**: Handlebars options object.
1591
- * `returns` **{Object}**: Returns an object with the picked values. If used as a block helper, the values are passed as context to the inner block. If no values are found, the context is passed to the inverse block.
1592
-
1593
- ## path
1594
-
1595
- ### [{{absolute}}](lib/path.js#L20)
1596
-
1597
- Get the directory path segment from the given `filepath`.
1598
-
1599
- **Params**
1600
-
1601
- * `ext` **{String}**
1602
- * `returns` **{String}**
1603
-
1604
- **Example**
1605
-
1606
- ```html
1607
- {{absolute "docs/toc.md"}}
1608
- <!-- results in: 'docs' -->
1609
- ```
1610
-
1611
- ### [{{dirname}}](lib/path.js#L40)
1612
-
1613
- Get the directory path segment from the given `filepath`.
1614
-
1615
- **Params**
1616
-
1617
- * `ext` **{String}**
1618
- * `returns` **{String}**
1619
-
1620
- **Example**
1621
-
1622
- ```html
1623
- {{dirname "docs/toc.md"}}
1624
- <!-- results in: 'docs' -->
1625
- ```
1626
-
1627
- ### [{{relative}}](lib/path.js#L59)
1628
-
1629
- Get the relative filepath from `a` to `b`.
1630
-
1631
- **Params**
1632
-
1633
- * `a` **{String}**
1634
- * `b` **{String}**
1635
- * `returns` **{String}**
1636
-
1637
- **Example**
1638
-
1639
- ```html
1640
- {{relative a b}}
1641
- ```
1642
-
1643
- ### [{{basename}}](lib/path.js#L81)
1644
-
1645
- Get the file extension from the given `filepath`.
1646
-
1647
- **Params**
1648
-
1649
- * `ext` **{String}**
1650
- * `returns` **{String}**
1651
-
1652
- **Example**
1653
-
1654
- ```html
1655
- {{basename "docs/toc.md"}}
1656
- <!-- results in: 'toc.md' -->
1657
- ```
1658
-
1659
- ### [{{stem}}](lib/path.js#L100)
1660
-
1661
- Get the "stem" from the given `filepath`.
1662
-
1663
- **Params**
1664
-
1665
- * `filepath` **{String}**
1666
- * `returns` **{String}**
1667
-
1668
- **Example**
1669
-
1670
- ```html
1671
- {{stem "docs/toc.md"}}
1672
- <!-- results in: 'toc' -->
1673
- ```
1674
-
1675
- ### [{{extname}}](lib/path.js#L119)
1676
-
1677
- Get the file extension from the given `filepath`.
1678
-
1679
- **Params**
1680
-
1681
- * `filepath` **{String}**
1682
- * `returns` **{String}**
1683
-
1684
- **Example**
1685
-
1686
- ```html
1687
- {{extname "docs/toc.md"}}
1688
- <!-- results in: '.md' -->
1689
- ```
1690
-
1691
- ### [{{resolve}}](lib/path.js#L138)
1692
-
1693
- Resolve an absolute path from the given `filepath`.
1694
-
1695
- **Params**
1696
-
1697
- * `filepath` **{String}**
1698
- * `returns` **{String}**
1699
-
1700
- **Example**
1701
-
1702
- ```html
1703
- {{resolve "docs/toc.md"}}
1704
- <!-- results in: '/User/dev/docs/toc.md' -->
1705
- ```
1706
-
1707
- ### [{{segments}}](lib/path.js#L166)
1708
-
1709
- Get specific (joined) segments of a file path by passing a range of array indices.
1710
-
1711
- **Params**
1712
-
1713
- * `filepath` **{String}**: The file path to split into segments.
1714
- * `returns` **{String}**: Returns a single, joined file path.
1715
-
1716
- **Example**
1717
-
1718
- ```html
1719
- {{segments "a/b/c/d" "2" "3"}}
1720
- <!-- results in: 'c/d' -->
1721
-
1722
- {{segments "a/b/c/d" "1" "3"}}
1723
- <!-- results in: 'b/c/d' -->
1724
-
1725
- {{segments "a/b/c/d" "1" "2"}}
1726
- <!-- results in: 'b/c' -->
1727
- ```
1728
-
1729
- ## regex
1730
-
1731
- ### [{{toRegex}}](lib/regex.js#L19)
1732
-
1733
- Convert the given string to a regular expression.
1734
-
1735
- **Params**
1736
-
1737
- * `str` **{String}**
1738
- * `returns` **{RegExp}**
1739
-
1740
- **Example**
1741
-
1742
- ```html
1743
- {{toRegex "foo"}}
1744
- <!-- results in: /foo/ -->
1745
- ```
1746
-
1747
- ### [{{test}}](lib/regex.js#L42)
1748
-
1749
- Returns true if the given `str` matches the given regex. A regex can be passed on the context, or using the [toRegex](#toregex) helper as a subexpression.
1750
-
1751
- **Params**
1752
-
1753
- * `str` **{String}**
1754
- * `returns` **{RegExp}**
1755
-
1756
- **Example**
1757
-
1758
- ```html
1759
- {{test "bar" (toRegex "foo")}}
1760
- <!-- results in: false -->
1761
- {{test "foobar" (toRegex "foo")}}
1762
- <!-- results in: true -->
1763
- {{test "foobar" (toRegex "^foo$")}}
1764
- <!-- results in: false -->
1765
- ```
1766
-
1767
- ## string
1768
-
1769
- ### [{{append}}](lib/string.js#L22)
1770
-
1771
- Append the specified `suffix` to the given string.
1772
-
1773
- **Params**
1774
-
1775
- * `str` **{String}**
1776
- * `suffix` **{String}**
1777
- * `returns` **{String}**
1778
-
1779
- **Example**
1780
-
1781
- ```html
1782
- <!-- given that "item.stem" is "foo" -->
1783
- {{append item.stem ".html"}}
1784
- <!-- results in: 'foo.html' -->
1785
- ```
1786
-
1787
- ### [{{camelcase}}](lib/string.js#L41)
1788
-
1789
- camelCase the characters in the given `string`.
1790
-
1791
- **Params**
1792
-
1793
- * `string` **{String}**: The string to camelcase.
1794
- * `returns` **{String}**
1795
-
1796
- **Example**
1797
-
1798
- ```html
1799
- {{camelcase "foo bar baz"}};
1800
- <!-- results in: 'fooBarBaz' -->
1801
- ```
1802
-
1803
- ### [{{capitalize}}](lib/string.js#L60)
1804
-
1805
- Capitalize the first word in a sentence.
1806
-
1807
- **Params**
1808
-
1809
- * `str` **{String}**
1810
- * `returns` **{String}**
1811
-
1812
- **Example**
1813
-
1814
- ```html
1815
- {{capitalize "foo bar baz"}}
1816
- <!-- results in: "Foo bar baz" -->
1817
- ```
1818
-
1819
- ### [{{capitalizeAll}}](lib/string.js#L77)
1820
-
1821
- Capitalize all words in a string.
1822
-
1823
- **Params**
1824
-
1825
- * `str` **{String}**
1826
- * `returns` **{String}**
1827
-
1828
- **Example**
1829
-
1830
- ```html
1831
- {{capitalizeAll "foo bar baz"}}
1832
- <!-- results in: "Foo Bar Baz" -->
1833
- ```
1834
-
1835
- ### [{{center}}](lib/string.js#L95)
1836
-
1837
- Center a string using non-breaking spaces
1838
-
1839
- **Params**
1840
-
1841
- * `str` **{String}**
1842
- * `spaces` **{String}**
1843
- * `returns` **{String}**
1844
-
1845
- ### [{{chop}}](lib/string.js#L125)
1846
-
1847
- Like trim, but removes both extraneous whitespace **and non-word characters** from the beginning and end of a string.
1848
-
1849
- **Params**
1850
-
1851
- * `string` **{String}**: The string to chop.
1852
- * `returns` **{String}**
1853
-
1854
- **Example**
1855
-
1856
- ```html
1857
- {{chop "_ABC_"}}
1858
- <!-- results in: 'ABC' -->
1859
-
1860
- {{chop "-ABC-"}}
1861
- <!-- results in: 'ABC' -->
1862
-
1863
- {{chop " ABC "}}
1864
- <!-- results in: 'ABC' -->
1865
- ```
1866
-
1867
- ### [{{dashcase}}](lib/string.js#L143)
1868
-
1869
- dash-case the characters in `string`. Replaces non-word characters and periods with hyphens.
1870
-
1871
- **Params**
1872
-
1873
- * `string` **{String}**
1874
- * `returns` **{String}**
1875
-
1876
- **Example**
1877
-
1878
- ```html
1879
- {{dashcase "a-b-c d_e"}}
1880
- <!-- results in: 'a-b-c-d-e' -->
1881
- ```
1882
-
1883
- ### [{{dotcase}}](lib/string.js#L162)
1884
-
1885
- dot.case the characters in `string`.
1886
-
1887
- **Params**
1888
-
1889
- * `string` **{String}**
1890
- * `returns` **{String}**
1891
-
1892
- **Example**
1893
-
1894
- ```html
1895
- {{dotcase "a-b-c d_e"}}
1896
- <!-- results in: 'a.b.c.d.e' -->
1897
- ```
1898
-
1899
- ### [{{downcase}}](lib/string.js#L182)
1900
-
1901
- Lowercase all of the characters in the given string. Alias for [lowercase](#lowercase).
1902
-
1903
- **Params**
1904
-
1905
- * `string` **{String}**
1906
- * `returns` **{String}**
1907
-
1908
- **Example**
1909
-
1910
- ```html
1911
- {{downcase "aBcDeF"}}
1912
- <!-- results in: 'abcdef' -->
1913
- ```
1914
-
1915
- ### [{{ellipsis}}](lib/string.js#L202)
1916
-
1917
- Truncates a string to the specified `length`, and appends it with an elipsis, `…`.
1918
-
1919
- **Params**
1920
-
1921
- * `str` **{String}**
1922
- * `length` **{Number}**: The desired length of the returned string.
1923
- * `returns` **{String}**: The truncated string.
1924
-
1925
- **Example**
1926
-
1927
- ```html
1928
- {{ellipsis (sanitize "<span>foo bar baz</span>"), 7}}
1929
- <!-- results in: 'foo bar…' -->
1930
- {{ellipsis "foo bar baz", 7}}
1931
- <!-- results in: 'foo bar…' -->
1932
- ```
1933
-
1934
- ### [{{hyphenate}}](lib/string.js#L223)
1935
-
1936
- Replace spaces in a string with hyphens.
1937
-
1938
- **Params**
1939
-
1940
- * `str` **{String}**
1941
- * `returns` **{String}**
1942
-
1943
- **Example**
1944
-
1945
- ```html
1946
- {{hyphenate "foo bar baz qux"}}
1947
- <!-- results in: "foo-bar-baz-qux" -->
1948
- ```
1949
-
1950
- ### [{{isString}}](lib/string.js#L240)
1951
-
1952
- Return true if `value` is a string.
1953
-
1954
- **Params**
1955
-
1956
- * `value` **{String}**
1957
- * `returns` **{Boolean}**
1958
-
1959
- **Example**
1960
-
1961
- ```html
1962
- {{isString "foo"}}
1963
- <!-- results in: 'true' -->
1964
- ```
1965
-
1966
- ### [{{lowercase}}](lib/string.js#L256)
1967
-
1968
- Lowercase all characters in the given string.
1969
-
1970
- **Params**
1971
-
1972
- * `str` **{String}**
1973
- * `returns` **{String}**
1974
-
1975
- **Example**
1976
-
1977
- ```html
1978
- {{lowercase "Foo BAR baZ"}}
1979
- <!-- results in: 'foo bar baz' -->
1980
- ```
1981
-
1982
- ### [{{occurrences}}](lib/string.js#L278)
1983
-
1984
- Return the number of occurrences of `substring` within the given `string`.
1985
-
1986
- **Params**
1987
-
1988
- * `str` **{String}**
1989
- * `substring` **{String}**
1990
- * `returns` **{Number}**: Number of occurrences
1991
-
1992
- **Example**
1993
-
1994
- ```html
1995
- {{occurrences "foo bar foo bar baz" "foo"}}
1996
- <!-- results in: 2 -->
1997
- ```
1998
-
1999
- ### [{{pascalcase}}](lib/string.js#L303)
2000
-
2001
- PascalCase the characters in `string`.
2002
-
2003
- **Params**
2004
-
2005
- * `string` **{String}**
2006
- * `returns` **{String}**
2007
-
2008
- **Example**
2009
-
2010
- ```html
2011
- {{pascalcase "foo bar baz"}}
2012
- <!-- results in: 'FooBarBaz' -->
2013
- ```
2014
-
2015
- ### [{{pathcase}}](lib/string.js#L323)
2016
-
2017
- path/case the characters in `string`.
2018
-
2019
- **Params**
2020
-
2021
- * `string` **{String}**
2022
- * `returns` **{String}**
2023
-
2024
- **Example**
2025
-
2026
- ```html
2027
- {{pathcase "a-b-c d_e"}}
2028
- <!-- results in: 'a/b/c/d/e' -->
2029
- ```
2030
-
2031
- ### [{{plusify}}](lib/string.js#L343)
2032
-
2033
- Replace spaces in the given string with pluses.
2034
-
2035
- **Params**
2036
-
2037
- * `str` **{String}**: The input string
2038
- * `returns` **{String}**: Input string with spaces replaced by plus signs
2039
-
2040
- **Example**
2041
-
2042
- ```html
2043
- {{plusify "foo bar baz"}}
2044
- <!-- results in: 'foo+bar+baz' -->
2045
- ```
2046
-
2047
- ### [{{prepend}}](lib/string.js#L363)
2048
-
2049
- Prepends the given `string` with the specified `prefix`.
2050
-
2051
- **Params**
2052
-
2053
- * `str` **{String}**
2054
- * `prefix` **{String}**
2055
- * `returns` **{String}**
2056
-
2057
- **Example**
2058
-
2059
- ```html
2060
- <!-- given that "val" is "bar" -->
2061
- {{prepend val "foo-"}}
2062
- <!-- results in: 'foo-bar' -->
2063
- ```
2064
-
2065
- ### [{{raw}}](lib/string.js#L385)
2066
-
2067
- Render a block without processing mustache templates inside the block.
2068
-
2069
- **Params**
2070
-
2071
- * `options` **{Object}**
2072
- * `returns` **{String}**
2073
-
2074
- **Example**
2075
-
2076
- ```html
2077
- {{{{#raw}}}}
2078
- {{foo}}
2079
- {{{{/raw}}}}
2080
- <!-- results in: '{{foo}}' -->
2081
- ```
2082
-
2083
- ### [{{remove}}](lib/string.js#L413)
2084
-
2085
- Remove all occurrences of `substring` from the given `str`.
2086
-
2087
- **Params**
2088
-
2089
- * `str` **{String}**
2090
- * `substring` **{String}**
2091
- * `returns` **{String}**
2092
-
2093
- **Example**
2094
-
2095
- ```html
2096
- {{remove "a b a b a b" "a "}}
2097
- <!-- results in: 'b b b' -->
2098
- ```
2099
-
2100
- ### [{{removeFirst}}](lib/string.js#L432)
2101
-
2102
- Remove the first occurrence of `substring` from the given `str`.
2103
-
2104
- **Params**
2105
-
2106
- * `str` **{String}**
2107
- * `substring` **{String}**
2108
- * `returns` **{String}**
2109
-
2110
- **Example**
2111
-
2112
- ```html
2113
- {{remove "a b a b a b" "a"}}
2114
- <!-- results in: ' b a b a b' -->
2115
- ```
2116
-
2117
- ### [{{replace}}](lib/string.js#L452)
2118
-
2119
- Replace all occurrences of substring `a` with substring `b`.
2120
-
2121
- **Params**
2122
-
2123
- * `str` **{String}**
2124
- * `a` **{String}**
2125
- * `b` **{String}**
2126
- * `returns` **{String}**
2127
-
2128
- **Example**
2129
-
2130
- ```html
2131
- {{replace "a b a b a b" "a" "z"}}
2132
- <!-- results in: 'z b z b z b' -->
2133
- ```
2134
-
2135
- ### [{{replaceFirst}}](lib/string.js#L473)
2136
-
2137
- Replace the first occurrence of substring `a` with substring `b`.
2138
-
2139
- **Params**
2140
-
2141
- * `str` **{String}**
2142
- * `a` **{String}**
2143
- * `b` **{String}**
2144
- * `returns` **{String}**
2145
-
2146
- **Example**
2147
-
2148
- ```html
2149
- {{replace "a b a b a b" "a" "z"}}
2150
- <!-- results in: 'z b a b a b' -->
2151
- ```
2152
-
2153
- ### [{{reverse}}](lib/string.js#L492)
2154
-
2155
- Reverse a string.
2156
-
2157
- **Params**
2158
-
2159
- * `str` **{String}**
2160
- * `returns` **{String}**
2161
-
2162
- **Example**
2163
-
2164
- ```html
2165
- {{reverse "abcde"}}
2166
- <!-- results in: 'edcba' -->
2167
- ```
2168
-
2169
- ### [{{sentence}}](lib/string.js#L509)
2170
-
2171
- Sentence case the given string
2172
-
2173
- **Params**
2174
-
2175
- * `str` **{String}**
2176
- * `returns` **{String}**
2177
-
2178
- **Example**
2179
-
2180
- ```html
2181
- {{sentence "hello world. goodbye world."}}
2182
- <!-- results in: 'Hello world. Goodbye world.' -->
2183
- ```
2184
-
2185
- ### [{{snakecase}}](lib/string.js#L528)
2186
-
2187
- snake_case the characters in the given `string`.
2188
-
2189
- **Params**
2190
-
2191
- * `string` **{String}**
2192
- * `returns` **{String}**
2193
-
2194
- **Example**
2195
-
2196
- ```html
2197
- {{snakecase "a-b-c d_e"}}
2198
- <!-- results in: 'a_b_c_d_e' -->
2199
- ```
2200
-
2201
- ### [{{split}}](lib/string.js#L547)
2202
-
2203
- Split `string` by the given `character`.
2204
-
2205
- **Params**
2206
-
2207
- * `string` **{String}**: The string to split.
2208
- * `returns` **{String}** `character`: Default is an empty string.
2209
-
2210
- **Example**
2211
-
2212
- ```html
2213
- {{split "a,b,c" ","}}
2214
- <!-- results in: ['a', 'b', 'c'] -->
2215
- ```
2216
-
2217
- ### [{{startsWith}}](lib/string.js#L572)
2218
-
2219
- Tests whether a string begins with the given prefix.
2220
-
2221
- **Params**
2222
-
2223
- * `prefix` **{String}**
2224
- * `testString` **{String}**
2225
- * `options` **{String}**
2226
- * `returns` **{String}**
2227
-
2228
- **Example**
2229
-
2230
- ```html
2231
- {{#startsWith "Goodbye" "Hello, world!"}}
2232
- Whoops
2233
- {{else}}
2234
- Bro, do you even hello world?
2235
- {{/startsWith}}
2236
- ```
2237
-
2238
- ### [{{titleize}}](lib/string.js#L596)
2239
-
2240
- Title case the given string.
2241
-
2242
- **Params**
2243
-
2244
- * `str` **{String}**
2245
- * `returns` **{String}**
2246
-
2247
- **Example**
2248
-
2249
- ```html
2250
- {{titleize "this is title case"}}
2251
- <!-- results in: 'This Is Title Case' -->
2252
- ```
2253
-
2254
- ### [{{trim}}](lib/string.js#L623)
2255
-
2256
- Removes extraneous whitespace from the beginning and end of a string.
2257
-
2258
- **Params**
2259
-
2260
- * `string` **{String}**: The string to trim.
2261
- * `returns` **{String}**
2262
-
2263
- **Example**
2264
-
2265
- ```html
2266
- {{trim " ABC "}}
2267
- <!-- results in: 'ABC' -->
2268
- ```
2269
-
2270
- ### [{{trimLeft}}](lib/string.js#L639)
2271
-
2272
- Removes extraneous whitespace from the beginning of a string.
2273
-
2274
- **Params**
2275
-
2276
- * `string` **{String}**: The string to trim.
2277
- * `returns` **{String}**
2278
-
2279
- **Example**
2280
-
2281
- ```html
2282
- {{trim " ABC "}}
2283
- <!-- results in: 'ABC ' -->
2284
- ```
2285
-
2286
- ### [{{trimRight}}](lib/string.js#L657)
2287
-
2288
- Removes extraneous whitespace from the end of a string.
2289
-
2290
- **Params**
2291
-
2292
- * `string` **{String}**: The string to trim.
2293
- * `returns` **{String}**
2294
-
2295
- **Example**
2296
-
2297
- ```html
2298
- {{trimRight " ABC "}}
2299
- <!-- results in: ' ABC' -->
2300
- ```
2301
-
2302
- ### [{{truncate}}](lib/string.js#L680)
2303
-
2304
- Truncate a string to the specified `length`. Also see [ellipsis](#ellipsis).
2305
-
2306
- **Params**
2307
-
2308
- * `str` **{String}**
2309
- * `limit` **{Number}**: The desired length of the returned string.
2310
- * `suffix` **{String}**: Optionally supply a string to use as a suffix to denote when the string has been truncated. Otherwise an ellipsis (`…`) will be used.
2311
- * `returns` **{String}**: The truncated string.
2312
-
2313
- **Example**
2314
-
2315
- ```html
2316
- truncate("foo bar baz", 7);
2317
- <!-- results in: 'foo bar' -->
2318
- truncate(sanitize("<span>foo bar baz</span>", 7));
2319
- <!-- results in: 'foo bar' -->
2320
- ```
2321
-
2322
- ### [{{truncateWords}}](lib/string.js#L712)
2323
-
2324
- Truncate a string to have the specified number of words. Also see [truncate](#truncate).
2325
-
2326
- **Params**
2327
-
2328
- * `str` **{String}**
2329
- * `limit` **{Number}**: The desired length of the returned string.
2330
- * `suffix` **{String}**: Optionally supply a string to use as a suffix to denote when the string has been truncated.
2331
- * `returns` **{String}**: The truncated string.
2332
-
2333
- **Example**
2334
-
2335
- ```html
2336
- truncateWords("foo bar baz", 1);
2337
- <!-- results in: 'foo…' -->
2338
- truncateWords("foo bar baz", 2);
2339
- <!-- results in: 'foo bar…' -->
2340
- truncateWords("foo bar baz", 3);
2341
- <!-- results in: 'foo bar baz' -->
2342
- ```
2343
-
2344
- ### [{{upcase}}](lib/string.js#L742)
2345
-
2346
- Uppercase all of the characters in the given string. Alias for [uppercase](#uppercase).
2347
-
2348
- **Params**
2349
-
2350
- * `string` **{String}**
2351
- * `returns` **{String}**
2352
-
2353
- **Example**
2354
-
2355
- ```html
2356
- {{upcase "aBcDeF"}}
2357
- <!-- results in: 'ABCDEF' -->
2358
- ```
2359
-
2360
- ### [{{uppercase}}](lib/string.js#L763)
2361
-
2362
- Uppercase all of the characters in the given string. If used as a block helper it will uppercase the entire block. This helper does not support inverse blocks.
2363
-
2364
- **Params**
2365
-
2366
- * `str` **{String}**: The string to uppercase
2367
- * `options` **{Object}**: Handlebars options object
2368
- * `returns` **{String}**
2369
-
2370
- **Example**
2371
-
2372
- ```html
2373
- {{uppercase "aBcDeF"}}
2374
- <!-- results in: 'ABCDEF' -->
2375
- ```
2376
-
2377
- ## url
2378
-
2379
- ### [{{encodeURI}}](lib/url.js#L19)
2380
-
2381
- Encodes a Uniform Resource Identifier (URI) component
2382
- by replacing each instance of certain characters by
2383
- one, two, three, or four escape sequences representing
2384
- the UTF-8 encoding of the character.
2385
-
2386
- **Params**
2387
-
2388
- * `str` **{String}**: The un-encoded string
2389
- * `returns` **{String}**: The endcoded string
2390
-
2391
- ### [{{escape}}](lib/url.js#L34)
2392
-
2393
- Escape the given string by replacing characters with escape sequences.
2394
- Useful for allowing the string to be used in a URL, etc.
2395
-
2396
- **Params**
2397
-
2398
- * `str` **{String}**
2399
- * `returns` **{String}**: Escaped string.
2400
-
2401
- ### [{{decodeURI}}](lib/url.js#L48)
2402
-
2403
- Decode a Uniform Resource Identifier (URI) component.
2404
-
2405
- **Params**
2406
-
2407
- * `str` **{String}**
2408
- * `returns` **{String}**
2409
-
2410
- ### [{{url_encode}}](lib/url.js#L59)
2411
-
2412
- Alias for [encodeURI](#encodeuri).
2413
-
2414
- ### [{{url_decode}}](lib/url.js#L68)
2415
-
2416
- Alias for [decodeURI](#decodeuri).
2417
-
2418
- ### [{{urlResolve}}](lib/url.js#L82)
2419
-
2420
- Take a base URL, and a href URL, and resolve them as a
2421
- browser would for an anchor tag.
2422
-
2423
- **Params**
2424
-
2425
- * `base` **{String}**
2426
- * `href` **{String}**
2427
- * `returns` **{String}**
2428
-
2429
- ### [{{urlParse}}](lib/url.js#L94)
2430
-
2431
- Parses a `url` string into an object.
2432
-
2433
- **Params**
2434
-
2435
- * `str` **{String}**: URL string
2436
- * `returns` **{String}**: Returns stringified JSON
2437
-
2438
- ### [{{stripQuerystring}}](lib/url.js#L106)
2439
-
2440
- Strip the query string from the given `url`.
2441
-
2442
- **Params**
2443
-
2444
- * `url` **{String}**
2445
- * `returns` **{String}**: the url without the queryString
2446
-
2447
- ### [{{stripProtocol}}](lib/url.js#L126)
2448
-
2449
- Strip protocol from a `url`. Useful for displaying media that may have an 'http' protocol on secure connections.
2450
-
2451
- **Params**
2452
-
2453
- * `str` **{String}**
2454
- * `returns` **{String}**: the url with http protocol stripped
2455
-
2456
- **Example**
2457
-
2458
- ```html
2459
- <!-- url = 'http://foo.bar' -->
2460
- {{stripProtocol url}}
2461
- <!-- results in: '//foo.bar' -->
2462
- ```
2463
-
2464
- ***
2465
-
2466
- ## Utils
2467
-
2468
- The following utils are exposed on `.utils`.
2469
-
2470
- ### [{{changecase}}](lib/utils/index.js#L54)
2471
-
2472
- Change casing on the given `string`, optionally passing a delimiter to use between words in the returned string.
2473
-
2474
- **Params**
2475
-
2476
- * `string` **{String}**: The string to change.
2477
- * `returns` **{String}**
2478
-
2479
- **Example**
2480
-
2481
- ```html
2482
- utils.changecase('fooBarBaz');
2483
- //=> 'foo bar baz'
2484
-
2485
- utils.changecase('fooBarBaz' '-');
2486
- //=> 'foo-bar-baz'
2487
- ```
2488
-
2489
- ### [{{random}}](lib/utils/index.js#L80)
2490
-
2491
- Generate a random number
2492
-
2493
- **Params**
2494
-
2495
- * `min` **{Number}**
2496
- * `max` **{Number}**
2497
- * `returns` **{Number}**
2498
-
2499
104
  ## How to Contribute
2500
105
  clone the repository locally and run 'npm i' in the root. Now that you've set up your workspace, you're ready to contribute changes to the `fumanchu` repository you can refer to the [CONTRIBUTING](CONTRIBUTING.md) guide. If you have any questions please feel free to ask by creating an issue and label it `question`.
2501
106