@jaredwray/fumanchu 1.0.2 → 1.1.0

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.
package/README.md CHANGED
@@ -13,7 +13,7 @@ Handlebars + Helpers Together
13
13
 
14
14
  ## Table of Contents
15
15
  * [Using in Nodejs](#using-in-nodejs)
16
- * [Using in Browser](#using-in-browser)
16
+ * [Just using Handlebar Helpers](#using-handlebars-helpers)
17
17
  * [Helpers](#helpers)
18
18
  * [How to Contribute](#how-to-contribute)
19
19
  * [License and Copyright](#license-and-copyright)
@@ -21,7 +21,9 @@ Handlebars + Helpers Together
21
21
  ## Usage Nodejs
22
22
 
23
23
  ```bash
24
- npm install @jaredwray/fumanchu
24
+ npm install @jaredwray/fumanchu --save
25
+ // or
26
+ yarn add @jaredwray/fumanchu
25
27
  ```
26
28
 
27
29
  ```javascript
@@ -33,6 +35,20 @@ console.log(html);
33
35
 
34
36
  It's just that easy! No need to add Handlebars to your project, it's already included.
35
37
 
38
+ ## Using Handlebars Helpers
39
+
40
+ If you only want to use handlebar helpers you can easily do that by doing the following:
41
+
42
+ ```javascript
43
+ var helpers = require('@jaredwray/fumanchu').handlebarHelpers;
44
+ var handlebars = require('handlebars');
45
+ helpers({ handlebars: handlebars });
46
+ var fn = handlebars.compile('{{add value 5}}');
47
+ console.log(fn);
48
+ ```
49
+
50
+ Notice that in this scenario you are accessing helpers via `handlebarHelpers` from `fumanchu` instead of just using handlebars via fumanchu directly.
51
+
36
52
  ## Helpers
37
53
  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.
38
54
 
@@ -78,13 +94,13 @@ Visit the: [code](lib/array.js) | [unit tests](test/array.js) | [issues](https:/
78
94
  * **[isArray](#isArray)** ([code](lib/array.js#L244) | [tests](test/array.js#L172))
79
95
  * **[itemAt](#itemAt)** ([code](lib/array.js#L263) | [tests](test/array.js#L182))
80
96
  * **[join](#join)** ([code](lib/array.js#L294) | [tests](test/array.js#L225))
81
- * **[equalsLength](#equalsLength)** ([code](lib/array.js#L313) | [no tests])
97
+ * **[equalsLength](#equalsLength)** ([code](lib/array.js#L313) | [tests](test/array.js#L494))
82
98
  * **[last](#last)** ([code](lib/array.js#L349) | [tests](test/array.js#L240))
83
99
  * **[length](#length)** ([code](lib/array.js#L379) | [tests](test/array.js#L254))
84
100
  * **[lengthEqual](#lengthEqual)** ([code](lib/array.js#L395) | [tests](test/array.js#L254))
85
101
  * **[map](#map)** ([code](lib/array.js#L414) | [tests](test/array.js#L266))
86
102
  * **[pluck](#pluck)** ([code](lib/array.js#L445) | [tests](test/array.js#L300))
87
- * **[reverse](#reverse)** ([code](lib/array.js#L473) | [no tests])
103
+ * **[reverse](#reverse)** ([code](lib/array.js#L473) | [tests](test/array.js#L506))
88
104
  * **[some](#some)** ([code](lib/array.js#L504) | [tests](test/array.js#L308))
89
105
  * **[sort](#sort)** ([code](lib/array.js#L532) | [tests](test/array.js#L333))
90
106
  * **[sortBy](#sortBy)** ([code](lib/array.js#L557) | [tests](test/array.js#L358))
@@ -133,7 +149,7 @@ Visit the: [code](lib/comparison.js) | [unit tests](test/comparison.js) | [issue
133
149
  * **[lt](#lt)** ([code](lib/comparison.js#L411) | [tests](test/comparison.js#L449))
134
150
  * **[lte](#lte)** ([code](lib/comparison.js#L435) | [tests](test/comparison.js#L476))
135
151
  * **[neither](#neither)** ([code](lib/comparison.js#L456) | [tests](test/comparison.js#L511))
136
- * **[not](#not)** ([code](lib/comparison.js#L470) | [no tests])
152
+ * **[not](#not)** ([code](lib/comparison.js#L470) | [tests](test/comparison.js#L624))
137
153
  * **[or](#or)** ([code](lib/comparison.js#L492) | [tests](test/comparison.js#L523))
138
154
  * **[unlessEq](#unlessEq)** ([code](lib/comparison.js#L518) | [tests](test/comparison.js#L556))
139
155
  * **[unlessGt](#unlessGt)** ([code](lib/comparison.js#L538) | [tests](test/comparison.js#L567))
@@ -211,37 +227,37 @@ Visit the: [code](lib/match.js) | [unit tests](test/match.js) | [issues](https:/
211
227
 
212
228
  * **[match](#match)** ([code](lib/match.js#L23) | [tests](test/match.js#L13))
213
229
  * **[isMatch](#isMatch)** ([code](lib/match.js#L47) | [tests](test/match.js#L61))
214
- * **[mm](#mm)** ([code](lib/match.js#L56) | [no tests])
230
+ * **[mm](#mm)** ([code](lib/match.js#L56) | [tests](test/match.js#L67))
215
231
 
216
232
  ### [math helpers](#math)
217
233
 
218
234
  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))
219
235
 
220
- * **[abs](#abs)** ([code](lib/math.js#L15) | [no tests])
236
+ * **[abs](#abs)** ([code](lib/math.js#L15) | [test](test/math.js#L149))
221
237
  * **[add](#add)** ([code](lib/math.js#L31) | [tests](test/math.js#L10))
222
- * **[avg](#avg)** ([code](lib/math.js#L54) | [no tests])
238
+ * **[avg](#avg)** ([code](lib/math.js#L54) | [tests](test/math.js#L25))
223
239
  * **[ceil](#ceil)** ([code](lib/math.js#L69) | [tests](test/math.js#L29))
224
240
  * **[divide](#divide)** ([code](lib/math.js#L84) | [tests](test/math.js#L36))
225
241
  * **[floor](#floor)** ([code](lib/math.js#L102) | [tests](test/math.js#L43))
226
- * **[minus](#minus)** ([code](lib/math.js#L118) | [no tests])
227
- * **[modulo](#modulo)** ([code](lib/math.js#L137) | [no tests])
242
+ * **[minus](#minus)** ([code](lib/math.js#L118) | [tests](test/math.js#L169))
243
+ * **[modulo](#modulo)** ([code](lib/math.js#L137) | [tests](test/math.js#L191))
228
244
  * **[multiply](#multiply)** ([code](lib/math.js#L157) | [tests](test/math.js#L50))
229
- * **[plus](#plus)** ([code](lib/math.js#L175) | [no tests])
245
+ * **[plus](#plus)** ([code](lib/math.js#L175) | [tests](test/math.js#L231))
230
246
  * **[random](#random)** ([code](lib/math.js#L194) | [tests](test/math.js#L102))
231
247
  * **[remainder](#remainder)** ([code](lib/math.js#L212) | [tests](test/math.js#L57))
232
248
  * **[round](#round)** ([code](lib/math.js#L224) | [tests](test/math.js#L69))
233
249
  * **[subtract](#subtract)** ([code](lib/math.js#L241) | [tests](test/math.js#L76))
234
250
  * **[sum](#sum)** ([code](lib/math.js#L263) | [tests](test/math.js#L83))
235
- * **[times](#times)** ([code](lib/math.js#L286) | [no tests])
251
+ * **[times](#times)** ([code](lib/math.js#L286) | [tests](test/math.js#L299))
236
252
 
237
253
  ### [misc helpers](#misc)
238
254
 
239
255
  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))
240
256
 
241
- * **[frame](#frame)** ([code](lib/misc.js#L11) | [no tests])
257
+ * **[frame](#frame)** ([code](lib/misc.js#L11) | [tests](test/misc.js#L1))
242
258
  * **[option](#option)** ([code](lib/misc.js#L26) | [tests](test/misc.js#L20))
243
259
  * **[noop](#noop)** ([code](lib/misc.js#L39) | [tests](test/misc.js#L13))
244
- * **[typeOf](#typeOf)** ([code](lib/misc.js#L59) | [no tests])
260
+ * **[typeOf](#typeOf)** ([code](lib/misc.js#L59) | [tests](test/misc.js#L38))
245
261
  * **[withHash](#withHash)** ([code](lib/misc.js#L71) | [tests](test/misc.js#L38))
246
262
 
247
263
  ### [number helpers](#number)
@@ -287,21 +303,21 @@ Visit the: [code](lib/path.js) | [unit tests](test/path.js) | [issues](https://g
287
303
  * **[basename](#basename)** ([code](lib/path.js#L81) | [tests](test/path.js#L47))
288
304
  * **[stem](#stem)** ([code](lib/path.js#L100) | [tests](test/path.js#L58))
289
305
  * **[extname](#extname)** ([code](lib/path.js#L119) | [tests](test/path.js#L69))
290
- * **[resolve](#resolve)** ([code](lib/path.js#L138) | [no tests])
306
+ * **[resolve](#resolve)** ([code](lib/path.js#L138) | [tests](test/path.js#L145))
291
307
  * **[segments](#segments)** ([code](lib/path.js#L166) | [tests](test/path.js#L80))
292
308
 
293
309
  ### [regex helpers](#regex)
294
310
 
295
311
  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))
296
312
 
297
- * **[toRegex](#toRegex)** ([code](lib/regex.js#L19) | [no tests])
298
- * **[test](#test)** ([code](lib/regex.js#L42) | [no tests])
313
+ * **[toRegex](#toRegex)** ([code](lib/regex.js#L19) | [tests](test/regex.js#10))
314
+ * **[test](#test)** ([code](lib/regex.js#L42) | [tests](test/regex.js#15))
299
315
 
300
316
  ### [string helpers](#string)
301
317
 
302
318
  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))
303
319
 
304
- * **[append](#append)** ([code](lib/string.js#L22) | [no tests])
320
+ * **[append](#append)** ([code](lib/string.js#L22) | [tests](test/string.js#L9))
305
321
  * **[camelcase](#camelcase)** ([code](lib/string.js#L41) | [tests](test/string.js#L10))
306
322
  * **[capitalize](#capitalize)** ([code](lib/string.js#L60) | [tests](test/string.js#L25))
307
323
  * **[capitalizeAll](#capitalizeAll)** ([code](lib/string.js#L77) | [tests](test/string.js#L36))
@@ -309,7 +325,7 @@ Visit the: [code](lib/string.js) | [unit tests](test/string.js) | [issues](https
309
325
  * **[chop](#chop)** ([code](lib/string.js#L125) | [tests](test/string.js#L58))
310
326
  * **[dashcase](#dashcase)** ([code](lib/string.js#L143) | [tests](test/string.js#L73))
311
327
  * **[dotcase](#dotcase)** ([code](lib/string.js#L162) | [tests](test/string.js#L88))
312
- * **[downcase](#downcase)** ([code](lib/string.js#L182) | [no tests])
328
+ * **[downcase](#downcase)** ([code](lib/string.js#L182) | [tests](test/string.js#L391))
313
329
  * **[ellipsis](#ellipsis)** ([code](lib/string.js#L202) | [tests](test/string.js#L103))
314
330
  * **[hyphenate](#hyphenate)** ([code](lib/string.js#L223) | [tests](test/string.js#L118))
315
331
  * **[isString](#isString)** ([code](lib/string.js#L240) | [tests](test/string.js#L129))
@@ -318,12 +334,12 @@ Visit the: [code](lib/string.js) | [unit tests](test/string.js) | [issues](https
318
334
  * **[pascalcase](#pascalcase)** ([code](lib/string.js#L303) | [tests](test/string.js#L173))
319
335
  * **[pathcase](#pathcase)** ([code](lib/string.js#L323) | [tests](test/string.js#L188))
320
336
  * **[plusify](#plusify)** ([code](lib/string.js#L343) | [tests](test/string.js#L203))
321
- * **[prepend](#prepend)** ([code](lib/string.js#L363) | [no tests])
322
- * **[raw](#raw)** ([code](lib/string.js#L385) | [no tests])
323
- * **[remove](#remove)** ([code](lib/string.js#L413) | [no tests])
324
- * **[removeFirst](#removeFirst)** ([code](lib/string.js#L432) | [no tests])
337
+ * **[prepend](#prepend)** ([code](lib/string.js#L363) | [tests](test/string.js#L409))
338
+ * **[raw](#raw)** ([code](lib/string.js#L385) | [tests](test/string.js#L465))
339
+ * **[remove](#remove)** ([code](lib/string.js#L413) | [tests](test/string.js#L416)
340
+ * **[removeFirst](#removeFirst)** ([code](lib/string.js#L432) | [tests](test/string.js#L422))
325
341
  * **[replace](#replace)** ([code](lib/string.js#L452) | [tests](test/string.js#L222))
326
- * **[replaceFirst](#replaceFirst)** ([code](lib/string.js#L473) | [no tests])
342
+ * **[replaceFirst](#replaceFirst)** ([code](lib/string.js#L473) | [tests](test/string.js#L428))
327
343
  * **[reverse](#reverse)** ([code](lib/string.js#L492) | [tests](test/string.js#L241))
328
344
  * **[sentence](#sentence)** ([code](lib/string.js#L509) | [tests](test/string.js#L252))
329
345
  * **[snakecase](#snakecase)** ([code](lib/string.js#L528) | [tests](test/string.js#L263))
@@ -331,11 +347,11 @@ Visit the: [code](lib/string.js) | [unit tests](test/string.js) | [issues](https
331
347
  * **[startsWith](#startsWith)** ([code](lib/string.js#L572) | [tests](test/string.js#L293))
332
348
  * **[titleize](#titleize)** ([code](lib/string.js#L596) | [tests](test/string.js#L312))
333
349
  * **[trim](#trim)** ([code](lib/string.js#L623) | [tests](test/string.js#L323))
334
- * **[trimLeft](#trimLeft)** ([code](lib/string.js#L639) | [no tests])
335
- * **[trimRight](#trimRight)** ([code](lib/string.js#L657) | [no tests])
350
+ * **[trimLeft](#trimLeft)** ([code](lib/string.js#L639) | [tests](test/string.js#L436))
351
+ * **[trimRight](#trimRight)** ([code](lib/string.js#L657) | [tests](test/string.js#L441))
336
352
  * **[truncate](#truncate)** ([code](lib/string.js#L680) | [tests](test/string.js#L338))
337
- * **[truncateWords](#truncateWords)** ([code](lib/string.js#L712) | [no tests])
338
- * **[upcase](#upcase)** ([code](lib/string.js#L742) | [no tests])
353
+ * **[truncateWords](#truncateWords)** ([code](lib/string.js#L712) | [tests](test/string.js#L447)))
354
+ * **[upcase](#upcase)** ([code](lib/string.js#L742) | [tests](test/string.js#458))
339
355
  * **[uppercase](#uppercase)** ([code](lib/string.js#L763) | [tests](test/string.js#L362))
340
356
 
341
357
  ### [url helpers](#url)
@@ -343,14 +359,14 @@ Visit the: [code](lib/string.js) | [unit tests](test/string.js) | [issues](https
343
359
  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))
344
360
 
345
361
  * **[encodeURI](#encodeURI)** ([code](lib/url.js#L19) | [tests](test/url.js#L31))
346
- * **[escape](#escape)** ([code](lib/url.js#L34) | [no tests])
362
+ * **[escape](#escape)** ([code](lib/url.js#L34) | [tests](test/url.js#L81))
347
363
  * **[decodeURI](#decodeURI)** ([code](lib/url.js#L48) | [tests](test/url.js#L38))
348
- * **[url_encode](#url_encode)** ([code](lib/url.js#L59) | [no tests])
349
- * **[url_decode](#url_decode)** ([code](lib/url.js#L68) | [no tests])
364
+ * **[url_encode](#url_encode)** ([code](lib/url.js#L59) | [tests](test/url.js#L89))
365
+ * **[url_decode](#url_decode)** ([code](lib/url.js#L68) | [tests](test/url.js#L93))
350
366
  * **[urlResolve](#urlResolve)** ([code](lib/url.js#L82) | [tests](test/url.js#L11))
351
367
  * **[urlParse](#urlParse)** ([code](lib/url.js#L94) | [tests](test/url.js#L45))
352
368
  * **[stripQuerystring](#stripQuerystring)** ([code](lib/url.js#L106) | [tests](test/url.js#L24))
353
- * **[stripProtocol](#stripProtocol)** ([code](lib/url.js#L126) | [no tests])
369
+ * **[stripProtocol](#stripProtocol)** ([code](lib/url.js#L126) | [tests](test/url.js#L53))
354
370
 
355
371
  ***
356
372
 
package/index.d.ts CHANGED
@@ -1,16 +1,3 @@
1
1
  // index.d.ts
2
-
3
- // Importing types from the handlebars package
4
- import { Handlebars } from 'handlebars';
5
-
6
- // Assuming helpers.js exports a function. Adjust as needed.
7
- interface HelpersFunction {
8
- (config: { handlebars: typeof Handlebars }): void;
9
- }
10
-
11
- // Since you're exporting the handlebars instance itself:
12
- declare const handlebars: typeof Handlebars;
13
-
14
- export = handlebars;
15
-
16
-
2
+ import * as Handlebars from 'handlebars';
3
+ export = Handlebars;
package/index.js CHANGED
@@ -5,3 +5,4 @@ const handlebars = HandlebarsLib.create();
5
5
  helpers({ handlebars: handlebars });
6
6
 
7
7
  module.exports = handlebars;
8
+ module.exports.handlebarHelpers = helpers;
package/lib/math.js CHANGED
@@ -32,9 +32,6 @@ helpers.add = function(a, b) {
32
32
  if (isNumber(a) && isNumber(b)) {
33
33
  return Number(a) + Number(b);
34
34
  }
35
- if (typeof a === 'string' && typeof b === 'string') {
36
- return a + b;
37
- }
38
35
  return '';
39
36
  };
40
37
 
package/lib/path.js CHANGED
@@ -5,6 +5,15 @@ var path = require('path');
5
5
  var utils = require('./utils');
6
6
  var helpers = module.exports;
7
7
 
8
+ utils.expectedType = (variableName, expectedType, variableValue) => {
9
+ const actualType = Object.prototype.toString.call(variableValue).slice(8, -1).toLowerCase();
10
+
11
+ if (actualType !== expectedType) {
12
+ throw new TypeError(`Expected ${variableName} to be of type ${expectedType}, but got ${actualType}`);
13
+ }
14
+ };
15
+
16
+
8
17
  /**
9
18
  * Get the directory path segment from the given `filepath`.
10
19
  *
package/lib/regex.js CHANGED
@@ -43,7 +43,7 @@ helpers.test = function(str, regex) {
43
43
  if (!util.isString(str)) {
44
44
  return false;
45
45
  }
46
- if (!utils.typeOf(regex) === 'regexp') {
46
+ if (utils.typeOf(regex) !== 'regexp') {
47
47
  throw new TypeError('expected a regular expression');
48
48
  }
49
49
  return regex.test(str);
package/lib/string.js CHANGED
@@ -460,7 +460,7 @@ helpers.replace = function(str, a, b) {
460
460
  * Replace the first occurrence of substring `a` with substring `b`.
461
461
  *
462
462
  * ```handlebars
463
- * {{replace "a b a b a b" "a" "z"}}
463
+ * {{replaceFirst "a b a b a b" "a" "z"}}
464
464
  * <!-- results in: 'z b a b a b' -->
465
465
  * ```
466
466
  * @param {String} `str`
@@ -695,9 +695,9 @@ helpers.truncate = function(str, limit, suffix) {
695
695
  *
696
696
  * ```handlebars
697
697
  * truncateWords("foo bar baz", 1);
698
- * <!-- results in: 'foo…' -->
698
+ * <!-- results in: 'foo...' -->
699
699
  * truncateWords("foo bar baz", 2);
700
- * <!-- results in: 'foo bar…' -->
700
+ * <!-- results in: 'foo bar...' -->
701
701
  * truncateWords("foo bar baz", 3);
702
702
  * <!-- results in: 'foo bar baz' -->
703
703
  * ```
@@ -712,12 +712,12 @@ helpers.truncate = function(str, limit, suffix) {
712
712
  helpers.truncateWords = function(str, count, suffix) {
713
713
  if (util.isString(str) && isNumber(count)) {
714
714
  if (typeof suffix !== 'string') {
715
- suffix = '…';
715
+ suffix = '...';
716
716
  }
717
717
 
718
718
  var num = Number(count);
719
- var arr = str.split(/[ \t]/);
720
- if (num > arr.length) {
719
+ var arr = str.split(' ');
720
+ if (num < arr.length) {
721
721
  arr = arr.slice(0, num);
722
722
  }
723
723
 
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@jaredwray/fumanchu",
3
3
  "description": "Handlebars + Helpers = Fumanchu",
4
- "version": "1.0.2",
4
+ "version": "1.1.0",
5
5
  "homepage": "https://github.com/jaredwray/fumanchu",
6
6
  "author": "Jared Wray (me@jaredwray.com)",
7
7
  "keywords": [
@@ -97,15 +97,13 @@
97
97
  "source": "index.js",
98
98
  "main": "index.js",
99
99
  "types": "index.d.ts",
100
- "browser": "dist/fumanchu.min.js",
101
100
  "engines": {
102
101
  "node": ">=14"
103
102
  },
104
103
  "scripts": {
105
104
  "test": "c8 mocha --reporter list",
106
105
  "test:ci": "c8 --reporter=lcov mocha --reporter list",
107
- "build": "parcel build --dist-dir dist",
108
- "clean": "rm -rf node_modules && rm -rf dist && rm -rf .parcel-cache"
106
+ "clean": "rm -rf node_modules && rm -rf coverage"
109
107
  },
110
108
  "dependencies": {
111
109
  "arr-flatten": "^1.1.0",
@@ -138,22 +136,10 @@
138
136
  "year": "^0.2.1"
139
137
  },
140
138
  "devDependencies": {
141
- "@parcel/watcher": "^2.3.0",
142
139
  "c8": "^8.0.1",
143
140
  "chai": "^4.3.8",
144
- "global-modules": "^2.0.0",
145
141
  "mocha": "^10.2.0",
146
- "parcel": "^2.9.3",
147
142
  "template-helpers": "^1.0.1",
148
143
  "templates": "^1.2.9"
149
- },
150
- "browserslist": [
151
- "last 1 version",
152
- "> 1%",
153
- "not dead"
154
- ],
155
- "targets": {
156
- "main": false,
157
- "types": false
158
144
  }
159
145
  }