littoral-templates 0.4.0-rc.3 → 0.4.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/CHANGELOG.md CHANGED
@@ -5,11 +5,21 @@
5
5
  * Thunks returning a `Template` are now `Template`s as well.
6
6
  * The 3rd (Curried) argument of `indentWith`, and the 2nd (Curried) argument of `when` are now variadic.
7
7
  * The EOL style can be taken from the OS, using the asynchronous `setEOLStyleFromOS` function.
8
- The `asString` returns a string that uses that EOL style *exclusively*.
8
+ The `asString` function now returns a string that uses that EOL style *exclusively*.
9
9
  Multi-line strings inside a template are therefore now split on `/\r*\n/` rather than just `/\n/`, so that `asString` effectively normalizes EOL style.
10
10
  * The `withNewlineAppended` function has been renamed to `withEmptyLineAppended`.
11
11
  (The former is kept as a legacy alias.)
12
12
  * An object constant `commonIndentations` is added and exposed which holds the most common indentation styles: “2 spaces”, “4 spaces”, and “1 tab”.
13
+ * Updated the [README](./README.md) significantly!
14
+
15
+ *Note*: `asString` now behaves more consistently on EOLs, meaning that existing templates might behave differently, particularly when using multi-line strings (nested) inside templates.
16
+ (Also see the updated [README](./README.md).)
17
+ Specifically: it’s no longer necessary – or even useful/desirable – to have multi-line strings ending in a bare EOL in your template code, because you shouldn't expect the following to evaluate to `"foo\n"`:
18
+
19
+ ```javascript
20
+ asString([`foo
21
+ `])
22
+ ```
13
23
 
14
24
 
15
25
  ## 0.3.0
package/README.md CHANGED
@@ -39,6 +39,7 @@ console.log(
39
39
 
40
40
  The `indent` function is a function that takes one argument: the indentation level — let’s call that _n_.
41
41
  It then returns a *template function* that takes a template as its argument, and returns a template that is indented to indentation level _n_, using 2 spaces for each indentation.
42
+ (A _template function_ is any function that produces an instance of `Template`.)
42
43
  Defining the `indent` function uses the `indentWith` function.
43
44
 
44
45
  This code produces the following text on the JavaScript console:
@@ -136,9 +137,7 @@ An example of that would be to keep track of imports that have to appear before
136
137
 
137
138
  Other convenience functions are:
138
139
 
139
- * `withEmptyLineAppended`: Wrap this around a template function (see definition below) to produce a template function that adds an empty line after any item fed to the original template function.
140
-
141
- A _template function_ is any function that produces an instance of `Template`.
140
+ * `withEmptyLineAppended`: Wrap this around a template function to produce a template function that adds an empty line after any item fed to the original template function.
142
141
 
143
142
  An example of the usage of `withEmptyLineAppended` is
144
143
 
@@ -167,8 +166,8 @@ Other convenience functions are:
167
166
 
168
167
  ### EOLs
169
168
 
170
- EOLs – AKA “newlines” or “line endings” – vary between OS's: Windows uses `crlf` EOL style – `\r\n` –, while essentially all other mainstream OS's use `lf` style – `\n`.
171
- Not taking that into account can cause content being generated differently across OS's, potentially confusing tools like Git — especially if these are not configured correctly.
169
+ EOLs – AKA “newlines” or “line endings” – vary between OSs: Windows uses `crlf` EOL style – `\r\n` –, while essentially all other mainstream OSs use `lf` style – `\n`.
170
+ Not taking that into account can cause content being generated differently across OSs, potentially confusing tools like Git — especially if these are not configured correctly.
172
171
  Since generated content is often large, this causes additional confusion and friction in the software development process.
173
172
 
174
173
  To prevent such issues, you can set the EOL style by calling the `setEOLStyleFromOS` function before any calls to `asString`.
@@ -198,6 +197,8 @@ asString([`foo
198
197
  ```
199
198
 
200
199
  evaluates to `"foo<eol><eol>"`.
200
+ Because of this, it’s usually not a good idea to have multi-line strings ending with EOLs of their own in your template code.
201
+ Moreover, because multi-line strings break indentation, they’re probably not great to have anyway.
201
202
 
202
203
  Splitting is done on *EOLs of any style*, so this *effectively normalizes* EOLs, meaning that even if multi-line strings use different EOL, `asString` will only use the set EOL style.
203
204
 
@@ -207,7 +208,7 @@ Templates **compose** nicely, and predictably, e.g.:
207
208
  asString([t1, t2]) === `${asString(t1)}${asString(t2)}`
208
209
  ```
209
210
 
210
- The expression `asString([])` evaluates to the empty string, which both satisfies the property above, and is useful as a “nil” template that doesn't result in a new/empty line in the output.
211
+ The expression `asString([])` evaluates to the empty string, which both satisfies the property above, and is useful as a “nil” template that doesnt result in a new/empty line in the output.
211
212
 
212
213
 
213
214
  ## Package name
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "littoral-templates",
3
- "version": "0.4.0-rc.3",
3
+ "version": "0.4.0",
4
4
  "description": "A small JavaScript/TypeScript framework to do templating comfortably using the template literal syntax in either JavaScript or TypeScript.",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",
package/.editorconfig DELETED
@@ -1,9 +0,0 @@
1
- # Help: https://EditorConfig.org`
2
- root = true
3
-
4
- [*]
5
- charset = utf-8
6
- end_of_line = lf
7
- indent_style = space
8
- indent_size = 4
9
-