hbl-strings
v0.1.0
Published
A helper for Handlebars that adds string manipulation.
Downloads
3
Readme
hbl-strings
A helper for Handlebars that adds string manipulation. Meant to superseed helpers/handlebars-helpers
' string helpers.
It omits a few helpers, namely :
{{ dashcase str }}
{{ dotcase str }}
{{ pascalcase str }}
{{ pathcase str }}
{{ sentence str }}
{{ snakecase str }}
{{ titleize str }}
These helpers are/were broken in the original package ; a string like this it title case
would become This Is Title Case
instead of This is Title Case
when using {{titleize str}}
, or would take I Like TV
and make it I like tv
when using {{ sentence str }}
. If you need these helpers, you will need to still use helpers/handlebars-helpers
or a different helper package.
Usage
const Handlebars = require('handlebars');
require('hbl-strings').default();
const tpl = Handlebars.compile('{{trim x}}');
console.log(tpl({x: ' Neutralis '})) // result : 'Neutralis'
Package documentation
{{ append str suffix }}
Append a substring to a string.
Usage : {{ append "Neu" "tralis" }}
Result : Neutralis
{{ camelcase str }}
Converts a string to camelcase.
Usage : {{ camelcase "neutralis maintains packages" }}
Result : neutralis_maintains_packages
{{ capitalize str }}
Capitalise a string. Aliased to {{ capitalise str }}
.
Usage : {{ capitalize "neutralis" }}
Result : Neutralis
{{ capitalizeAll str }}
Capitalise every word in a string. Aliased to {{ capitaliseAll str }}
.
Usage : {{ capitalizeAll "neutralis maintains packages" }}
Result : Neutralis Maintains Packages
{{ center str spaces }}
Centres a string using a pre-defined (spaces
parameter) number of "invisible", non-breaking spaces.
Usage : {{ center "Neutralis" 3 }}
Result : Neutralis
{{ contains str substr }}
Checks if a substring is within a string.
Usage : {{ contains "tralis" "Neutralis" }}
Result : true
{{ ellipsis str limit }}
Truncates a string and appends an ellipsis character (…
).
Usage : {{ ellipsis "Neutralis 3" }}
Result : Neu…
{{ endsWith str suffix }}
Checks if a string ends with a suffix.
Usage : {{ endsWith "tralis" "Neutralis" }}
Result : true
{{ hyphenate str }}
Replaces the spaces within a string to hyphens.
Usage : {{ hyphenate "Neutralis maintains packages" }}
Result : Neutralis-maintains-packages
{{ isString var }}
Checks if a passed variable is a string or not.
Usage : {{ isString "Neutralis maintains packages" }}
Result : true
{{ lowercase str }}
Converts string to all lowercase variables. Aliased with {{ downcase str }}
.
Usage : {{ lowercase "Neutralis Maintains PACKAGES" }}
Result : neutralis maintains packages
{{ occurrences str substr}}
Counts the amount of occurrences of a substring within a string.
Usage : {{ occurrences "Neutralis" "Neu" }}
Result : 3
{{ prepend str substr}}
Prepends a substring to a string.
Usage : {{ prepend "tralis" "neu" }}
Result : neutralis
{{ plusify str }}
Replaces the spaces within a string to pluses.
Usage : {{ plusify "Neutralis maintains packages" }}
Result : Neutralis+maintains+packages
{{{{ raw }}}}
Prevents contents of block from being compiled/rendered.
Usage : {{{{raw}}}} {{neutralis}} {{{{/raw}}}}
Result : {{neutralis}}
{{ remove str substr }}
Remove all instances of a substring within a string.
Usage : {{ remove "Neutralis maintains packages and packages" "packages" }}
Result : Neutralis maintains and
{{ removeFirst str substr }}
Remove the first instance of a subtring within a string.
Usage : {{ removeFirst "Neutralis maintains packages and packages" }}
Result : Neutralis maintains and packages
{{ replace str substr replacement }}
Replace all instances of a substring within a string.
Usage : {{ replace "Neutralis maintains packages and packages" "packages" "pACKages" }}
Result : Neutralis maintains pACKages and pACKages
{{ replaceFirst str substr replacement }}
Replace the first instance of a subtring within a string.
Usage : {{ replaceFirst "Neutralis maintains packages and packages" "packages" "pACKages" }}
Result : Neutralis maintains pACKages and packages
{{ reverse str }}
Reverse a string.
Usage : {{ reverse "Neutralis" }}
Result : silartueN
{{ split str substr }}
Checks if a string starts with a prefix.
Usage : {{ split "Neutralis maintains packages and packages" "packages" }}
Result : TODO
{{ startsWith prefix str }}
Checks if a string starts with a prefix.
Usage : {{ startsWith "Neu" "Neutralis" }}
Result : true
{{ trim str }}
Trims whitespace from a string.
Usage : {{ trim " Neutralis " }}
Result : Neutralis
{{ trimLeft str }}
Trims whitespace from the start of a string.
Usage : {{ trimLeft " Neutralis " }}
Result : Neutralis
{{ trimRight str }}
Trims whitespace from the end of a string.
Usage : {{ trimRight " Neutralis " }}
Result : Neutralis
{{ truncate str limit }}
Truncate a string to a limit of characters, ending with an ellipsis (preserves compatibility with helpers/handlebars-helpers
).
Usage : {{ truncate "Neutralis maintains packages" 3 }}
Result : Neu…
{{ truncateWords str limit }}
Truncate a string to a limit of words, ending with an ellipsis (preserves compatibility with helpers/handlebars-helpers
).
Usage : {{ truncateWords "Neutralis maintains packages" 2 }}
Result : Neutralis maintains…
{{ uppercase str }}
Uppercase all characters within a string. Aliased with {{ upcase str }}
.
Usage : {{ uppercase "Neutralis Maintains PACKAGES" }}
Result : NEUTRALIS MAINTAINS PACKAGES
Acknowledgements
This package is licensed under the 3-Clause BSD licence. A copy of it can be found in the LICENSE
file in the root of the source repository and in the root of the package directory.