littoral-templates 0.3.0 → 0.4.0-rc.1

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/.editorconfig ADDED
@@ -0,0 +1,9 @@
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
+
package/.eslintrc.cjs ADDED
@@ -0,0 +1,15 @@
1
+ /* eslint-env node */
2
+ module.exports = {
3
+ extends: ["eslint:recommended", "plugin:@typescript-eslint/recommended"],
4
+ parser: "@typescript-eslint/parser",
5
+ plugins: ["@typescript-eslint"],
6
+ root: true,
7
+ rules: {
8
+ "@typescript-eslint/no-unused-vars": ["error", {"argsIgnorePattern": "^_"}],
9
+ "@typescript-eslint/ban-ts-ignore": "off",
10
+ "@typescript-eslint/prefer-spread": ["off"]
11
+ },
12
+ env: {
13
+ browser: true,
14
+ node: true
15
+ }}
package/CHANGELOG.md CHANGED
@@ -1,5 +1,10 @@
1
1
  # CHANGELOG
2
2
 
3
+ ## 0.4.0
4
+
5
+ * Thunks returning a `Template` are now `Template`s as well.
6
+ * The 3rd (Curried) argument of `indentWith`, and the 2nd (Curried) argument of `when` are now variadic.
7
+
3
8
 
4
9
  ## 0.3.0
5
10
 
@@ -0,0 +1,55 @@
1
+ import { Template } from "./types.js";
2
+ /**
3
+ * @returns {string} - the given template joined as one string, taking care of proper newline endings.
4
+ */
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[];
24
+ /**
25
+ * Allows for the following syntax:
26
+ * <pre>
27
+ * [
28
+ * when(<some boolean condition>)(
29
+ * <stuff to include when boolean condition is true>
30
+ * )
31
+ * ]
32
+ * </pre>
33
+ *
34
+ * and
35
+ *
36
+ * <pre>
37
+ * [
38
+ * when(<some boolean condition>)(
39
+ * () => <stuff to include when boolean condition is true>
40
+ * )
41
+ * ]
42
+ * </pre>
43
+ *
44
+ * In the latter case, it's guaranteed that the thunk ({@see https://en.wikipedia.org/wiki/Thunk})
45
+ * is only evaluated (/run) when the boolean condition is true.
46
+ * That is useful in case the stuff to include produces side effects.
47
+ *
48
+ * Note that the second Curried argument is variadic, so it doesn't require array brackets (`[]`).
49
+ */
50
+ export declare const when: (bool: boolean) => (...whenResults: Template[]) => Template;
51
+ /**
52
+ * @return a function that composes the given template function with the action of "adding a newline after".
53
+ */
54
+ export declare const withNewlineAppended: <T>(templateFunc: (t: T) => Template) => (t: T) => Template[];
55
+ //# sourceMappingURL=functions.d.ts.map
@@ -0,0 +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"}
@@ -0,0 +1,103 @@
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
+ /**
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>
45
+ */
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
+ };
60
+ /**
61
+ * Allows for the following syntax:
62
+ * <pre>
63
+ * [
64
+ * when(<some boolean condition>)(
65
+ * <stuff to include when boolean condition is true>
66
+ * )
67
+ * ]
68
+ * </pre>
69
+ *
70
+ * and
71
+ *
72
+ * <pre>
73
+ * [
74
+ * when(<some boolean condition>)(
75
+ * () => <stuff to include when boolean condition is true>
76
+ * )
77
+ * ]
78
+ * </pre>
79
+ *
80
+ * In the latter case, it's guaranteed that the thunk ({@see https://en.wikipedia.org/wiki/Thunk})
81
+ * is only evaluated (/run) when the boolean condition is true.
82
+ * That is useful in case the stuff to include produces side effects.
83
+ *
84
+ * Note that the second Curried argument is variadic, so it doesn't require array brackets (`[]`).
85
+ */
86
+ export var when = function (bool) {
87
+ return bool
88
+ ? function () {
89
+ var whenResults = [];
90
+ for (var _i = 0; _i < arguments.length; _i++) {
91
+ whenResults[_i] = arguments[_i];
92
+ }
93
+ return flatten(whenResults);
94
+ } // (need to be explicit here, or it doesn't work – despite having specified the return type...)
95
+ : function (_) { return []; };
96
+ };
97
+ /**
98
+ * @return a function that composes the given template function with the action of "adding a newline after".
99
+ */
100
+ export var withNewlineAppended = function (templateFunc) {
101
+ return function (t) { return [templateFunc(t), ""]; };
102
+ };
103
+ //# sourceMappingURL=functions.js.map
@@ -0,0 +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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,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"}
package/dist/index.d.ts CHANGED
@@ -1,69 +1,4 @@
1
- /**
2
- * A type definition for “templates” that consist of array of strings nested to an arbitrary depth.
3
- * (Depth 0 corresponds to just a single string.)
4
- *
5
- * @since version 0.3.0
6
- */
7
- export type Template = string | Array<Template>;
8
- /**
9
- * An alias for the {@link Template} type definition.
10
- * Note: this type might be deprecated and removed (per a major version) in the future.
11
- */
12
- export type NestedString = Template;
13
- type TemplateFunction<T> = (_: Template) => T;
14
- /**
15
- * @returns {string} - the given template joined as one string, taking care of proper newline endings.
16
- */
17
- export declare const asString: (template: Template) => string;
18
- /**
19
- * @returns {function} - a function to instantiate a function to indent a sub-template.
20
- * The function always returns an array of strings.
21
- *
22
- * Its usage looks as follows:
23
- * <pre>
24
- * indentWith(" ")(2)([
25
- * `this is indented 2 levels`
26
- * ])
27
- * </pre>
28
- *
29
- * Usually, one sets up the following function constant before:
30
- * <pre>
31
- * const indent = indentWith(" ")
32
- * </pre>
33
- */
34
- export declare const indentWith: (singleIndentation: string) => (indentLevel?: number) => TemplateFunction<string[]>;
35
- /**
36
- * Allows for the following syntax:
37
- * <pre>
38
- * [
39
- * when(<some boolean condition>)(
40
- * <stuff to include when boolean condition is true>
41
- * )
42
- * ]
43
- * </pre>
44
- *
45
- * and
46
- *
47
- * <pre>
48
- * [
49
- * when(<some boolean condition>)(
50
- * () => <stuff to include when boolean condition is true>
51
- * )
52
- * ]
53
- * </pre>
54
- *
55
- * In the latter case, it's guaranteed that the thunk ({@see https://en.wikipedia.org/wiki/Thunk})
56
- * is only evaluated (/run) when the boolean condition is true.
57
- * That is useful in case the stuff to include produces side effects.
58
- */
59
- export declare const when: (bool: boolean) => (whenResult: (() => Template) | Template) => Template;
60
- /**
61
- * @return a function that composes the given template function with the action of "adding a newline after".
62
- */
63
- export declare const withNewlineAppended: <T>(templateFunc: (t: T) => Template) => (t: T) => Template[];
64
- /**
65
- * @return the given array of strings but with commas added after each string except the last one.
66
- */
67
- export declare const commaSeparated: (strings: string[]) => string[];
68
- export {};
1
+ export { Template, NestedString } from "./types.js";
2
+ export { asString, indentWith, when, withNewlineAppended } from "./functions.js";
3
+ export { commaSeparated } from "./string-utils.js";
69
4
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AACH,MAAM,MAAM,QAAQ,GAAG,MAAM,GAAG,KAAK,CAAC,QAAQ,CAAC,CAAA;AAE/C;;;GAGG;AACH,MAAM,MAAM,YAAY,GAAG,QAAQ,CAAA;AAGnC,KAAK,gBAAgB,CAAC,CAAC,IAAI,CAAC,CAAC,EAAE,QAAQ,KAAK,CAAC,CAAA;AA6B7C;;GAEG;AACH,eAAO,MAAM,QAAQ,aAdN,QAAQ,WAc2F,CAAA;AAoBlH;;;;;;;;;;;;;;;GAeG;AACH,eAAO,MAAM,UAAU,sBAAuB,MAAM,oBAClC,MAAM,KAAO,gBAAgB,CAAC,MAAM,EAAE,CAInD,CAAA;AAGL;;;;;;;;;;;;;;;;;;;;;;;GAuBG;AACH,eAAO,MAAM,IAAI,SAAU,OAAO,kBAEX,CAAC,MAAM,QAAQ,CAAC,GAAG,QAAQ,aAIQ,CAAA;AAG1D;;GAEG;AACH,eAAO,MAAM,mBAAmB,GAAI,CAAC,gBAAgB,CAAC,CAAC,EAAE,CAAC,KAAK,QAAQ,SAC/D,CAAC,eAA0B,CAAA;AAGnC;;GAEG;AACH,eAAO,MAAM,cAAc,YAAa,MAAM,EAAE,aACiC,CAAA"}
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"}
package/dist/index.js CHANGED
@@ -1,124 +1,3 @@
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
- /**
11
- * Polyfill/shim for ES2019's Array.prototype.flat(..).
12
- */
13
- var flatten = function (template) {
14
- return Array.isArray(template)
15
- ? template.map(flatten).reduce(function (arrL, arrR) { return __spreadArray(__spreadArray([], arrL, true), arrR, true); }, [])
16
- : [template];
17
- };
18
- /**
19
- * @returns {function(*=): *} - a function that maps over a single string using mapString, or an array of strings using mapStrings.
20
- * If an array is given, that array is completely (i.e.: recursively) flattened first, before the mapStrings function is applied.
21
- * (This function is only used internally.)
22
- */
23
- var mapNestedString = function (mapString, mapStrings) {
24
- return function (template) {
25
- return Array.isArray(template)
26
- ? mapStrings(flatten(template))
27
- : mapString(template);
28
- };
29
- };
30
- var withNewlineEnsured = function (str) {
31
- return str.charAt(str.length - 1) === '\n'
32
- ? str
33
- : (str + "\n");
34
- };
35
- /**
36
- * @returns {string} - the given template joined as one string, taking care of proper newline endings.
37
- */
38
- export var asString = mapNestedString(withNewlineEnsured, function (strings) { return strings.map(withNewlineEnsured).join(""); });
39
- /**
40
- * Polyfill/shim for ES2015's String.prototype.repeat which doesn't work for some reason in the test...
41
- */
42
- var repeat = function (str, n) {
43
- var result = "";
44
- while (n > 0) {
45
- if (n % 2 === 1) {
46
- result += str;
47
- }
48
- if (n > 1) {
49
- str += str;
50
- }
51
- n >>= 1;
52
- }
53
- return result;
54
- };
55
- /**
56
- * @returns {function} - a function to instantiate a function to indent a sub-template.
57
- * The function always returns an array of strings.
58
- *
59
- * Its usage looks as follows:
60
- * <pre>
61
- * indentWith(" ")(2)([
62
- * `this is indented 2 levels`
63
- * ])
64
- * </pre>
65
- *
66
- * Usually, one sets up the following function constant before:
67
- * <pre>
68
- * const indent = indentWith(" ")
69
- * </pre>
70
- */
71
- export var indentWith = function (singleIndentation) {
72
- return function (indentLevel) {
73
- if (indentLevel === void 0) { indentLevel = 1; }
74
- var indentationPrefix = repeat(singleIndentation, indentLevel);
75
- var indentLine = function (str) { return str.split("\n").map(function (line) { return (line.length > 0 ? indentationPrefix : "") + line; }).join("\n"); };
76
- return mapNestedString(function (string) { return [indentLine(string)]; }, function (strings) { return strings.map(indentLine); });
77
- };
78
- };
79
- /**
80
- * Allows for the following syntax:
81
- * <pre>
82
- * [
83
- * when(<some boolean condition>)(
84
- * <stuff to include when boolean condition is true>
85
- * )
86
- * ]
87
- * </pre>
88
- *
89
- * and
90
- *
91
- * <pre>
92
- * [
93
- * when(<some boolean condition>)(
94
- * () => <stuff to include when boolean condition is true>
95
- * )
96
- * ]
97
- * </pre>
98
- *
99
- * In the latter case, it's guaranteed that the thunk ({@see https://en.wikipedia.org/wiki/Thunk})
100
- * is only evaluated (/run) when the boolean condition is true.
101
- * That is useful in case the stuff to include produces side effects.
102
- */
103
- export var when = function (bool) {
104
- return bool
105
- ? function (whenResult) {
106
- return typeof whenResult === "function"
107
- ? whenResult()
108
- : whenResult;
109
- }
110
- : function (_whenResult) { return []; };
111
- };
112
- /**
113
- * @return a function that composes the given template function with the action of "adding a newline after".
114
- */
115
- export var withNewlineAppended = function (templateFunc) {
116
- return function (t) { return [templateFunc(t), ""]; };
117
- };
118
- /**
119
- * @return the given array of strings but with commas added after each string except the last one.
120
- */
121
- export var commaSeparated = function (strings) {
122
- return strings.map(function (str, index) { return "".concat(str).concat(index + 1 < strings.length ? "," : ""); });
123
- };
1
+ export { asString, indentWith, when, withNewlineAppended } from "./functions.js";
2
+ export { commaSeparated } from "./string-utils.js";
124
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":";;;;;;;;;AAkBA;;GAEG;AACH,IAAM,OAAO,GAAG,UAAC,QAAkB;IAC/B,OAAA,KAAK,CAAC,OAAO,CAAC,QAAQ,CAAC;QACnB,CAAC,CAAC,QAAQ,CAAC,GAAG,CAAC,OAAO,CAAC,CAAC,MAAM,CAAC,UAAC,IAAI,EAAE,IAAI,IAAK,uCAAK,IAAI,SAAK,IAAI,SAAlB,CAAoB,EAAE,EAAE,CAAC;QACxE,CAAC,CAAC,CAAE,QAAQ,CAAE;AAFlB,CAEkB,CAAA;AAGtB;;;;GAIG;AACH,IAAM,eAAe,GAAG,UAAI,SAA2B,EAAE,UAA8B;IACnF,OAAA,UAAC,QAAkB;QACf,OAAA,KAAK,CAAC,OAAO,CAAC,QAAQ,CAAC;YACnB,CAAC,CAAC,UAAU,CAAC,OAAO,CAAC,QAAQ,CAAC,CAAC;YAC/B,CAAC,CAAC,SAAS,CAAC,QAAQ,CAAC;IAFzB,CAEyB;AAH7B,CAG6B,CAAA;AAGjC,IAAM,kBAAkB,GAAG,UAAC,GAAW;IACnC,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;AAEvB;;GAEG;AACH,MAAM,CAAC,IAAM,QAAQ,GAAG,eAAe,CAAC,kBAAkB,EAAE,UAAC,OAAO,IAAK,OAAA,OAAO,CAAC,GAAG,CAAC,kBAAkB,CAAC,CAAC,IAAI,CAAC,EAA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C,IAAa;IAC9B,OAAA,IAAI;QACA,CAAC,CAAC,UAAC,UAAuC;YACtC,OAAA,OAAO,UAAU,KAAK,UAAU;gBAC5B,CAAC,CAAC,UAAU,EAAE;gBACd,CAAC,CAAC,UAAU;QAFhB,CAEgB;QACpB,CAAC,CAAC,UAAC,WAAwC,IAAK,OAAA,EAAE,EAAF,CAAE;AALtD,CAKsD,CAAA;AAG1D;;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;AAGnC;;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"}
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"}
@@ -0,0 +1,13 @@
1
+ /**
2
+ * @return the given array of strings but with commas added after each string except the last one.
3
+ */
4
+ export declare const commaSeparated: (strings: string[]) => string[];
5
+ /**
6
+ * Polyfill/shim for ES2015's String.prototype.repeat which doesn't work for some reason in the test...
7
+ */
8
+ 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
@@ -0,0 +1 @@
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"}
@@ -0,0 +1,31 @@
1
+ /**
2
+ * @return the given array of strings but with commas added after each string except the last one.
3
+ */
4
+ export var commaSeparated = function (strings) {
5
+ return strings.map(function (str, index) { return "".concat(str).concat(index + 1 < strings.length ? "," : ""); });
6
+ };
7
+ /**
8
+ * Polyfill/shim for ES2015's String.prototype.repeat which doesn't work for some reason in the test...
9
+ */
10
+ export var repeat = function (str, n) {
11
+ var result = "";
12
+ while (n > 0) {
13
+ if (n % 2 === 1) {
14
+ result += str;
15
+ }
16
+ if (n > 1) {
17
+ str += str;
18
+ }
19
+ n >>= 1;
20
+ }
21
+ return result;
22
+ };
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
@@ -0,0 +1 @@
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"}
@@ -0,0 +1,13 @@
1
+ /**
2
+ * A type definition for “templates” that consist of a string, or an array of templates, or a thunk returning a template.
3
+ * Note that nesting can occur to arbitrary (finite) depth.
4
+ *
5
+ * @since version 0.3.0
6
+ */
7
+ export type Template = string | Array<Template> | (() => Template);
8
+ /**
9
+ * An alias for the {@link Template} type definition.
10
+ * Note: this type might be deprecated and removed (per a major version) in the future.
11
+ */
12
+ export type NestedString = Template;
13
+ //# sourceMappingURL=types.d.ts.map
@@ -0,0 +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"}
package/dist/types.js ADDED
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=types.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.js","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":""}
package/package.json CHANGED
@@ -1,39 +1,46 @@
1
1
  {
2
- "name": "littoral-templates",
3
- "version": "0.3.0",
4
- "description": "A small JavaScript/TypeScript framework to do templating comfortably using the template literal syntax in either JavaScript or TypeScript.",
5
- "type": "module",
6
- "main": "dist/index.js",
7
- "types": "dist/index.d.ts",
8
- "scripts": {
9
- "build": "tsc",
10
- "watch-build": "tsc --watch",
11
- "clean": "rm -rf dist",
12
- "pretest": "npm-run-all build",
13
- "test": "mocha dist/test/*.js",
14
- "watch-test": "mocha --watch dist/test/*.js"
15
- },
16
- "repository": {
17
- "type": "git",
18
- "url": "git+https://github.com/dslmeinte/littoral-templates.git"
19
- },
20
- "keywords": [
21
- "template",
22
- "engine"
23
- ],
24
- "author": "Meinte Boersma",
25
- "license": "MIT",
26
- "bugs": {
27
- "url": "https://github.com/dslmeinte/littoral-templates/issues"
28
- },
29
- "homepage": "https://github.com/dslmeinte/littoral-templates#readme",
30
- "devDependencies": {
31
- "@types/chai": "5.0.1",
32
- "@types/mocha": "10.0.9",
33
- "@types/node": "18.19.64",
34
- "chai": "5.1.2",
35
- "mocha": "10.8.2",
36
- "npm-run-all": "4.1.5",
37
- "typescript": "5.6.3"
38
- }
2
+ "name": "littoral-templates",
3
+ "version": "0.4.0-rc.1",
4
+ "description": "A small JavaScript/TypeScript framework to do templating comfortably using the template literal syntax in either JavaScript or TypeScript.",
5
+ "type": "module",
6
+ "main": "dist/index.js",
7
+ "types": "dist/index.d.ts",
8
+ "scripts": {
9
+ "build": "tsc",
10
+ "watch-build": "tsc --watch",
11
+ "clean": "rm -rf dist node_modules",
12
+ "pretest": "npm run build",
13
+ "test": "mocha dist/test/*.js",
14
+ "watch-test": "mocha --watch dist/test/*.js",
15
+ "lint": "eslint src",
16
+ "pre-release-either": "npm run clean && npm install && npm test",
17
+ "prerelease": "npm run pre-release-either",
18
+ "release": "npm publish",
19
+ "prerelease-beta": "npm run pre-release-either",
20
+ "release-beta": "npm publish --tag beta"
21
+ },
22
+ "repository": {
23
+ "type": "git",
24
+ "url": "git+https://github.com/dslmeinte/littoral-templates.git"
25
+ },
26
+ "keywords": [
27
+ "template",
28
+ "engine"
29
+ ],
30
+ "author": "Meinte Boersma",
31
+ "license": "MIT",
32
+ "bugs": {
33
+ "url": "https://github.com/dslmeinte/littoral-templates/issues"
34
+ },
35
+ "homepage": "https://github.com/dslmeinte/littoral-templates#readme",
36
+ "devDependencies": {
37
+ "@types/chai": "5.0.1",
38
+ "@types/mocha": "10.0.10",
39
+ "@types/node": "18.19.68",
40
+ "@typescript-eslint/eslint-plugin": "6.21.0",
41
+ "@typescript-eslint/parser": "6.21.0",
42
+ "chai": "5.1.2",
43
+ "mocha": "10.8.2",
44
+ "typescript": "5.3.3"
45
+ }
39
46
  }