littoral-templates 0.4.0-rc.2 → 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 +8 -7
- package/README.md +84 -23
- package/dist/{internals.d.ts → eol.d.ts} +10 -4
- package/dist/eol.d.ts.map +1 -0
- package/dist/{internals.js → eol.js} +10 -13
- package/dist/eol.js.map +1 -0
- package/dist/functions.d.ts +8 -37
- package/dist/functions.d.ts.map +1 -1
- package/dist/functions.js +10 -76
- package/dist/functions.js.map +1 -1
- package/dist/indents.d.ts +38 -0
- package/dist/indents.d.ts.map +1 -0
- package/dist/indents.js +51 -0
- package/dist/indents.js.map +1 -0
- package/dist/index-internal.d.ts +15 -0
- package/dist/index-internal.d.ts.map +1 -0
- package/dist/index-internal.js +15 -0
- package/dist/index-internal.js.map +1 -0
- package/dist/index.d.ts +2 -3
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +2 -2
- package/dist/index.js.map +1 -1
- package/dist/primitives.d.ts +14 -0
- package/dist/primitives.d.ts.map +1 -0
- package/dist/primitives.js +34 -0
- package/dist/primitives.js.map +1 -0
- package/dist/strings.d.ts +4 -0
- package/dist/strings.d.ts.map +1 -1
- package/dist/strings.js +4 -0
- package/dist/strings.js.map +1 -1
- package/dist/types.d.ts +5 -2
- package/dist/types.d.ts.map +1 -1
- package/dist/types.js +3 -0
- package/dist/types.js.map +1 -1
- package/package.json +1 -1
- package/dist/internals.d.ts.map +0 -1
- package/dist/internals.js.map +0 -1
package/CHANGELOG.md
CHANGED
@@ -4,10 +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
|
8
|
-
|
9
|
-
|
10
|
-
* The `
|
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”.
|
11
13
|
|
12
14
|
|
13
15
|
## 0.3.0
|
@@ -15,9 +17,8 @@
|
|
15
17
|
* Turn the package into an ESM module (back again).
|
16
18
|
(Should work with Deno in the meanwhile.)
|
17
19
|
* Update dependencies: no impact on shipped code.
|
18
|
-
* Add functions: `when`, `
|
19
|
-
* Rename `NestedString` to `Template`, leaving `NestedString` as
|
20
|
-
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.
|
21
22
|
* Add {T|J}SDoc.
|
22
23
|
|
23
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
|
-
|
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
|
-
|
22
|
-
|
23
|
-
|
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
|
-
|
41
|
-
|
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
|
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
|
131
|
+
Using side effects inside a template can be useful to store information that’s 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
|
-
* `
|
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 `
|
143
|
+
An example of the usage of `withEmptyLineAppended` is
|
128
144
|
|
129
145
|
```typescript
|
130
|
-
[1, 2, 3].map(
|
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
|
-
###
|
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
|
155
|
-
The latter word indicates the part of a body of water (lake, sea, or ocean) that
|
156
|
-
The name tries to convey that implementing templates with this framework doesn
|
215
|
+
The repository’s 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) that’s closest to shore, usually shallow, and possibly not always entirely submerged.
|
217
|
+
The name tries to convey that implementing templates with this framework doesn’t require you to “wade too far into the water”.
|
157
218
|
|
@@ -1,3 +1,9 @@
|
|
1
|
+
/**
|
2
|
+
* EOL-related constants and functions.
|
3
|
+
*/
|
4
|
+
/**
|
5
|
+
* Common EOL styles.
|
6
|
+
*/
|
1
7
|
export declare const eolStyles: {
|
2
8
|
readonly lf: "\n";
|
3
9
|
readonly crlf: "\r\n";
|
@@ -9,15 +15,15 @@ export declare let eol: string;
|
|
9
15
|
/**
|
10
16
|
* Sets the EOL to the OS-dependent value.
|
11
17
|
*/
|
12
|
-
export declare const
|
18
|
+
export declare const setEOLStyleFromOS: () => Promise<void>;
|
13
19
|
/**
|
14
20
|
* Sets the EOL explicitly to the given value.
|
15
21
|
* (This is especially useful for testing.)
|
16
22
|
*/
|
17
23
|
export declare const setEOLExplicitly: (newEol: string) => void;
|
18
24
|
/**
|
19
|
-
*
|
25
|
+
* Splits the given string on EOLs (of any style) into an array of strings,
|
26
|
+
* each corresponding to one line.
|
20
27
|
*/
|
21
|
-
export declare const withEOLEnsured: (str: string) => string;
|
22
28
|
export declare const splitOnEOL: (str: string) => string[];
|
23
|
-
//# sourceMappingURL=
|
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"}
|
@@ -1,5 +1,5 @@
|
|
1
|
-
|
2
|
-
*
|
1
|
+
/**
|
2
|
+
* EOL-related constants and functions.
|
3
3
|
*/
|
4
4
|
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
5
5
|
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
@@ -37,6 +37,9 @@ var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
37
37
|
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
38
38
|
}
|
39
39
|
};
|
40
|
+
/**
|
41
|
+
* Common EOL styles.
|
42
|
+
*/
|
40
43
|
export var eolStyles = {
|
41
44
|
lf: "\n",
|
42
45
|
crlf: "\r\n"
|
@@ -48,7 +51,7 @@ export var eol = eolStyles.lf;
|
|
48
51
|
/**
|
49
52
|
* Sets the EOL to the OS-dependent value.
|
50
53
|
*/
|
51
|
-
export var
|
54
|
+
export var setEOLStyleFromOS = function () { return __awaiter(void 0, void 0, void 0, function () {
|
52
55
|
return __generator(this, function (_a) {
|
53
56
|
return [2 /*return*/, import("os").then(function (os) {
|
54
57
|
eol = os.EOL;
|
@@ -67,18 +70,12 @@ export var setEOLFromOS = function () { return __awaiter(void 0, void 0, void 0,
|
|
67
70
|
export var setEOLExplicitly = function (newEol) {
|
68
71
|
eol = newEol;
|
69
72
|
};
|
70
|
-
var
|
73
|
+
var splitRegex = new RegExp(/\r*\n/);
|
71
74
|
/**
|
72
|
-
*
|
75
|
+
* Splits the given string on EOLs (of any style) into an array of strings,
|
76
|
+
* each corresponding to one line.
|
73
77
|
*/
|
74
|
-
export var withEOLEnsured = function (str) {
|
75
|
-
var match = str.match(normalizeRegex);
|
76
|
-
return match === null
|
77
|
-
? str // (should not happen, but OK...)
|
78
|
-
: (str.substring(0, match.index) + eol);
|
79
|
-
};
|
80
|
-
var splitRegex = new RegExp(/\r*\n/);
|
81
78
|
export var splitOnEOL = function (str) {
|
82
79
|
return str.split(splitRegex);
|
83
80
|
};
|
84
|
-
//# sourceMappingURL=
|
81
|
+
//# sourceMappingURL=eol.js.map
|
package/dist/eol.js.map
ADDED
@@ -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"}
|
package/dist/functions.d.ts
CHANGED
@@ -1,41 +1,7 @@
|
|
1
|
-
import { Template } from "./index.js";
|
2
1
|
/**
|
3
|
-
*
|
2
|
+
* Non-primitive functions on the {@link Template} type.
|
4
3
|
*/
|
5
|
-
|
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[];
|
24
|
-
/**
|
25
|
-
* An enumeration of common indentation styles.
|
26
|
-
* Use these in a type-safe way as follows, e.g. for “1 tab”:
|
27
|
-
*
|
28
|
-
* ```
|
29
|
-
* const indent = indentWith(commonIndentations["1 tab"])
|
30
|
-
*
|
31
|
-
* indent([`foo`])
|
32
|
-
* ```
|
33
|
-
*/
|
34
|
-
export declare const commonIndentations: {
|
35
|
-
readonly "2 spaces": " ";
|
36
|
-
readonly "4 spaces": " ";
|
37
|
-
readonly "1 tab": "\t";
|
38
|
-
};
|
4
|
+
import { Template } from "./index-internal.js";
|
39
5
|
/**
|
40
6
|
* Allows for the following syntax:
|
41
7
|
* <pre>
|
@@ -64,7 +30,12 @@ export declare const commonIndentations: {
|
|
64
30
|
*/
|
65
31
|
export declare const when: (bool: boolean) => (...whenResults: Template[]) => Template;
|
66
32
|
/**
|
67
|
-
* @return a function that composes the given template function with the action of "adding
|
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.
|
68
39
|
*/
|
69
40
|
export declare const withNewlineAppended: <T>(templateFunc: (t: T) => Template) => (t: T) => Template[];
|
70
41
|
//# sourceMappingURL=functions.d.ts.map
|
package/dist/functions.d.ts.map
CHANGED
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"functions.d.ts","sourceRoot":"","sources":["../src/functions.ts"],"names":[],"mappings":"AAAA
|
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,78 +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 } from "./index.js";
|
11
|
-
import { withEOLEnsured } from "./internals.js";
|
12
|
-
/**
|
13
|
-
* “Flattens” the given template to an array of strings, each of which represent exactly one line.
|
14
|
-
*/
|
15
|
-
var flatten = function (template) {
|
16
|
-
if (typeof template === "function") {
|
17
|
-
return flatten(template());
|
18
|
-
}
|
19
|
-
if (Array.isArray(template)) {
|
20
|
-
return template.map(flatten).reduce(function (arrL, arrR) { return __spreadArray(__spreadArray([], arrL, true), arrR, true); }, []);
|
21
|
-
}
|
22
|
-
return template.split(/\r*\n/);
|
23
|
-
};
|
24
1
|
/**
|
25
|
-
*
|
2
|
+
* Non-primitive functions on the {@link Template} type.
|
26
3
|
*/
|
27
|
-
|
28
|
-
return flatten(template).map(withEOLEnsured).join("");
|
29
|
-
};
|
30
|
-
/**
|
31
|
-
* @returns a function to instantiate a function to indent a sub-template.
|
32
|
-
* The function always returns an array of strings.
|
33
|
-
*
|
34
|
-
* Its usage looks as follows:
|
35
|
-
* <pre>
|
36
|
-
* indentWith(" ")(2)([
|
37
|
-
* `this is indented 2 levels`
|
38
|
-
* ])
|
39
|
-
* </pre>
|
40
|
-
* Note that the third Curried argument is variadic, so the array brackets (`[]`) can be elided.
|
41
|
-
*
|
42
|
-
* Usually, one sets up the following function constant before:
|
43
|
-
* <pre>
|
44
|
-
* const indent = indentWith(" ")
|
45
|
-
* </pre>
|
46
|
-
*/
|
47
|
-
export var indentWith = function (singleIndentation) {
|
48
|
-
return function (indentLevel) {
|
49
|
-
if (indentLevel === void 0) { indentLevel = 1; }
|
50
|
-
var prefix = repeat(singleIndentation, indentLevel);
|
51
|
-
var indenter = function (line) { return line.length > 0 ? (prefix + line) : line; };
|
52
|
-
return function () {
|
53
|
-
var templates = [];
|
54
|
-
for (var _i = 0; _i < arguments.length; _i++) {
|
55
|
-
templates[_i] = arguments[_i];
|
56
|
-
}
|
57
|
-
return flatten(templates).map(indenter);
|
58
|
-
}; // Note: Template[] has type Template as well!
|
59
|
-
};
|
60
|
-
};
|
61
|
-
/**
|
62
|
-
* An enumeration of common indentation styles.
|
63
|
-
* Use these in a type-safe way as follows, e.g. for “1 tab”:
|
64
|
-
*
|
65
|
-
* ```
|
66
|
-
* const indent = indentWith(commonIndentations["1 tab"])
|
67
|
-
*
|
68
|
-
* indent([`foo`])
|
69
|
-
* ```
|
70
|
-
*/
|
71
|
-
export var commonIndentations = {
|
72
|
-
"2 spaces": " ",
|
73
|
-
"4 spaces": " ",
|
74
|
-
"1 tab": "\t"
|
75
|
-
};
|
4
|
+
import { flattened } from "./index-internal.js";
|
76
5
|
/**
|
77
6
|
* Allows for the following syntax:
|
78
7
|
* <pre>
|
@@ -106,14 +35,19 @@ export var when = function (bool) {
|
|
106
35
|
for (var _i = 0; _i < arguments.length; _i++) {
|
107
36
|
whenResults[_i] = arguments[_i];
|
108
37
|
}
|
109
|
-
return
|
38
|
+
return flattened(whenResults);
|
110
39
|
} // (need to be explicit here, or it doesn't work – despite having specified the return type...)
|
111
40
|
: function (_) { return []; };
|
112
41
|
};
|
113
42
|
/**
|
114
|
-
* @return a function that composes the given template function with the action of "adding
|
43
|
+
* @return a function that composes the given template function with the action of "adding an empty line after".
|
115
44
|
*/
|
116
|
-
export var
|
45
|
+
export var withEmptyLineAppended = function (templateFunc) {
|
117
46
|
return function (t) { return [templateFunc(t), ""]; };
|
118
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;
|
119
53
|
//# sourceMappingURL=functions.js.map
|
package/dist/functions.js.map
CHANGED
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"functions.js","sourceRoot":"","sources":["../src/functions.ts"],"names":[],"mappings":"
|
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"}
|
package/dist/indents.js
ADDED
@@ -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 {
|
2
|
-
export {
|
3
|
-
export { commaSeparated, repeat } from "./strings.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
|
package/dist/index.d.ts.map
CHANGED
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,
|
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
|
2
|
-
|
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":"
|
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"}
|
package/dist/strings.d.ts
CHANGED
@@ -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
|
*/
|
@@ -5,6 +8,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...
|
7
10
|
* (Implementation uses the binary representation of n.)
|
11
|
+
* Note: doesn't need to be exposed.
|
8
12
|
*/
|
9
13
|
export declare const repeat: (str: string, n: number) => string;
|
10
14
|
//# sourceMappingURL=strings.d.ts.map
|
package/dist/strings.d.ts.map
CHANGED
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"strings.d.ts","sourceRoot":"","sources":["../src/strings.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,eAAO,MAAM,cAAc,YAAa,MAAM,EAAE,aACiC,CAAA;AAEjF
|
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"}
|
package/dist/strings.js
CHANGED
@@ -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
|
*/
|
@@ -7,6 +10,7 @@ export var commaSeparated = function (strings) {
|
|
7
10
|
/**
|
8
11
|
* Polyfill/shim for ES2015's String.prototype.repeat which doesn't work for some reason in the test...
|
9
12
|
* (Implementation uses the binary representation of n.)
|
13
|
+
* Note: doesn't need to be exposed.
|
10
14
|
*/
|
11
15
|
export var repeat = function (str, n) {
|
12
16
|
var result = "";
|
package/dist/strings.js.map
CHANGED
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"strings.js","sourceRoot":"","sources":["../src/strings.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
|
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 |
|
10
|
+
export type Template = string | (() => Template) | Array<Template>;
|
8
11
|
/**
|
9
|
-
*
|
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;
|
package/dist/types.d.ts.map
CHANGED
@@ -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,
|
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
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.
|
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",
|
package/dist/internals.d.ts.map
DELETED
@@ -1 +0,0 @@
|
|
1
|
-
{"version":3,"file":"internals.d.ts","sourceRoot":"","sources":["../src/internals.ts"],"names":[],"mappings":"AAKA,eAAO,MAAM,SAAS;;;CAGZ,CAAA;AAEV;;GAEG;AACH,eAAO,IAAI,GAAG,EAAE,MAAqB,CAAA;AAGrC;;GAEG;AACH,eAAO,MAAM,YAAY,QAAa,QAAQ,IAAI,CAG5C,CAAA;AAGN;;;GAGG;AACH,eAAO,MAAM,gBAAgB,WAAY,MAAM,SAE9C,CAAA;AAKD;;GAEG;AACH,eAAO,MAAM,cAAc,QAAS,MAAM,KAAG,MAK5C,CAAA;AAKD,eAAO,MAAM,UAAU,QAAS,MAAM,KAAG,MAAM,EACtB,CAAA"}
|
package/dist/internals.js.map
DELETED
@@ -1 +0,0 @@
|
|
1
|
-
{"version":3,"file":"internals.js","sourceRoot":"","sources":["../src/internals.ts"],"names":[],"mappings":"AAAA;;GAEG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAGH,MAAM,CAAC,IAAM,SAAS,GAAG;IACrB,EAAE,EAAE,IAAI;IACR,IAAI,EAAE,MAAM;CACN,CAAA;AAEV;;GAEG;AACH,MAAM,CAAC,IAAI,GAAG,GAAW,SAAS,CAAC,EAAE,CAAA;AAGrC;;GAEG;AACH,MAAM,CAAC,IAAM,YAAY,GAAG;;QACxB,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,cAAc,GAAG,IAAI,MAAM,CAAC,SAAS,CAAC,CAAA;AAE5C;;GAEG;AACH,MAAM,CAAC,IAAM,cAAc,GAAG,UAAC,GAAW;IACtC,IAAM,KAAK,GAAG,GAAG,CAAC,KAAK,CAAC,cAAc,CAAC,CAAA;IACvC,OAAO,KAAK,KAAK,IAAI;QACjB,CAAC,CAAC,GAAG,CAAG,iCAAiC;QACzC,CAAC,CAAC,CAAC,GAAG,CAAC,SAAS,CAAC,CAAC,EAAE,KAAK,CAAC,KAAK,CAAC,GAAG,GAAG,CAAC,CAAA;AAC/C,CAAC,CAAA;AAGD,IAAM,UAAU,GAAG,IAAI,MAAM,CAAC,OAAO,CAAC,CAAA;AAEtC,MAAM,CAAC,IAAM,UAAU,GAAG,UAAC,GAAW;IAClC,OAAA,GAAG,CAAC,KAAK,CAAC,UAAU,CAAC;AAArB,CAAqB,CAAA"}
|