littoral-templates 0.4.0-rc.1 → 0.4.0-rc.3

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
@@ -4,6 +4,12 @@
4
4
 
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
+ * 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*.
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
+ * The `withNewlineAppended` function has been renamed to `withEmptyLineAppended`.
11
+ (The former is kept as a legacy alias.)
12
+ * An object constant `commonIndentations` is added and exposed which holds the most common indentation styles: “2 spaces”, “4 spaces”, and “1 tab”.
7
13
 
8
14
 
9
15
  ## 0.3.0
@@ -11,9 +17,8 @@
11
17
  * Turn the package into an ESM module (back again).
12
18
  (Should work with Deno in the meanwhile.)
13
19
  * Update dependencies: no impact on shipped code.
14
- * Add functions: `when`, `withNewlineAppended`, and `commaSeparated`.
15
- * Rename `NestedString` to `Template`, leaving `NestedString` as an alias.
16
- This is not a breaking change, but I might deprecate and remove `NestedString` in the future.
20
+ * Add functions: `when`, `withEmptyLineAppended`, and `commaSeparated`.
21
+ * Rename `NestedString` to `Template`, leaving `NestedString` as a legacy alias, which might be deprecated and removed in the future.
17
22
  * Add {T|J}SDoc.
18
23
 
19
24
 
package/README.md CHANGED
@@ -1,57 +1,73 @@
1
1
  # littoral-templates
2
2
 
3
- A small JavaScript/TypeScript framework to do templating comfortably using the [template literal](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Template_literals) syntax in either JavaScript or TypeScript.
4
- It doesn't come with its own syntax, like frameworks like [mustache](https://mustache.github.io/), and [handlebars](https://handlebarsjs.com/) do.
3
+ A small JavaScript/TypeScript framework to do light-weight templating – e.g. for doing code generation – comfortably using the [template literal](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Template_literals) syntax in either JavaScript or TypeScript.
5
4
 
6
- Instead, templates look as follows:
7
5
 
8
- ```typescript
6
+ ## Quickstart
7
+
8
+ `littoral-templates` doesn’t come with its own syntax, like frameworks like [mustache](https://mustache.github.io/), and [handlebars](https://handlebarsjs.com/) do.
9
+ Instead, templates are written as ordinary JavaScript/TypeScript code.
10
+ They look as follows:
11
+
12
+ ```javascript
9
13
  [
10
14
  `top-level`,
11
15
  [ `still top-level, but on a new line` ],
12
16
  indent(1)([
13
17
  `this is indented (1 level)`,
14
- indent(2)([
18
+ indent(2)(() => [
15
19
  `this is much more indented (3 levels)`
16
20
  ])
17
21
  ])
18
22
  ]
19
23
  ```
20
24
 
21
- Instances of the `Template` type are arrays of strings nested to an arbitrary depth/level.
22
- (Depth 0 corresponds to a single string).
23
- To convert this to a proper string, use the `asString` function, as follows:
25
+ Templates – i.e.: instances of the `Template` type are either strings, no-args functions returning a template, or arrays of templates.
26
+ This is a circular definition, so you can have nesting to an arbitrary depth/level.
27
+
28
+ To convert a template back to a proper string, use the **`asString`** function, as follows:
24
29
 
25
30
  ```typescript
26
- import {asString, indentWith} from "littoral-templates"
31
+ import {asString, commonIndentations, indentWith} from "littoral-templates"
27
32
 
28
- const indent = indentWith(" ")
33
+ const indent = indentWith(commonIndentations["2 spaces"])
29
34
 
30
35
  console.log(
31
36
  asString(<the template from the listing above>)
32
37
  )
33
38
  ```
34
39
 
40
+ The `indent` function is a function that takes one argument: the indentation level — let’s call that _n_.
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
+ Defining the `indent` function uses the `indentWith` function.
43
+
35
44
  This code produces the following text on the JavaScript console:
36
45
 
37
- ```
46
+ ```javascript
38
47
  top-level
39
48
  still top-level, but on a new line
40
- this is indented (1 level)
41
- this is even more indented (3 levels)
49
+ this is indented (1 level)
50
+ this is even more indented (3 levels)
42
51
  ```
43
52
 
53
+ This makes for a convenient way to generate code with correct indentation levels.
54
+
55
+ Be sure to check out the [cookbook](#cookbook) below to learn how to use `littoral-templates` for common templating tasks conveniently.
56
+ Read the [fundamentals](#fundamentals) below to learn more about the concepts underlying this package.
57
+
58
+
59
+ ## Cookbook
44
60
 
45
61
  ### Iterating over collections
46
62
 
47
- A common activity in templates is to iterate over a collection and map each item to text.
63
+ A common activity in code generation is to iterate over a collection and map each item to text.
48
64
  These sub-texts would then have to be joined together, and taking care of correct indentation is then usually quite a hassle.
49
65
  Using the `Template` type, you can simply use the `Array.map` function, as follows:
50
66
 
51
67
  ```typescript
52
68
  import {asString, indentWith} from "littoral-templates"
53
69
 
54
- const indent = indentWith(" ")
70
+ const indent = indentWith(commonIndentations["2 spaces"])
55
71
 
56
72
  console.log(
57
73
  asString([
@@ -112,7 +128,7 @@ const template = [
112
128
  ]
113
129
  ```
114
130
 
115
- Using side effects inside a template can be useful to store information that's needed elsewhere in the text-to-generate.
131
+ Using side effects inside a template can be useful to store information thats needed elsewhere in the text-to-generate.
116
132
  An example of that would be to keep track of imports that have to appear before their usage.
117
133
 
118
134
 
@@ -120,14 +136,14 @@ An example of that would be to keep track of imports that have to appear before
120
136
 
121
137
  Other convenience functions are:
122
138
 
123
- * `withNewlineAppended`: Wrap this around a template function (see definition below) to produce a template function that adds a newline after any item fed to the original template function.
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.
124
140
 
125
141
  A _template function_ is any function that produces an instance of `Template`.
126
142
 
127
- An example of the usage of `withNewlineAppended` is
143
+ An example of the usage of `withEmptyLineAppended` is
128
144
 
129
145
  ```typescript
130
- [1, 2, 3].map(withNewlineAppended((num) => `${num}`))
146
+ [1, 2, 3].map(withEmptyLineAppended((num) => `${num}`))
131
147
  ```
132
148
 
133
149
  which should produce the following text:
@@ -149,9 +165,54 @@ Other convenience functions are:
149
165
  _Note_ that this only works on a list of strings, not an any instance of `Template`.
150
166
 
151
167
 
152
- ### Package name
168
+ ### EOLs
169
+
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.
172
+ Since generated content is often large, this causes additional confusion and friction in the software development process.
173
+
174
+ To prevent such issues, you can set the EOL style by calling the `setEOLStyleFromOS` function before any calls to `asString`.
175
+ The default value for the EOL style is `lf` – meaning `\n`.
176
+ I’ll use the notation `<eol>` for the currently-set EOL value throughout the rest of the documentation.
177
+
178
+
179
+ ## Fundamentals
180
+
181
+ Templates are in essence *line-oriented*: each single-line string (containing no EOL of any style) inside a template – no matter how deeply nested it occurs – corresponds to one line after calling `asString`.
182
+ In code, all the following expressions result in a value of `"foo<eol>"` when calling `asString` with them:
183
+
184
+ ```javascript
185
+ "foo"
186
+ ["foo"]
187
+ [["foo"]]
188
+ () => ["foo"]
189
+ [() => ["foo"]]
190
+ ```
191
+
192
+ A multi-line string inside a template is split on EOL of any style, retaining the exact number of lines that it originally had.
193
+ So:
194
+
195
+ ```javascript
196
+ asString([`foo
197
+ `])
198
+ ```
199
+
200
+ evaluates to `"foo<eol><eol>"`.
201
+
202
+ 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
+ Templates **compose** nicely, and predictably, e.g.:
205
+
206
+ ```javascript
207
+ asString([t1, t2]) === `${asString(t1)}${asString(t2)}`
208
+ ```
209
+
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
+
212
+
213
+ ## Package name
153
214
 
154
- The repository's name is a play on "temporal literals" and "littoral", begin phonetically close to "literal".
155
- The latter word indicates the part of a body of water (lake, sea, or ocean) that's closest to shore, usually shallow, and possibly not always entirely submerged.
156
- The name tries to convey that implementing templates with this framework doesn't require you to "wade too far into the water".
215
+ The repositorys name is a play on temporal literals and littoral”, begin phonetically close to literal”.
216
+ The latter word indicates the part of a body of water (lake, sea, or ocean) thats closest to shore, usually shallow, and possibly not always entirely submerged.
217
+ The name tries to convey that implementing templates with this framework doesnt require you to wade too far into the water”.
157
218
 
package/dist/eol.d.ts ADDED
@@ -0,0 +1,29 @@
1
+ /**
2
+ * EOL-related constants and functions.
3
+ */
4
+ /**
5
+ * Common EOL styles.
6
+ */
7
+ export declare const eolStyles: {
8
+ readonly lf: "\n";
9
+ readonly crlf: "\r\n";
10
+ };
11
+ /**
12
+ * The value of the EOL string: typically, either "\n" (=LF-style, compatible with POSIX/Linux/macOS), or "\r\n" (=CRLF-style, compatible with Windows).
13
+ */
14
+ export declare let eol: string;
15
+ /**
16
+ * Sets the EOL to the OS-dependent value.
17
+ */
18
+ export declare const setEOLStyleFromOS: () => Promise<void>;
19
+ /**
20
+ * Sets the EOL explicitly to the given value.
21
+ * (This is especially useful for testing.)
22
+ */
23
+ export declare const setEOLExplicitly: (newEol: string) => void;
24
+ /**
25
+ * Splits the given string on EOLs (of any style) into an array of strings,
26
+ * each corresponding to one line.
27
+ */
28
+ export declare const splitOnEOL: (str: string) => string[];
29
+ //# sourceMappingURL=eol.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"eol.d.ts","sourceRoot":"","sources":["../src/eol.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH;;GAEG;AACH,eAAO,MAAM,SAAS;;;CAGZ,CAAA;AAGV;;GAEG;AACH,eAAO,IAAI,GAAG,EAAE,MAAqB,CAAA;AAGrC;;GAEG;AACH,eAAO,MAAM,iBAAiB,QAAa,QAAQ,IAAI,CAGjD,CAAA;AAGN;;;GAGG;AACH,eAAO,MAAM,gBAAgB,WAAY,MAAM,SAE9C,CAAA;AAKD;;;GAGG;AACH,eAAO,MAAM,UAAU,QAAS,MAAM,KAAG,MAAM,EACtB,CAAA"}
package/dist/eol.js ADDED
@@ -0,0 +1,81 @@
1
+ /**
2
+ * EOL-related constants and functions.
3
+ */
4
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
5
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
6
+ return new (P || (P = Promise))(function (resolve, reject) {
7
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
8
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
9
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
10
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
11
+ });
12
+ };
13
+ var __generator = (this && this.__generator) || function (thisArg, body) {
14
+ var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
15
+ return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
16
+ function verb(n) { return function (v) { return step([n, v]); }; }
17
+ function step(op) {
18
+ if (f) throw new TypeError("Generator is already executing.");
19
+ while (g && (g = 0, op[0] && (_ = 0)), _) try {
20
+ if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
21
+ if (y = 0, t) op = [op[0] & 2, t.value];
22
+ switch (op[0]) {
23
+ case 0: case 1: t = op; break;
24
+ case 4: _.label++; return { value: op[1], done: false };
25
+ case 5: _.label++; y = op[1]; op = [0]; continue;
26
+ case 7: op = _.ops.pop(); _.trys.pop(); continue;
27
+ default:
28
+ if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
29
+ if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
30
+ if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
31
+ if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
32
+ if (t[2]) _.ops.pop();
33
+ _.trys.pop(); continue;
34
+ }
35
+ op = body.call(thisArg, _);
36
+ } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
37
+ if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
38
+ }
39
+ };
40
+ /**
41
+ * Common EOL styles.
42
+ */
43
+ export var eolStyles = {
44
+ lf: "\n",
45
+ crlf: "\r\n"
46
+ };
47
+ /**
48
+ * The value of the EOL string: typically, either "\n" (=LF-style, compatible with POSIX/Linux/macOS), or "\r\n" (=CRLF-style, compatible with Windows).
49
+ */
50
+ export var eol = eolStyles.lf;
51
+ /**
52
+ * Sets the EOL to the OS-dependent value.
53
+ */
54
+ export var setEOLStyleFromOS = function () { return __awaiter(void 0, void 0, void 0, function () {
55
+ return __generator(this, function (_a) {
56
+ return [2 /*return*/, import("os").then(function (os) {
57
+ eol = os.EOL;
58
+ })
59
+ /**
60
+ * Sets the EOL explicitly to the given value.
61
+ * (This is especially useful for testing.)
62
+ */
63
+ ];
64
+ });
65
+ }); };
66
+ /**
67
+ * Sets the EOL explicitly to the given value.
68
+ * (This is especially useful for testing.)
69
+ */
70
+ export var setEOLExplicitly = function (newEol) {
71
+ eol = newEol;
72
+ };
73
+ var splitRegex = new RegExp(/\r*\n/);
74
+ /**
75
+ * Splits the given string on EOLs (of any style) into an array of strings,
76
+ * each corresponding to one line.
77
+ */
78
+ export var splitOnEOL = function (str) {
79
+ return str.split(splitRegex);
80
+ };
81
+ //# sourceMappingURL=eol.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"eol.js","sourceRoot":"","sources":["../src/eol.ts"],"names":[],"mappings":"AAAA;;GAEG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAEH;;GAEG;AACH,MAAM,CAAC,IAAM,SAAS,GAAG;IACrB,EAAE,EAAE,IAAI;IACR,IAAI,EAAE,MAAM;CACN,CAAA;AAGV;;GAEG;AACH,MAAM,CAAC,IAAI,GAAG,GAAW,SAAS,CAAC,EAAE,CAAA;AAGrC;;GAEG;AACH,MAAM,CAAC,IAAM,iBAAiB,GAAG;;QAC7B,sBAAA,MAAM,CAAC,IAAI,CAAC,CAAC,IAAI,CAAC,UAAC,EAAE;gBACjB,GAAG,GAAG,EAAE,CAAC,GAAG,CAAA;YAChB,CAAC,CAAC;YAGN;;;eAGG;UANG;;KAAA,CAAA;AAGN;;;GAGG;AACH,MAAM,CAAC,IAAM,gBAAgB,GAAG,UAAC,MAAc;IAC3C,GAAG,GAAG,MAAM,CAAA;AAChB,CAAC,CAAA;AAGD,IAAM,UAAU,GAAG,IAAI,MAAM,CAAC,OAAO,CAAC,CAAA;AAEtC;;;GAGG;AACH,MAAM,CAAC,IAAM,UAAU,GAAG,UAAC,GAAW;IAClC,OAAA,GAAG,CAAC,KAAK,CAAC,UAAU,CAAC;AAArB,CAAqB,CAAA"}
@@ -1,26 +1,7 @@
1
- import { Template } from "./types.js";
2
1
  /**
3
- * @returns {string} - the given template joined as one string, taking care of proper newline endings.
2
+ * Non-primitive functions on the {@link Template} type.
4
3
  */
5
- export declare const asString: (template: Template) => string;
6
- /**
7
- * @returns a function to instantiate a function to indent a sub-template.
8
- * The function always returns an array of strings.
9
- *
10
- * Its usage looks as follows:
11
- * <pre>
12
- * indentWith(" ")(2)([
13
- * `this is indented 2 levels`
14
- * ])
15
- * </pre>
16
- * Note that the third Curried argument is variadic, so the array brackets (`[]`) can be elided.
17
- *
18
- * Usually, one sets up the following function constant before:
19
- * <pre>
20
- * const indent = indentWith(" ")
21
- * </pre>
22
- */
23
- export declare const indentWith: (singleIndentation: string) => (indentLevel?: number) => (...templates: Template[]) => string[];
4
+ import { Template } from "./index-internal.js";
24
5
  /**
25
6
  * Allows for the following syntax:
26
7
  * <pre>
@@ -49,7 +30,12 @@ export declare const indentWith: (singleIndentation: string) => (indentLevel?: n
49
30
  */
50
31
  export declare const when: (bool: boolean) => (...whenResults: Template[]) => Template;
51
32
  /**
52
- * @return a function that composes the given template function with the action of "adding a newline after".
33
+ * @return a function that composes the given template function with the action of "adding an empty line after".
34
+ */
35
+ export declare const withEmptyLineAppended: <T>(templateFunc: (t: T) => Template) => (t: T) => Template[];
36
+ /**
37
+ * A legacy alias of {@link withEmptyLineAppended}.
38
+ * Note: this function might be deprecated and removed (per a major version) in the future.
53
39
  */
54
40
  export declare const withNewlineAppended: <T>(templateFunc: (t: T) => Template) => (t: T) => Template[];
55
41
  //# sourceMappingURL=functions.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"functions.d.ts","sourceRoot":"","sources":["../src/functions.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,QAAQ,EAAC,MAAM,YAAY,CAAA;AAkBnC;;GAEG;AACH,eAAO,MAAM,QAAQ,aAAc,QAAQ,KAAG,MACQ,CAAA;AAGtD;;;;;;;;;;;;;;;;GAgBG;AACH,eAAO,MAAM,UAAU,sBAAuB,MAAM,oBAClC,MAAM,oBAGM,QAAQ,EAAE,aAEnC,CAAA;AAGL;;;;;;;;;;;;;;;;;;;;;;;;;GAyBG;AACH,eAAO,MAAM,IAAI,SAAU,OAAO,sBAAqB,QAAQ,EAAE,KAAK,QAGnD,CAAA;AAGnB;;GAEG;AACH,eAAO,MAAM,mBAAmB,8BAA+B,QAAQ,yBACpC,CAAA"}
1
+ {"version":3,"file":"functions.d.ts","sourceRoot":"","sources":["../src/functions.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,EAAY,QAAQ,EAAC,MAAM,qBAAqB,CAAA;AAEvD;;;;;;;;;;;;;;;;;;;;;;;;;GAyBG;AACH,eAAO,MAAM,IAAI,SAAU,OAAO,sBAAqB,QAAQ,EAAE,KAAK,QAGnD,CAAA;AAGnB;;GAEG;AACH,eAAO,MAAM,qBAAqB,8BAA+B,QAAQ,yBACtC,CAAA;AAEnC;;;GAGG;AACH,eAAO,MAAM,mBAAmB,8BAPiC,QAAQ,yBAOjB,CAAA"}
package/dist/functions.js CHANGED
@@ -1,62 +1,7 @@
1
- var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
2
- if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
3
- if (ar || !(i in from)) {
4
- if (!ar) ar = Array.prototype.slice.call(from, 0, i);
5
- ar[i] = from[i];
6
- }
7
- }
8
- return to.concat(ar || Array.prototype.slice.call(from));
9
- };
10
- import { repeat, withNewlineEnsured } from "./string-utils.js";
11
1
  /**
12
- * “Flattens” the given template to an array of strings, each of which represent exactly one line.
13
- */
14
- var flatten = function (template) {
15
- if (typeof template === "function") {
16
- return flatten(template());
17
- }
18
- if (Array.isArray(template)) {
19
- return template.map(flatten).reduce(function (arrL, arrR) { return __spreadArray(__spreadArray([], arrL, true), arrR, true); }, []);
20
- }
21
- return template.split("\n");
22
- };
23
- /**
24
- * @returns {string} - the given template joined as one string, taking care of proper newline endings.
25
- */
26
- export var asString = function (template) {
27
- return flatten(template).map(withNewlineEnsured).join("");
28
- };
29
- /**
30
- * @returns a function to instantiate a function to indent a sub-template.
31
- * The function always returns an array of strings.
32
- *
33
- * Its usage looks as follows:
34
- * <pre>
35
- * indentWith(" ")(2)([
36
- * `this is indented 2 levels`
37
- * ])
38
- * </pre>
39
- * Note that the third Curried argument is variadic, so the array brackets (`[]`) can be elided.
40
- *
41
- * Usually, one sets up the following function constant before:
42
- * <pre>
43
- * const indent = indentWith(" ")
44
- * </pre>
2
+ * Non-primitive functions on the {@link Template} type.
45
3
  */
46
- export var indentWith = function (singleIndentation) {
47
- return function (indentLevel) {
48
- if (indentLevel === void 0) { indentLevel = 1; }
49
- var prefix = repeat(singleIndentation, indentLevel);
50
- var indenter = function (line) { return line.length > 0 ? (prefix + line) : line; };
51
- return function () {
52
- var templates = [];
53
- for (var _i = 0; _i < arguments.length; _i++) {
54
- templates[_i] = arguments[_i];
55
- }
56
- return flatten(templates).map(indenter);
57
- }; // Note: Template[] has type Template as well!
58
- };
59
- };
4
+ import { flattened } from "./index-internal.js";
60
5
  /**
61
6
  * Allows for the following syntax:
62
7
  * <pre>
@@ -90,14 +35,19 @@ export var when = function (bool) {
90
35
  for (var _i = 0; _i < arguments.length; _i++) {
91
36
  whenResults[_i] = arguments[_i];
92
37
  }
93
- return flatten(whenResults);
38
+ return flattened(whenResults);
94
39
  } // (need to be explicit here, or it doesn't work – despite having specified the return type...)
95
40
  : function (_) { return []; };
96
41
  };
97
42
  /**
98
- * @return a function that composes the given template function with the action of "adding a newline after".
43
+ * @return a function that composes the given template function with the action of "adding an empty line after".
99
44
  */
100
- export var withNewlineAppended = function (templateFunc) {
45
+ export var withEmptyLineAppended = function (templateFunc) {
101
46
  return function (t) { return [templateFunc(t), ""]; };
102
47
  };
48
+ /**
49
+ * A legacy alias of {@link withEmptyLineAppended}.
50
+ * Note: this function might be deprecated and removed (per a major version) in the future.
51
+ */
52
+ export var withNewlineAppended = withEmptyLineAppended;
103
53
  //# sourceMappingURL=functions.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"functions.js","sourceRoot":"","sources":["../src/functions.ts"],"names":[],"mappings":";;;;;;;;;AACA,OAAO,EAAC,MAAM,EAAE,kBAAkB,EAAC,MAAM,mBAAmB,CAAA;AAG5D;;GAEG;AACH,IAAM,OAAO,GAAG,UAAC,QAAkB;IAC/B,IAAI,OAAO,QAAQ,KAAK,UAAU,EAAE,CAAC;QACjC,OAAO,OAAO,CAAC,QAAQ,EAAE,CAAC,CAAA;IAC9B,CAAC;IACD,IAAI,KAAK,CAAC,OAAO,CAAC,QAAQ,CAAC,EAAE,CAAC;QAC1B,OAAO,QAAQ,CAAC,GAAG,CAAC,OAAO,CAAC,CAAC,MAAM,CAAC,UAAC,IAAI,EAAE,IAAI,IAAK,uCAAI,IAAI,SAAK,IAAI,SAAjB,CAAkB,EAAE,EAAE,CAAC,CAAA;IAC/E,CAAC;IACD,OAAO,QAAQ,CAAC,KAAK,CAAC,IAAI,CAAC,CAAA;AAC/B,CAAC,CAAA;AAGD;;GAEG;AACH,MAAM,CAAC,IAAM,QAAQ,GAAG,UAAC,QAAkB;IACvC,OAAA,OAAO,CAAC,QAAQ,CAAC,CAAC,GAAG,CAAC,kBAAkB,CAAC,CAAC,IAAI,CAAC,EAAE,CAAC;AAAlD,CAAkD,CAAA;AAGtD;;;;;;;;;;;;;;;;GAgBG;AACH,MAAM,CAAC,IAAM,UAAU,GAAG,UAAC,iBAAyB;IAChD,OAAA,UAAC,WAAuB;QAAvB,4BAAA,EAAA,eAAuB;QACpB,IAAM,MAAM,GAAG,MAAM,CAAC,iBAAiB,EAAE,WAAW,CAAC,CAAA;QACrD,IAAM,QAAQ,GAAG,UAAC,IAAY,IAAK,OAAA,IAAI,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC,MAAM,GAAG,IAAI,CAAC,CAAC,CAAC,CAAC,IAAI,EAAxC,CAAwC,CAAA;QAC3E,OAAO;YAAC,mBAAwB;iBAAxB,UAAwB,EAAxB,qBAAwB,EAAxB,IAAwB;gBAAxB,8BAAwB;;YAC5B,OAAA,OAAO,CAAC,SAAS,CAAC,CAAC,GAAG,CAAC,QAAQ,CAAC;QAAhC,CAAgC,CAAA,CAAI,8CAA8C;IAC1F,CAAC;AALD,CAKC,CAAA;AAGL;;;;;;;;;;;;;;;;;;;;;;;;;GAyBG;AACH,MAAM,CAAC,IAAM,IAAI,GAAG,UAAC,IAAa;IAC9B,OAAA,IAAI;QACA,CAAC,CAAC;YAAC,qBAA0B;iBAA1B,UAA0B,EAA1B,qBAA0B,EAA1B,IAA0B;gBAA1B,gCAA0B;;YAAK,OAAA,OAAO,CAAC,WAAW,CAAC;QAApB,CAAoB,CAAE,+FAA+F;QACvJ,CAAC,CAAC,UAAC,CAAC,IAAK,OAAA,EAAE,EAAF,CAAE;AAFf,CAEe,CAAA;AAGnB;;GAEG;AACH,MAAM,CAAC,IAAM,mBAAmB,GAAG,UAAI,YAAgC;IACnE,OAAA,UAAC,CAAI,IAAK,OAAA,CAAC,YAAY,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,EAArB,CAAqB;AAA/B,CAA+B,CAAA"}
1
+ {"version":3,"file":"functions.js","sourceRoot":"","sources":["../src/functions.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,EAAC,SAAS,EAAW,MAAM,qBAAqB,CAAA;AAEvD;;;;;;;;;;;;;;;;;;;;;;;;;GAyBG;AACH,MAAM,CAAC,IAAM,IAAI,GAAG,UAAC,IAAa;IAC9B,OAAA,IAAI;QACA,CAAC,CAAC;YAAC,qBAA0B;iBAA1B,UAA0B,EAA1B,qBAA0B,EAA1B,IAA0B;gBAA1B,gCAA0B;;YAAK,OAAA,SAAS,CAAC,WAAW,CAAC;QAAtB,CAAsB,CAAE,+FAA+F;QACzJ,CAAC,CAAC,UAAC,CAAC,IAAK,OAAA,EAAE,EAAF,CAAE;AAFf,CAEe,CAAA;AAGnB;;GAEG;AACH,MAAM,CAAC,IAAM,qBAAqB,GAAG,UAAI,YAAgC;IACrE,OAAA,UAAC,CAAI,IAAK,OAAA,CAAC,YAAY,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,EAArB,CAAqB;AAA/B,CAA+B,CAAA;AAEnC;;;GAGG;AACH,MAAM,CAAC,IAAM,mBAAmB,GAAG,qBAAqB,CAAA"}
@@ -0,0 +1,38 @@
1
+ /**
2
+ * Indentation-related constants and functions.
3
+ */
4
+ import { Template } from "./index-internal.js";
5
+ /**
6
+ * @returns a function to instantiate a function to indent a sub-template.
7
+ * The function always returns an array of strings.
8
+ *
9
+ * Its usage looks as follows:
10
+ * <pre>
11
+ * indentWith(" ")(2)([
12
+ * `this is indented 2 levels`
13
+ * ])
14
+ * </pre>
15
+ * Note that the third Curried argument is variadic, so the array brackets (`[]`) can be elided.
16
+ *
17
+ * Usually, one sets up the following function constant before:
18
+ * <pre>
19
+ * const indent = indentWith(" ")
20
+ * </pre>
21
+ */
22
+ export declare const indentWith: (singleIndentation: string) => (indentLevel?: number) => (...templates: Template[]) => string[];
23
+ /**
24
+ * An enumeration of common indentation styles.
25
+ * Use these in a type-safe way as follows, e.g. for “1 tab”:
26
+ *
27
+ * ```
28
+ * const indent = indentWith(commonIndentations["1 tab"])
29
+ *
30
+ * indent([`foo`])
31
+ * ```
32
+ */
33
+ export declare const commonIndentations: {
34
+ readonly "2 spaces": " ";
35
+ readonly "4 spaces": " ";
36
+ readonly "1 tab": "\t";
37
+ };
38
+ //# sourceMappingURL=indents.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"indents.d.ts","sourceRoot":"","sources":["../src/indents.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,EAAoB,QAAQ,EAAC,MAAM,qBAAqB,CAAA;AAE/D;;;;;;;;;;;;;;;;GAgBG;AACH,eAAO,MAAM,UAAU,sBAAuB,MAAM,oBAClC,MAAM,oBAGM,QAAQ,EAAE,aAEnC,CAAA;AAEL;;;;;;;;;GASG;AACH,eAAO,MAAM,kBAAkB;;;;CAIrB,CAAA"}
@@ -0,0 +1,51 @@
1
+ /**
2
+ * Indentation-related constants and functions.
3
+ */
4
+ import { flattened, repeat } from "./index-internal.js";
5
+ /**
6
+ * @returns a function to instantiate a function to indent a sub-template.
7
+ * The function always returns an array of strings.
8
+ *
9
+ * Its usage looks as follows:
10
+ * <pre>
11
+ * indentWith(" ")(2)([
12
+ * `this is indented 2 levels`
13
+ * ])
14
+ * </pre>
15
+ * Note that the third Curried argument is variadic, so the array brackets (`[]`) can be elided.
16
+ *
17
+ * Usually, one sets up the following function constant before:
18
+ * <pre>
19
+ * const indent = indentWith(" ")
20
+ * </pre>
21
+ */
22
+ export var indentWith = function (singleIndentation) {
23
+ return function (indentLevel) {
24
+ if (indentLevel === void 0) { indentLevel = 1; }
25
+ var prefix = repeat(singleIndentation, indentLevel);
26
+ var indenter = function (line) { return line.length > 0 ? (prefix + line) : line; };
27
+ return function () {
28
+ var templates = [];
29
+ for (var _i = 0; _i < arguments.length; _i++) {
30
+ templates[_i] = arguments[_i];
31
+ }
32
+ return flattened(templates).map(indenter);
33
+ }; // Note: Template[] has type Template as well!
34
+ };
35
+ };
36
+ /**
37
+ * An enumeration of common indentation styles.
38
+ * Use these in a type-safe way as follows, e.g. for “1 tab”:
39
+ *
40
+ * ```
41
+ * const indent = indentWith(commonIndentations["1 tab"])
42
+ *
43
+ * indent([`foo`])
44
+ * ```
45
+ */
46
+ export var commonIndentations = {
47
+ "2 spaces": " ",
48
+ "4 spaces": " ",
49
+ "1 tab": "\t"
50
+ };
51
+ //# sourceMappingURL=indents.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"indents.js","sourceRoot":"","sources":["../src/indents.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,EAAC,SAAS,EAAE,MAAM,EAAW,MAAM,qBAAqB,CAAA;AAE/D;;;;;;;;;;;;;;;;GAgBG;AACH,MAAM,CAAC,IAAM,UAAU,GAAG,UAAC,iBAAyB;IAChD,OAAA,UAAC,WAAuB;QAAvB,4BAAA,EAAA,eAAuB;QACpB,IAAM,MAAM,GAAG,MAAM,CAAC,iBAAiB,EAAE,WAAW,CAAC,CAAA;QACrD,IAAM,QAAQ,GAAG,UAAC,IAAY,IAAK,OAAA,IAAI,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC,MAAM,GAAG,IAAI,CAAC,CAAC,CAAC,CAAC,IAAI,EAAxC,CAAwC,CAAA;QAC3E,OAAO;YAAC,mBAAwB;iBAAxB,UAAwB,EAAxB,qBAAwB,EAAxB,IAAwB;gBAAxB,8BAAwB;;YAC5B,OAAA,SAAS,CAAC,SAAS,CAAC,CAAC,GAAG,CAAC,QAAQ,CAAC;QAAlC,CAAkC,CAAA,CAAI,8CAA8C;IAC5F,CAAC;AALD,CAKC,CAAA;AAEL;;;;;;;;;GASG;AACH,MAAM,CAAC,IAAM,kBAAkB,GAAG;IAC9B,UAAU,EAAE,IAAI;IAChB,UAAU,EAAE,MAAM;IAClB,OAAO,EAAE,IAAI;CACP,CAAA"}
@@ -0,0 +1,15 @@
1
+ export * from "./eol.js";
2
+ export * from "./functions.js";
3
+ export * from "./indents.js";
4
+ export * from "./primitives.js";
5
+ export * from "./strings.js";
6
+ export * from "./types.js";
7
+ /**
8
+ * To avoid problems with circular dependencies between JavaScript – i.e.: transpiled TypeScript – files,
9
+ * members in any .ts file *must* be imported through this index-internal.ts, e.g.:
10
+ *
11
+ * `import {asString} from "./index-internal.js"`
12
+ *
13
+ * (Mind the .js extension!)
14
+ */
15
+ //# sourceMappingURL=index-internal.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index-internal.d.ts","sourceRoot":"","sources":["../src/index-internal.ts"],"names":[],"mappings":"AAAA,cAAc,UAAU,CAAA;AACxB,cAAc,gBAAgB,CAAA;AAC9B,cAAc,cAAc,CAAA;AAC5B,cAAc,iBAAiB,CAAA;AAC/B,cAAc,cAAc,CAAA;AAC5B,cAAc,YAAY,CAAA;AAE1B;;;;;;;GAOG"}
@@ -0,0 +1,15 @@
1
+ export * from "./eol.js";
2
+ export * from "./functions.js";
3
+ export * from "./indents.js";
4
+ export * from "./primitives.js";
5
+ export * from "./strings.js";
6
+ export * from "./types.js";
7
+ /**
8
+ * To avoid problems with circular dependencies between JavaScript – i.e.: transpiled TypeScript – files,
9
+ * members in any .ts file *must* be imported through this index-internal.ts, e.g.:
10
+ *
11
+ * `import {asString} from "./index-internal.js"`
12
+ *
13
+ * (Mind the .js extension!)
14
+ */
15
+ //# sourceMappingURL=index-internal.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index-internal.js","sourceRoot":"","sources":["../src/index-internal.ts"],"names":[],"mappings":"AAAA,cAAc,UAAU,CAAA;AACxB,cAAc,gBAAgB,CAAA;AAC9B,cAAc,cAAc,CAAA;AAC5B,cAAc,iBAAiB,CAAA;AAC/B,cAAc,cAAc,CAAA;AAC5B,cAAc,YAAY,CAAA;AAE1B;;;;;;;GAOG"}
package/dist/index.d.ts CHANGED
@@ -1,4 +1,3 @@
1
- export { Template, NestedString } from "./types.js";
2
- export { asString, indentWith, when, withNewlineAppended } from "./functions.js";
3
- export { commaSeparated } from "./string-utils.js";
1
+ export { asString, commaSeparated, commonIndentations, indentWith, setEOLStyleFromOS, when, withEmptyLineAppended, withNewlineAppended } from "./index-internal.js";
2
+ export type { Template, NestedString } from "./index-internal.js";
4
3
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,QAAQ,EAAE,YAAY,EAAC,MAAM,YAAY,CAAA;AACjD,OAAO,EAAC,QAAQ,EAAE,UAAU,EAAE,IAAI,EAAE,mBAAmB,EAAC,MAAM,gBAAgB,CAAA;AAC9E,OAAO,EAAC,cAAc,EAAC,MAAM,mBAAmB,CAAA"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACH,QAAQ,EACR,cAAc,EACd,kBAAkB,EAClB,UAAU,EACV,iBAAiB,EACjB,IAAI,EACJ,qBAAqB,EACrB,mBAAmB,EACtB,MAAM,qBAAqB,CAAA;AAC5B,YAAY,EACR,QAAQ,EACR,YAAY,EACf,MAAM,qBAAqB,CAAA"}
package/dist/index.js CHANGED
@@ -1,3 +1,3 @@
1
- export { asString, indentWith, when, withNewlineAppended } from "./functions.js";
2
- export { commaSeparated } from "./string-utils.js";
1
+ export { asString, commaSeparated, commonIndentations, indentWith, setEOLStyleFromOS, when, withEmptyLineAppended, withNewlineAppended // (legacy alias)
2
+ } from "./index-internal.js";
3
3
  //# sourceMappingURL=index.js.map
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AACA,OAAO,EAAC,QAAQ,EAAE,UAAU,EAAE,IAAI,EAAE,mBAAmB,EAAC,MAAM,gBAAgB,CAAA;AAC9E,OAAO,EAAC,cAAc,EAAC,MAAM,mBAAmB,CAAA"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACH,QAAQ,EACR,cAAc,EACd,kBAAkB,EAClB,UAAU,EACV,iBAAiB,EACjB,IAAI,EACJ,qBAAqB,EACrB,mBAAmB,CAAK,iBAAiB;EAC5C,MAAM,qBAAqB,CAAA"}
@@ -0,0 +1,14 @@
1
+ /**
2
+ * Primitive functions on the {@link Template} type.
3
+ */
4
+ import { Template } from "./index-internal.js";
5
+ /**
6
+ * “Flattens” the given template to an array of strings, each of which represent exactly one line.
7
+ * Note: doesn't need to be exposed.
8
+ */
9
+ export declare const flattened: (template: Template) => string[];
10
+ /**
11
+ * @returns {string} - the given template joined as one string, taking care of proper EOLs.
12
+ */
13
+ export declare const asString: (template: Template) => string;
14
+ //# sourceMappingURL=primitives.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"primitives.d.ts","sourceRoot":"","sources":["../src/primitives.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,EAAM,QAAQ,EAAC,MAAM,qBAAqB,CAAA;AAIjD;;;GAGG;AACH,eAAO,MAAM,SAAS,aAAc,QAAQ,KAAG,MAAM,EAQpD,CAAA;AAGD;;GAEG;AACH,eAAO,MAAM,QAAQ,aAAc,QAAQ,KAAG,MACY,CAAA"}
@@ -0,0 +1,34 @@
1
+ /**
2
+ * Primitive functions on the {@link Template} type.
3
+ */
4
+ var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
5
+ if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
6
+ if (ar || !(i in from)) {
7
+ if (!ar) ar = Array.prototype.slice.call(from, 0, i);
8
+ ar[i] = from[i];
9
+ }
10
+ }
11
+ return to.concat(ar || Array.prototype.slice.call(from));
12
+ };
13
+ import { eol } from "./index-internal.js";
14
+ var eolRegex = new RegExp(/\r*\n/);
15
+ /**
16
+ * “Flattens” the given template to an array of strings, each of which represent exactly one line.
17
+ * Note: doesn't need to be exposed.
18
+ */
19
+ export var flattened = function (template) {
20
+ if (typeof template === "function") {
21
+ return flattened(template());
22
+ }
23
+ if (Array.isArray(template)) {
24
+ return template.map(flattened).reduce(function (arrL, arrR) { return __spreadArray(__spreadArray([], arrL, true), arrR, true); }, []);
25
+ }
26
+ return template.split(eolRegex);
27
+ };
28
+ /**
29
+ * @returns {string} - the given template joined as one string, taking care of proper EOLs.
30
+ */
31
+ export var asString = function (template) {
32
+ return flattened(template).map(function (line) { return line + eol; }).join("");
33
+ };
34
+ //# sourceMappingURL=primitives.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"primitives.js","sourceRoot":"","sources":["../src/primitives.ts"],"names":[],"mappings":"AAAA;;GAEG;;;;;;;;;;AAEH,OAAO,EAAC,GAAG,EAAW,MAAM,qBAAqB,CAAA;AAEjD,IAAM,QAAQ,GAAG,IAAI,MAAM,CAAC,OAAO,CAAC,CAAA;AAEpC;;;GAGG;AACH,MAAM,CAAC,IAAM,SAAS,GAAG,UAAC,QAAkB;IACxC,IAAI,OAAO,QAAQ,KAAK,UAAU,EAAE,CAAC;QACjC,OAAO,SAAS,CAAC,QAAQ,EAAE,CAAC,CAAA;IAChC,CAAC;IACD,IAAI,KAAK,CAAC,OAAO,CAAC,QAAQ,CAAC,EAAE,CAAC;QAC1B,OAAO,QAAQ,CAAC,GAAG,CAAC,SAAS,CAAC,CAAC,MAAM,CAAC,UAAC,IAAI,EAAE,IAAI,IAAK,uCAAI,IAAI,SAAK,IAAI,SAAjB,CAAkB,EAAE,EAAE,CAAC,CAAA;IACjF,CAAC;IACD,OAAO,QAAQ,CAAC,KAAK,CAAC,QAAQ,CAAC,CAAA;AACnC,CAAC,CAAA;AAGD;;GAEG;AACH,MAAM,CAAC,IAAM,QAAQ,GAAG,UAAC,QAAkB;IACvC,OAAA,SAAS,CAAC,QAAQ,CAAC,CAAC,GAAG,CAAC,UAAC,IAAI,IAAK,OAAA,IAAI,GAAG,GAAG,EAAV,CAAU,CAAC,CAAC,IAAI,CAAC,EAAE,CAAC;AAAtD,CAAsD,CAAA"}
@@ -1,13 +1,14 @@
1
+ /**
2
+ * Purely string-related functions.
3
+ */
1
4
  /**
2
5
  * @return the given array of strings but with commas added after each string except the last one.
3
6
  */
4
7
  export declare const commaSeparated: (strings: string[]) => string[];
5
8
  /**
6
9
  * Polyfill/shim for ES2015's String.prototype.repeat which doesn't work for some reason in the test...
10
+ * (Implementation uses the binary representation of n.)
11
+ * Note: doesn't need to be exposed.
7
12
  */
8
13
  export declare const repeat: (str: string, n: number) => string;
9
- /**
10
- * Ensures that the given string ends with a newline (`\n`), adding one if necessary.
11
- */
12
- export declare const withNewlineEnsured: (str: string) => string;
13
- //# sourceMappingURL=string-utils.d.ts.map
14
+ //# sourceMappingURL=strings.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"strings.d.ts","sourceRoot":"","sources":["../src/strings.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH;;GAEG;AACH,eAAO,MAAM,cAAc,YAAa,MAAM,EAAE,aACiC,CAAA;AAEjF;;;;GAIG;AACH,eAAO,MAAM,MAAM,QAAS,MAAM,KAAK,MAAM,KAAG,MAY/C,CAAA"}
@@ -1,3 +1,6 @@
1
+ /**
2
+ * Purely string-related functions.
3
+ */
1
4
  /**
2
5
  * @return the given array of strings but with commas added after each string except the last one.
3
6
  */
@@ -6,6 +9,8 @@ export var commaSeparated = function (strings) {
6
9
  };
7
10
  /**
8
11
  * Polyfill/shim for ES2015's String.prototype.repeat which doesn't work for some reason in the test...
12
+ * (Implementation uses the binary representation of n.)
13
+ * Note: doesn't need to be exposed.
9
14
  */
10
15
  export var repeat = function (str, n) {
11
16
  var result = "";
@@ -20,12 +25,5 @@ export var repeat = function (str, n) {
20
25
  }
21
26
  return result;
22
27
  };
23
- /**
24
- * Ensures that the given string ends with a newline (`\n`), adding one if necessary.
25
- */
26
- export var withNewlineEnsured = function (str) {
27
- return str.charAt(str.length - 1) === '\n'
28
- ? str
29
- : (str + "\n");
30
- };
31
- //# sourceMappingURL=string-utils.js.map
28
+ // TODO more common string utils, e.g. withFirst{Upper|Lower}, etc.
29
+ //# sourceMappingURL=strings.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"strings.js","sourceRoot":"","sources":["../src/strings.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH;;GAEG;AACH,MAAM,CAAC,IAAM,cAAc,GAAG,UAAC,OAAiB;IAC5C,OAAA,OAAO,CAAC,GAAG,CAAC,UAAC,GAAG,EAAE,KAAK,IAAK,OAAA,UAAG,GAAG,SAAG,KAAK,GAAG,CAAC,GAAG,OAAO,CAAC,MAAM,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,CAAE,EAAhD,CAAgD,CAAC;AAA7E,CAA6E,CAAA;AAEjF;;;;GAIG;AACH,MAAM,CAAC,IAAM,MAAM,GAAG,UAAC,GAAW,EAAE,CAAS;IACzC,IAAI,MAAM,GAAG,EAAE,CAAA;IACf,OAAO,CAAC,GAAG,CAAC,EAAE,CAAC;QACX,IAAI,CAAC,GAAG,CAAC,KAAK,CAAC,EAAE,CAAC;YACd,MAAM,IAAI,GAAG,CAAA;QACjB,CAAC;QACD,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC;YACR,GAAG,IAAI,GAAG,CAAA;QACd,CAAC;QACD,CAAC,KAAK,CAAC,CAAA;IACX,CAAC;IACD,OAAO,MAAM,CAAA;AACjB,CAAC,CAAA;AAGD,oEAAoE"}
package/dist/types.d.ts CHANGED
@@ -1,12 +1,15 @@
1
+ /**
2
+ * Types for templates.
3
+ */
1
4
  /**
2
5
  * A type definition for “templates” that consist of a string, or an array of templates, or a thunk returning a template.
3
6
  * Note that nesting can occur to arbitrary (finite) depth.
4
7
  *
5
8
  * @since version 0.3.0
6
9
  */
7
- export type Template = string | Array<Template> | (() => Template);
10
+ export type Template = string | (() => Template) | Array<Template>;
8
11
  /**
9
- * An alias for the {@link Template} type definition.
12
+ * Legacy alias for the {@link Template} type definition.
10
13
  * Note: this type might be deprecated and removed (per a major version) in the future.
11
14
  */
12
15
  export type NestedString = Template;
@@ -1 +1 @@
1
- {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AACH,MAAM,MAAM,QAAQ,GAAG,MAAM,GAAG,KAAK,CAAC,QAAQ,CAAC,GAAG,CAAC,MAAM,QAAQ,CAAC,CAAA;AAElE;;;GAGG;AACH,MAAM,MAAM,YAAY,GAAG,QAAQ,CAAA"}
1
+ {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH;;;;;GAKG;AACH,MAAM,MAAM,QAAQ,GAAG,MAAM,GAAG,CAAC,MAAM,QAAQ,CAAC,GAAG,KAAK,CAAC,QAAQ,CAAC,CAAA;AAElE;;;GAGG;AACH,MAAM,MAAM,YAAY,GAAG,QAAQ,CAAA"}
package/dist/types.js CHANGED
@@ -1,2 +1,5 @@
1
+ /**
2
+ * Types for templates.
3
+ */
1
4
  export {};
2
5
  //# sourceMappingURL=types.js.map
package/dist/types.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"types.js","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":""}
1
+ {"version":3,"file":"types.js","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA;;GAEG"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "littoral-templates",
3
- "version": "0.4.0-rc.1",
3
+ "version": "0.4.0-rc.3",
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",
@@ -13,10 +13,12 @@
13
13
  "test": "mocha dist/test/*.js",
14
14
  "watch-test": "mocha --watch dist/test/*.js",
15
15
  "lint": "eslint src",
16
- "pre-release-either": "npm run clean && npm install && npm test",
17
- "prerelease": "npm run pre-release-either",
16
+ "prep:pre-release": "npm run clean && npm install && npm test",
17
+ "prerelease": "npm run prep:pre-release",
18
18
  "release": "npm publish",
19
- "prerelease-beta": "npm run pre-release-either",
19
+ "prerelease-alpha": "npm run prep:pre-release",
20
+ "release-alpha": "npm publish --tag beta",
21
+ "prerelease-beta": "npm run prep:pre-release",
20
22
  "release-beta": "npm publish --tag beta"
21
23
  },
22
24
  "repository": {
@@ -34,12 +36,12 @@
34
36
  },
35
37
  "homepage": "https://github.com/dslmeinte/littoral-templates#readme",
36
38
  "devDependencies": {
37
- "@types/chai": "5.0.1",
39
+ "@types/chai": "5.2.2",
38
40
  "@types/mocha": "10.0.10",
39
- "@types/node": "18.19.68",
41
+ "@types/node": "18.19.112",
40
42
  "@typescript-eslint/eslint-plugin": "6.21.0",
41
43
  "@typescript-eslint/parser": "6.21.0",
42
- "chai": "5.1.2",
44
+ "chai": "5.2.0",
43
45
  "mocha": "10.8.2",
44
46
  "typescript": "5.3.3"
45
47
  }
@@ -1 +0,0 @@
1
- {"version":3,"file":"string-utils.d.ts","sourceRoot":"","sources":["../src/string-utils.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,eAAO,MAAM,cAAc,YAAa,MAAM,EAAE,aACiC,CAAA;AAEjF;;GAEG;AACH,eAAO,MAAM,MAAM,QAAS,MAAM,KAAK,MAAM,KAAG,MAY/C,CAAA;AAED;;GAEG;AACH,eAAO,MAAM,kBAAkB,QAAS,MAAM,KAAG,MAG1B,CAAA"}
@@ -1 +0,0 @@
1
- {"version":3,"file":"string-utils.js","sourceRoot":"","sources":["../src/string-utils.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,MAAM,CAAC,IAAM,cAAc,GAAG,UAAC,OAAiB;IAC5C,OAAA,OAAO,CAAC,GAAG,CAAC,UAAC,GAAG,EAAE,KAAK,IAAK,OAAA,UAAG,GAAG,SAAG,KAAK,GAAG,CAAC,GAAG,OAAO,CAAC,MAAM,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,CAAE,EAAhD,CAAgD,CAAC;AAA7E,CAA6E,CAAA;AAEjF;;GAEG;AACH,MAAM,CAAC,IAAM,MAAM,GAAG,UAAC,GAAW,EAAE,CAAS;IACzC,IAAI,MAAM,GAAG,EAAE,CAAA;IACf,OAAO,CAAC,GAAG,CAAC,EAAE,CAAC;QACX,IAAI,CAAC,GAAG,CAAC,KAAK,CAAC,EAAE,CAAC;YACd,MAAM,IAAI,GAAG,CAAA;QACjB,CAAC;QACD,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC;YACR,GAAG,IAAI,GAAG,CAAA;QACd,CAAC;QACD,CAAC,KAAK,CAAC,CAAA;IACX,CAAC;IACD,OAAO,MAAM,CAAA;AACjB,CAAC,CAAA;AAED;;GAEG;AACH,MAAM,CAAC,IAAM,kBAAkB,GAAG,UAAC,GAAW;IAC1C,OAAA,GAAG,CAAC,MAAM,CAAC,GAAG,CAAC,MAAM,GAAG,CAAC,CAAC,KAAK,IAAI;QAC/B,CAAC,CAAC,GAAG;QACL,CAAC,CAAC,CAAE,GAAG,GAAG,IAAI,CAAC;AAFnB,CAEmB,CAAA"}