@budibase/string-templates 2.13.36 → 2.13.38

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
@@ -1,39 +1,42 @@
1
1
  # String templating
2
+
2
3
  This package provides a common system for string templating across the Budibase Builder, client and server.
3
4
  The templating is provided through the use of [Handlebars](https://handlebarsjs.com/) an extension of Mustache
4
- which is capable of carrying out logic. We have also extended the base Handlebars functionality through the use
5
+ which is capable of carrying out logic. We have also extended the base Handlebars functionality through the use
5
6
  of a set of helpers provided through the [handlebars-helpers](https://github.com/budibase/handlebars-helpers) package.
6
7
 
7
8
  We have not implemented all the helpers provided by the helpers package as some of them provide functionality
8
9
  we felt would not be beneficial. The following collections of helpers have been implemented:
9
- 1. [Math](https://github.com/budibase/handlebars-helpers/tree/master#math) - a set of useful helpers for
10
- carrying out logic pertaining to numbers e.g. `avg`, `add`, `abs` and so on.
10
+
11
+ 1. [Math](https://github.com/budibase/handlebars-helpers/tree/master#math) - a set of useful helpers for
12
+ carrying out logic pertaining to numbers e.g. `avg`, `add`, `abs` and so on.
11
13
  2. [Array](https://github.com/budibase/handlebars-helpers/tree/master#array) - some very specific helpers
12
- for use with arrays, useful for example in automations. Helpers like `first`, `last`, `after` and `join`
13
- can be useful for getting particular portions of arrays or turning them into strings.
14
+ for use with arrays, useful for example in automations. Helpers like `first`, `last`, `after` and `join`
15
+ can be useful for getting particular portions of arrays or turning them into strings.
14
16
  3. [Number](https://github.com/budibase/handlebars-helpers/tree/master#number) - unlike the math helpers these
15
- are useful for converting numbers into useful formats for display, e.g. `bytes`, `addCommas` and `toPrecision`.
17
+ are useful for converting numbers into useful formats for display, e.g. `bytes`, `addCommas` and `toPrecision`.
16
18
  4. [URL](https://github.com/budibase/handlebars-helpers/tree/master#url) - very specific helpers for dealing with URLs,
17
- such as `encodeURI`, `escape`, `stripQueryString` and `stripProtocol`. These are primarily useful
18
- for building up particular URLs to hit as say part of an automation.
19
- 5. [String](https://github.com/budibase/handlebars-helpers/tree/master#string) - these helpers are useful for building
20
- strings and preparing them for display, e.g. `append`, `camelcase`, `capitalize` and `ellipsis`.
21
- 6. [Comparison](https://github.com/budibase/handlebars-helpers/tree/master#comparison) - these helpers are mainly for
22
- building strings when particular conditions are met, for example `and`, `or`, `gt`, `lt`, `not` and so on. This is a very
23
- extensive set of helpers but is mostly as would be expected from a set of logical operators.
19
+ such as `encodeURI`, `escape`, `stripQueryString` and `stripProtocol`. These are primarily useful
20
+ for building up particular URLs to hit as say part of an automation.
21
+ 5. [String](https://github.com/budibase/handlebars-helpers/tree/master#string) - these helpers are useful for building
22
+ strings and preparing them for display, e.g. `append`, `camelcase`, `capitalize` and `ellipsis`.
23
+ 6. [Comparison](https://github.com/budibase/handlebars-helpers/tree/master#comparison) - these helpers are mainly for
24
+ building strings when particular conditions are met, for example `and`, `or`, `gt`, `lt`, `not` and so on. This is a very
25
+ extensive set of helpers but is mostly as would be expected from a set of logical operators.
24
26
  7. [Object](https://github.com/budibase/handlebars-helpers/tree/master#object) - useful operator for parsing objects, as well
25
- as converting them to JSON strings.
26
- 8. [Regex](https://github.com/budibase/handlebars-helpers/tree/master#regex) - allows performing regex tests on strings that
27
- can be used in conditional statements.
27
+ as converting them to JSON strings.
28
+ 8. [Regex](https://github.com/budibase/handlebars-helpers/tree/master#regex) - allows performing regex tests on strings that
29
+ can be used in conditional statements.
28
30
  9. [Date](https://github.com/helpers/helper-date) - last but certainly not least is a moment based date helper, which can
29
- format ISO/timestamp based dates into something human-readable. An example of this would be `{{date dateProperty "DD-MM-YYYY"}}`.
31
+ format ISO/timestamp based dates into something human-readable. An example of this would be `{{date dateProperty "DD-MM-YYYY"}}`.
30
32
 
31
33
  ## Date formatting
34
+
32
35
  This package uses the standard method for formatting date times, using the following syntax:
33
36
  | Input | Example | Description |
34
37
  | ----- | ------- | ----------- |
35
38
  | YYYY | 2014 | 4 or 2 digit year. Note: Only 4 digit can be parsed on strict mode |
36
- | YY | 14 | 2 digit year |
39
+ | YY | 14 | 2 digit year |
37
40
  | Y | -25 | Year with any number of digits and sign |
38
41
  | Q | 1..4 | Quarter of year. Sets month to first month in quarter. |
39
42
  | M MM | 1..12 | Month number |
@@ -42,55 +45,64 @@ This package uses the standard method for formatting date times, using the follo
42
45
  | Do | 1st..31st | Day of month with ordinal |
43
46
  | DDD DDDD | 1..365 | Day of year |
44
47
  | X | 1410715640.579 | Unix timestamp |
45
- | x | 1410715640579 | Unix ms timestamp |
48
+ | x | 1410715640579 | Unix ms timestamp |
46
49
 
47
50
  ## Template format
51
+
48
52
  There are two main ways that the templating system can be used, the first is very similar to that which
49
53
  would be produced by Mustache - a single statement:
54
+
50
55
  ```
51
56
  Hello I'm building a {{uppercase adjective}} string with Handlebars!
52
57
  ```
58
+
53
59
  In the statement above provided a context of `{adjective: "cool"}` will produce a string of `Hello I'm building a COOL string with Handlebars!`.
54
60
  Here we can see an example of how string helpers can be used to make a string exactly as we need it. These statements are relatively
55
61
  simple; we can also stack helpers as such: `{{ uppercase (remove string "bad") }}` with the use of parenthesis.
56
62
 
57
63
  The other type of statement that can be made with the templating system is conditional ones, that appear as such:
64
+
58
65
  ```
59
66
  Hello I'm building a {{ #gte score "50" }}Great{{ else }}Bad{{ /gte }} string with Handlebars!
60
- ```
61
- In this string we can see that the string `Great` or `Bad` will be inserted depending on the state of the
67
+ ```
68
+
69
+ In this string we can see that the string `Great` or `Bad` will be inserted depending on the state of the
62
70
  `score` context variable. The comparison, string and array helpers all provide some conditional operators which can be used
63
- in this way. There will also be some operators which will be built with a very similar syntax but will produce an
71
+ in this way. There will also be some operators which will be built with a very similar syntax but will produce an
64
72
  iterative operation, like a for each - an example of this would be the `forEach` array helper.
65
73
 
66
74
  ## Usage
67
- Usage of this templating package is through one of the primary functions provided by the package - these functions are
75
+
76
+ Usage of this templating package is through one of the primary functions provided by the package - these functions are
68
77
  as follows:
69
- 1. `processString` - `async (string, object)` - given a template string and a context object this will build a string
70
- using our pre-processors, post-processors and handlebars.
71
- 2. `processObject` - `async (object, object)` - carries out the functionality provided by `processString` for any string
72
- inside the given object. This will recurse deeply into the provided object so for very large objects this could be slow.
73
- 3. `processStringSync` - `(string, object)` - a reduced functionality processing of strings which is synchronous, like
74
- functions provided by Node (e.g. `readdirSync`)
78
+
79
+ 1. `processString` - `async (string, object)` - given a template string and a context object this will build a string
80
+ using our pre-processors, post-processors and handlebars.
81
+ 2. `processObject` - `async (object, object)` - carries out the functionality provided by `processString` for any string
82
+ inside the given object. This will recurse deeply into the provided object so for very large objects this could be slow.
83
+ 3. `processStringSync` - `(string, object)` - a reduced functionality processing of strings which is synchronous, like
84
+ functions provided by Node (e.g. `readdirSync`)
75
85
  4. `processObjectSync` - `(object, object)` - as with the sync'd string, recurses an object to process it synchronously.
76
- 5. `makePropSafe` - `(string)` - some properties cannot be handled by Handlebars, for example `Table 1` is not valid due
77
- to spaces found in the property name. This will update the property name to `[Table 1]` wrapping it in literal
78
- specifiers so that it is safe for use in Handlebars. Ideally this function should be called for every level of an object
79
- being accessed, for example `[Table 1].[property name]` is the syntax that is required for Handlebars.
86
+ 5. `makePropSafe` - `(string)` - some properties cannot be handled by Handlebars, for example `Table 1` is not valid due
87
+ to spaces found in the property name. This will update the property name to `[Table 1]` wrapping it in literal
88
+ specifiers so that it is safe for use in Handlebars. Ideally this function should be called for every level of an object
89
+ being accessed, for example `[Table 1].[property name]` is the syntax that is required for Handlebars.
80
90
  6. `isValid` - `(string)` - checks the given string for any templates and provides a boolean stating whether it is a valid
81
- template.
91
+ template.
82
92
  7. `getManifest` - returns the manifest JSON which has been generated for the helpers, describing them and their params.
83
93
 
84
94
  ## Development
95
+
85
96
  This library is built with [Rollup](https://rollupjs.org/guide/en/) as many of the packages built by Budibase are. We have
86
- built the string templating package as a UMD so that it can be used by Node and Browser based applications. This package also
87
- builds Typescript stubs which when making use of the library will be used by your IDE to provide code completion. The following
97
+ built the string templating package as a UMD so that it can be used by Node and Browser based applications. This package also
98
+ builds Typescript stubs which when making use of the library will be used by your IDE to provide code completion. The following
88
99
  commands are provided for development purposes:
100
+
89
101
  1. `yarn build` - will build the Typescript stubs and the bundle into the `dist` directory.
90
102
  2. `yarn test` - runs the test suite which will check various helpers are still functioning as
91
- expected and a few expected use cases.
92
- 3. `yarn dev:builder` - an internal command which is used by lerna to watch and build any changes
93
- to the package as part of the main `yarn dev` of the repo.
103
+ expected and a few expected use cases.
104
+ 3. `yarn dev` - an internal command which is used by lerna to watch and build any changes
105
+ to the package as part of the main `yarn dev` of the repo.
94
106
 
95
107
  It is also important to note this package is managed in the same manner as all other in the mono-repo,
96
- through lerna.
108
+ through lerna.