This project is a basic set of 88 Handlebars helpers in 7 categories.
Install basic-handlebars-helpers with npm:
npm install --save basic-handlebars-helpers
Register the Handlebars helpers.
require('basic-handlebars-helpers').helpers.register();
To use the "asciidoc" helper, the Asciidoctor dependency must be installed first. The Asciidoctor instance is used to set up this helper.
const asciidoctor = require('asciidoctor')();
require('basic-handlebars-helpers').helpers.register();
require('basic-handlebars-helpers').utils.asciidoc.setupAsciidoctor(asciidoctor, {/* attributes here */});
Helpers that make the Handlebars template engine usable.
equals, not-equals, and, or, not, xor, iif, type-of, to-boolean, to-number, to-string, to-json, from-json, to-yaml, from-yaml, array, object, range, get-root, get, jsonpath
Helpers for iterable types such as strings, arrays and objects.
length, empty, in, any-in, chunk, slice, reverse, shuffle, sort, first, last, at, concat, flatten, keys, values
Helpers for working with numbers.
is-nan, is-finite, lt, lte, gt, gte, even, odd, nth, round, floor, ceil, inc, dec, abs, neg
Helpers for working with path strings.
basename, dirname, extname, is-absolute-path, normalize-path, relative-path, resolve-path, join-path
Helpers to apply set operations to arrays and objects.
union, intersection, sym-difference, difference
Helpers for working with strings.
asciidoc, format, lowercase, uppercase, capitalize, replace, match, matches, blank, starts-with, ends-with, trim, trim-left, trim-right, split, join
Helpers for working with URL strings.
parse-url, with-auth, with-hostname, with-port, with-pathname, with-query, with-fragment
The version 3.0.0 was used to generate this API documentation.
Helpers that make the Handlebars template engine usable.
Checks whether the arguments are equal.
Parameters:
-
The values to compare.
- types: ...any (spread parameters)
- minimum: 2
Hash Parameters:
-
deep
This flag allows comparing data structures recursively.- types: implicit-boolean
- default: false
Checks whether the arguments are not equal.
Parameters:
-
The values to compare.
- types: ...any (spread parameters)
- minimum: 2
Hash Parameters:
-
deep
This flag allows comparing data structures recursively.- types: implicit-boolean
- default: false
Applies the logical conjunction to multiple values.
Parameters:
-
The values on which the AND operation is applied.
- types: ...implicit-boolean (spread parameters)
- minimum: 0
Applies the logical disjunction to multiple values.
Parameters:
-
The values on which the OR operation is applied.
- types: ...implicit-boolean (spread parameters)
- minimum: 0
Applies the logical negation to multiple values.
Parameters:
-
The values on which the NOT operation is applied.
- types: ...implicit-boolean (spread parameters)
- minimum: 0
Applies the logical exclusive disjunction to multiple values.
Parameters:
-
The values on which the XOR operation is applied.
- types: ...implicit-boolean (spread parameters)
- minimum: 0
Applies if-then-else in one method (known as inline if or ternary if).
Parameters:
-
The condition.
- types: implicit-boolean
- optional: false
-
The value used if condition is true.
- types: any
- optional: false
-
The value used if condition is false.
- types: any
- optional: false
Gets the type of a value.
Parameters:
-
The value for which the type is to be determined.
- types: any
- optional: false
Converts a value to a boolean type.
Parameters:
-
The value to be converted to boolean.
- types: any
- optional: false
Converts a value to a number type.
Parameters:
-
The value to be converted to number.
- types: any
- optional: false
Converts a value to a string type.
Parameters:
-
The value to be converted to string.
- types: any
- optional: false
Converts a value to a JSON string.
Parameters:
-
The value to be converted to a JSON string.
- types: any
- optional: false
Hash Parameters:
-
indent
The depth to indent. Zero means no indentation.- types: number
- default: 0
Parses a JSON string.
Parameters:
-
The value to be parsed.
- types: string
- optional: false
Converts a value to a YAML string.
Parameters:
-
The value to be converted to a YAML string.
- types: any
- optional: false
Parses a YAML string.
Parameters:
-
The value to be parsed.
- types: string
- optional: false
Hash Parameters:
-
multiple
This flag allows parsing of multi-document sources.- types: implicit-boolean
- default: false
Creates an array from arguments.
Parameters:
-
The elements of the new array.
- types: ...any (spread parameters)
- minimum: 0
Creates an object from hash arguments.
Creates a range of numbers as an array.
Parameters:
-
The inclusive number at which the range is started.
- types: number
- optional: false
-
The inclusive number at which the range is stopped.
- types: number
- optional: true
-
The increment step or decrement step if this number negative. The default is 1.
- types: number
- optional: true
Gets the a value from the root object by a sequence of keys and indices.
Parameters:
-
The keys or indices used to find a value in the data structure.
- types: ...any (spread parameters)
- minimum: 0
Gets a value from a data structure by a sequence of keys and indices.
Parameters:
-
The data structure.
- types: array, object
- optional: false
-
The keys or indices used to find a value in the data structure.
- types: ...any (spread parameters)
- minimum: 0
Gets a value from a data structure by a JSONPath expression.
Parameters:
-
The data structure.
- types: array, object
- optional: false
-
The query.
- types: string
- optional: false
Helpers for iterable types such as strings, arrays and objects.
Gets the length of an iterable value.
Parameters:
-
The given iterable value.
- types: string, array, object
- optional: false
Checks whether an iterable value is empty.
Parameters:
-
The given iterable value.
- types: string, array, object
- optional: false
Checks whether all of the given elements are included in an iterable value.
Parameters:
-
The given iterable value.
- types: string, array, object
- optional: false
-
The values to test.
- types: ...any (spread parameters)
- minimum: 1
Checks whether any of the given elements is included in an iterable value.
Parameters:
-
The given iterable value.
- types: string, array, object
- optional: false
-
The values to test.
- types: ...any (spread parameters)
- minimum: 1
Gets chunks of an iterable value with variable length.
Parameters:
-
The given iterable value.
- types: string, array, object
- optional: false
-
The size of the chunks.
- types: number
- optional: false
Gets a contiguous subsequence of an iterable value.
Parameters:
-
The given iterable value.
- types: string, array, object
- optional: false
-
The inclusive index at which the slice begins.
- types: number
- optional: false
-
The exclusive index at which the slice ends.
- types: number
- optional: true
Gets the elements of an iterable value in reverse order.
Parameters:
-
The given iterable value.
- types: string, array, object
- optional: false
Shuffles the elements of an iterable value in random order.
Parameters:
-
The given iterable value.
- types: string, array, object
- optional: false
Sorts the elements of an iterable value.
Parameters:
-
The given iterable value.
- types: string, array, object
- optional: false
-
The keys or indices used to find the values to compare.
- types: ...any (spread parameters)
- minimum: 0
Hash Parameters:
-
descending
This flag switches from ascending to descending order.- types: implicit-boolean
- default: false
-
ignorecase
This flag allows ignore-case comparison.- types: implicit-boolean
- default: false
Gets the first element of an iterable value.
Parameters:
-
The given iterable value.
- types: string, array, object
- optional: false
Gets the last element of an iterable value.
Parameters:
-
The given iterable value.
- types: string, array, object
- optional: false
Gets an element at a specific index of an iterable value.
Parameters:
-
The given iterable value.
- types: string, array, object
- optional: false
-
The index of the value to get.
- types: any
- optional: false
Concatenates two or more strings or arrays.
Parameters:
-
The strings or arrays to concatenate.
- types: ...string, ...array (spread parameters) (all should be of the same type)
- minimum: 2
Flattens an array with variable depth.
Parameters:
-
The given array.
- types: array
- optional: false
-
The depth to flatten. Zero means infinite depth. The default value is 1.
- types: number
- optional: true
Gets the keys of an object.
Parameters:
-
The given object.
- types: object
- optional: false
Gets the values of an object.
Parameters:
-
The given object.
- types: object
- optional: false
Helpers for working with numbers.
Checks whether a number is NaN.
Parameters:
-
The given number.
- types: number
- optional: false
Checks whether a number is finite.
Parameters:
-
The given number.
- types: number
- optional: false
Checks strictly increasing order of multiple numbers.
Parameters:
-
The given numbers to compare.
- types: ...number (spread parameters)
- minimum: 2
Checks increasing order of multiple numbers.
Parameters:
-
The given numbers to compare.
- types: ...number (spread parameters)
- minimum: 2
Checks strictly decreasing order of multiple numbers.
Parameters:
-
The given numbers to compare.
- types: ...number (spread parameters)
- minimum: 2
Checks decreasing order of multiple numbers.
Parameters:
-
The given numbers to compare.
- types: ...number (spread parameters)
- minimum: 2
Checks for even numbers.
Parameters:
-
The given number.
- types: number
- optional: false
Checks for odd numbers.
Parameters:
-
The given number.
- types: number
- optional: false
Checks for multiples of a number.
Parameters:
-
The given number to check.
- types: number
- optional: false
-
The factor.
- types: number
- optional: false
Rounds a number to the nearest digit value at a specific decimal position.
Parameters:
-
The given number.
- types: number
- optional: false
-
The number of digits after the floating point to round. The default is zero.
- types: number
- optional: true
Rounds a number down at a specific decimal position.
Parameters:
-
The given number.
- types: number
- optional: false
-
The number of digits after the floating point to round. The default is zero.
- types: number
- optional: true
Rounds a number up at a specific decimal position.
Parameters:
-
The given number.
- types: number
- optional: false
-
The number of digits after the floating point to round. The default is zero.
- types: number
- optional: true
Increases a number.
Parameters:
-
The given number.
- types: number
- optional: false
-
The increment step. The default value is 1.
- types: number
- optional: true
Decreases a number.
Parameters:
-
The given number.
- types: number
- optional: false
-
The decrement step. The default value is 1.
- types: number
- optional: true
Gets the absolute value of a number.
Parameters:
-
The given number.
- types: number
- optional: false
Gets the negated value of a number.
Parameters:
-
The given number.
- types: number
- optional: false
Helpers for working with path strings.
Gets the last part of a given path.
Parameters:
-
The given path.
- types: string
- optional: false
-
An optional file extension.
- types: string
- optional: true
Gets the directory name of a given path.
Parameters:
-
The given path.
- types: string
- optional: false
Gets the file extension of the given path.
Parameters:
-
The given path.
- types: string
- optional: false
Checks whether the given path is absolute.
Parameters:
-
The given path.
- types: string
- optional: false
Normalizes a given path.
Parameters:
-
The given path.
- types: string
- optional: false
Gets a relative path.
Parameters:
-
A path to relativize from this path to another path.
- types: string
- optional: false
-
A path to relativize from the other path to this path.
- types: string
- optional: false
Gets a resolved path from multiple paths.
Parameters:
-
The given paths to resolve.
- types: ...string (spread parameters)
- minimum: 1
Joins all given paths together.
Parameters:
-
The given paths to join.
- types: ...string (spread parameters)
- minimum: 1
Helpers to apply set operations to arrays and objects.
Creates the union of multiple arrays or objects
Parameters:
-
The given arrays or objects.
- types: ...array, ...object (spread parameters) (all should be of the same type)
- minimum: 1
Hash Parameters:
-
deep
This flag allows merging data structures recursively.- types: implicit-boolean
- default: false
Creates the intersection of multiple arrays or objects
Parameters:
-
The given arrays or objects.
- types: ...array, ...object (spread parameters) (all should be of the same type)
- minimum: 1
Creates the symmetric difference of multiple arrays or objects
Parameters:
-
The given arrays or objects.
- types: ...array, ...object (spread parameters) (all should be of the same type)
- minimum: 1
Creates the difference by applying the first one to all further arrays or objects
Parameters:
-
The given arrays or objects.
- types: ...array, ...object (spread parameters) (all should be of the same type)
- minimum: 2
Helpers for working with strings.
Converts AsciiDoc to HTML.
Parameters:
-
A string with AsciiDoc content.
- types: string
- optional: false
Hash Parameters:
-
inline
This flag switches the doctype between article and inline.- types: implicit-boolean
- default: false
Formats a string in the way of the sprintf method.
Parameters:
-
The format string.
- types: string
- optional: false
-
The arguments for the format string.
- types: ...any (spread parameters)
- minimum: 0
Gets the lowercase string.
Parameters:
-
The given string.
- types: string
- optional: false
Gets the uppercase string.
Parameters:
-
The given string.
- types: string
- optional: false
Gets the capitalized string.
Parameters:
-
The given string.
- types: string
- optional: false
Hash Parameters:
-
global
This flag allows to capitalize all words.- types: implicit-boolean
- default: false
Replaces some parts of a string by a regular expression.
Parameters:
-
The given string.
- types: string
- optional: false
-
The pattern.
- types: string
- optional: false
-
The replacement.
- types: string
- optional: false
Hash Parameters:
-
global
This flag allows replacing with any occurrence instead of just the first match.- types: implicit-boolean
- default: false
-
multiline
This flag allows matching every line as a separate input.- types: implicit-boolean
- default: false
Extracts parts of a string by a regular expression.
Parameters:
-
The given string.
- types: string
- optional: false
-
The pattern.
- types: string
- optional: false
Hash Parameters:
-
global
This flag allows extracting all occurrences instead of just the first match.- types: implicit-boolean
- default: false
-
multiline
This flag allows matching every line as a separate input.- types: implicit-boolean
- default: false
Checks whether a string matches a regular expression.
Parameters:
-
The given string.
- types: string
- optional: false
-
The pattern.
- types: string
- optional: false
Hash Parameters:
-
multiline
This flag allows matching every line as a separate input.- types: implicit-boolean
- default: false
Checks whether a string is empty or contains only spaces.
Parameters:
-
The given string.
- types: string
- optional: false
Checks whether a string starts with another string.
Parameters:
-
The given string.
- types: string
- optional: false
-
The search string.
- types: string
- optional: false
Checks whether a string ends with another string.
Parameters:
-
The given string.
- types: string
- optional: false
-
The search string.
- types: string
- optional: false
Gets a string without leading or trailing spaces.
Parameters:
-
The given string.
- types: string
- optional: false
Gets a string without leading spaces.
Parameters:
-
The given string.
- types: string
- optional: false
Gets a string without trailing spaces.
Parameters:
-
The given string.
- types: string
- optional: false
Splits a string into an array by a separator.
Parameters:
-
The given string.
- types: string
- optional: false
-
The separator.
- types: string
- optional: false
Joins an array of strings together to one string by a separator.
Parameters:
-
The given array of strings.
- types: array
- optional: false
-
The separator. The default value is an empty string.
- types: string
- optional: true
Helpers for working with URL strings.
Parses an URL string and returns an object with URL parts.
Parameters:
-
The given URL string.
- types: string
- optional: false
Gets an URL with a specified username and password.
Parameters:
-
The given URL string.
- types: string
- optional: false
-
The username.
- types: string, null
- optional: false
-
The password.
- types: string, null
- optional: true
Gets an URL with a specified hostname.
Parameters:
-
The given URL string.
- types: string
- optional: false
-
The hostname.
- types: string
- optional: false
Gets an URL with a specified port.
Parameters:
-
The given URL string.
- types: string
- optional: false
-
The port.
- types: string, number, null
- optional: false
Gets an URL with a specified pathname.
Parameters:
-
The given URL string.
- types: string
- optional: false
-
The pathname.
- types: string, null
- optional: false
Gets an URL with a specified query part.
Parameters:
-
The given URL string.
- types: string
- optional: false
-
The query part.
- types: string, array, object, null
- optional: false
Hash Parameters:
-
append
This flag allows to append to an existing query part.- types: implicit-boolean
- default: false
Gets an URL with a specified fragment.
Parameters:
-
The given URL string.
- types: string
- optional: false
-
The fragment.
- types: string, null
- optional: false
Copyright (c) 2022 Eric Löffler (brettaufheber)
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.