@fyno/handlebars_helpers

1.0.7 • Public • Published

Handlebars Helper Documentation

This documentation provides details and examples for each custom Handlebars helper defined in the provided code.

1. isArray

Checks if the provided context is an array.

Example:

{{#isArray myArray}}
  <!-- Code to execute if myArray is an array -->
{{else}}
  <!-- Code to execute if myArray is not an array -->
{{/isArray}}

2. formatDate

Formats a date according to the specified format, locale, and timezone.

Example:

{{formatDate "2023-01-01T12:00:00" "medium" "en-us" "+05:30"}}

3. formatDateTime

Formats a date and time according to the specified format, locale, and timezone.

Example:

{{formatDateTime "2023-01-01T12:00:00" "medium" "en-us" "+05:30"}}

4. remove

Removes specified strings from the input string.

Example:

{{remove "Hello, world!" "world"}}

5. isJSON

Checks if the provided context is a JSON object.

Example:

{{#isJSON myObject}}
  <!-- Code to execute if myObject is a JSON object -->
{{else}}
  <!-- Code to execute if myObject is not a JSON object -->
{{/isJSON}}

6. ifEquals

Conditionally executes code based on equality.

Example:

{{#ifEquals variable1 variable2}}
  <!-- Code to execute if variable1 equals variable2 -->
{{else}}
  <!-- Code to execute if variable1 does not equal variable2 -->
{{/ifEquals}}

7. stringify

Converts an object to as json string

Example:

{{stringify myObject}}

8. parse

Parses a JSON string into an object.

Example:

{{#parse jsonString}}
  <!-- Access properties of the parsed object -->
  {{property1}}
{{/parse}}

9. ifMatches

Checks if a string matches a regular expression.

Example:

{{#ifMatches myString "pattern"}}
  <!-- Code to execute if myString matches the pattern -->
{{else}}
  <!-- Code to execute if myString does not match the pattern -->
{{/ifMatches}}

10. raw-helper

Returns the raw content without rendering Handlebars expressions.

Example:

{{#raw-helper}}
  <p>This is raw HTML content: {{variable}}</p>
{{/raw-helper}}

11. isEmail

Checks if the provided string is a valid email address.

Example:

{{#isEmail "user@example.com"}}
  <!-- Code to execute if the email is valid -->
{{else}}
  <!-- Code to execute if the email is not valid -->
{{/isEmail}}

12. getNumberFromText

Extracts a number from the given text.

Example:

{{getNumberFromText "The price is $500"}}

13. default

Provides a default value if the key is falsy.

Example:

{{default myKey "Default Value"}}

14. ifStartsWith

Conditionally executes code based on whether a string starts with a specified prefix.

Example:

{{#ifStartsWith myString "prefix"}}
  <!-- Code to execute if myString starts with "prefix" -->
{{else}}
  <!-- Code to execute if myString does not start with "prefix" -->
{{/ifStartsWith}}

15. isExpo

Extracts the Expo token from a string if present.

Example:

{{isExpo "expo_token:ABC123"}}

16. isFCM

Extracts the FCM token from a string if present.

Example:

{{isFCM "fcm_token:XYZ789"}}

17. isOnesignal

Extracts Onesignal selector and token from a string if present.

Example:

{{#isOnesignal "onesignal_player_id:12345"}}
  <!-- Access properties: {{onesignal_selector}}, {{onesignal_token}} -->
{{else}}
  <!-- Code to execute if the string does not match Onesignal format -->
{{/isOnesignal}}

18. isEmpty

Checks if an object is empty.

Example:

{{#isEmpty myObject}}
  <!-- Code to execute if myObject is empty -->
{{else}}
  <!-- Code to execute if myObject is not empty -->
{{/isEmpty}}

19. setVariable

Sets a variable in the root context.

Example:

{{setVariable "myVar" "myValue"}}

20. pushCallback

Pushes callback information into the root context.

Example:

{{pushCallback}}

21. generateNotifyId

Generates a notification ID based on the provided key.

Example:

{{generateNotifyId "myKey"}}

22. dateDiff

Calculates the difference between two dates.

Example:

{{dateDiff "2023-01-01T12:00:00" "NOW" "days"}}

23. compare

Compares two values based on the specified operator.

Example:

{{#compare value1 "eq" value2}}
  <!-- Code to execute if value1 equals value2 -->
{{else}}
  <!-- Code to execute if value1 does not equal value2 -->
{{/compare}}

24. eq, ne, lt, gt, lte, gte, and, or

Logical comparison helpers.

Example:

{{#eq variable1 variable2}}
  <!-- Code to execute if variable1 equals variable2 -->
{{/eq}}

25. split

Splits a string into an array using a specified delimiter.

Example:

{{#split "apple,orange,banana" ","}}
  <!-- Access individual elements in the array -->
  {{this}}
{{/split}}

26. math

Performs basic arithmetic operations on two values.

Example:

{{math 10 "+" 5}}

27. relativeDay

Determines the relationship of a given date to the current date.

Example:

{{relativeDay "2023-01-01"}}

28. trim

Trims a string to a specified length and delimiter.

Example:

{{trim "This is a long string" 10 "..."}}

29. formatNumber

Formats a number using the specified locale.

Example:

{{formatNumber 1234567.89 "en-US"}}

Package Sidebar

Install

npm i @fyno/handlebars_helpers

Weekly Downloads

75

Version

1.0.7

License

MIT

Unpacked Size

205 kB

Total Files

19

Last publish

Collaborators

  • pranavbadami
  • saivinod
  • ashishag86
  • ashwin-agarwal