replace-all-mustaches 0.0.7 → 0.0.9

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.
@@ -0,0 +1 @@
1
+ {}
@@ -0,0 +1 @@
1
+ {}
@@ -0,0 +1,33 @@
1
+ {
2
+ "file-explorer": true,
3
+ "global-search": true,
4
+ "switcher": true,
5
+ "graph": true,
6
+ "backlink": true,
7
+ "canvas": true,
8
+ "outgoing-link": true,
9
+ "tag-pane": true,
10
+ "footnotes": false,
11
+ "properties": true,
12
+ "page-preview": true,
13
+ "daily-notes": true,
14
+ "templates": true,
15
+ "note-composer": true,
16
+ "command-palette": true,
17
+ "slash-command": false,
18
+ "editor-status": true,
19
+ "bookmarks": true,
20
+ "markdown-importer": false,
21
+ "zk-prefixer": false,
22
+ "random-note": false,
23
+ "outline": true,
24
+ "word-count": true,
25
+ "slides": false,
26
+ "audio-recorder": false,
27
+ "workspaces": false,
28
+ "file-recovery": true,
29
+ "publish": false,
30
+ "sync": true,
31
+ "bases": true,
32
+ "webviewer": false
33
+ }
@@ -0,0 +1,188 @@
1
+ {
2
+ "main": {
3
+ "id": "4daae414ad798d52",
4
+ "type": "split",
5
+ "children": [
6
+ {
7
+ "id": "b1b1c90b69ae71a3",
8
+ "type": "tabs",
9
+ "children": [
10
+ {
11
+ "id": "445cbff87fecafda",
12
+ "type": "leaf",
13
+ "state": {
14
+ "type": "markdown",
15
+ "state": {
16
+ "file": "README.md",
17
+ "mode": "source",
18
+ "source": false
19
+ },
20
+ "icon": "lucide-file",
21
+ "title": "README"
22
+ }
23
+ }
24
+ ]
25
+ }
26
+ ],
27
+ "direction": "vertical"
28
+ },
29
+ "left": {
30
+ "id": "bfcacb4e99960c9a",
31
+ "type": "split",
32
+ "children": [
33
+ {
34
+ "id": "c68d7a811923bb04",
35
+ "type": "tabs",
36
+ "children": [
37
+ {
38
+ "id": "5c71a0f5075ce654",
39
+ "type": "leaf",
40
+ "state": {
41
+ "type": "file-explorer",
42
+ "state": {
43
+ "sortOrder": "alphabetical",
44
+ "autoReveal": false
45
+ },
46
+ "icon": "lucide-folder-closed",
47
+ "title": "Files"
48
+ }
49
+ },
50
+ {
51
+ "id": "84c107d47eaefccf",
52
+ "type": "leaf",
53
+ "state": {
54
+ "type": "search",
55
+ "state": {
56
+ "query": "",
57
+ "matchingCase": false,
58
+ "explainSearch": false,
59
+ "collapseAll": false,
60
+ "extraContext": false,
61
+ "sortOrder": "alphabetical"
62
+ },
63
+ "icon": "lucide-search",
64
+ "title": "Search"
65
+ }
66
+ },
67
+ {
68
+ "id": "a8cbbcba343759c9",
69
+ "type": "leaf",
70
+ "state": {
71
+ "type": "bookmarks",
72
+ "state": {},
73
+ "icon": "lucide-bookmark",
74
+ "title": "Bookmarks"
75
+ }
76
+ }
77
+ ]
78
+ }
79
+ ],
80
+ "direction": "horizontal",
81
+ "width": 300
82
+ },
83
+ "right": {
84
+ "id": "8aff1fa5c518451e",
85
+ "type": "split",
86
+ "children": [
87
+ {
88
+ "id": "43a814ace492ceab",
89
+ "type": "tabs",
90
+ "children": [
91
+ {
92
+ "id": "28da262e1698e35e",
93
+ "type": "leaf",
94
+ "state": {
95
+ "type": "backlink",
96
+ "state": {
97
+ "file": "README.md",
98
+ "collapseAll": false,
99
+ "extraContext": false,
100
+ "sortOrder": "alphabetical",
101
+ "showSearch": false,
102
+ "searchQuery": "",
103
+ "backlinkCollapsed": false,
104
+ "unlinkedCollapsed": true
105
+ },
106
+ "icon": "links-coming-in",
107
+ "title": "Backlinks for README"
108
+ }
109
+ },
110
+ {
111
+ "id": "7f9babb66cdf09c1",
112
+ "type": "leaf",
113
+ "state": {
114
+ "type": "outgoing-link",
115
+ "state": {
116
+ "file": "README.md",
117
+ "linksCollapsed": false,
118
+ "unlinkedCollapsed": true
119
+ },
120
+ "icon": "links-going-out",
121
+ "title": "Outgoing links from README"
122
+ }
123
+ },
124
+ {
125
+ "id": "b31d305f280030e8",
126
+ "type": "leaf",
127
+ "state": {
128
+ "type": "tag",
129
+ "state": {
130
+ "sortOrder": "frequency",
131
+ "useHierarchy": true,
132
+ "showSearch": false,
133
+ "searchQuery": ""
134
+ },
135
+ "icon": "lucide-tags",
136
+ "title": "Tags"
137
+ }
138
+ },
139
+ {
140
+ "id": "375aeedde3085647",
141
+ "type": "leaf",
142
+ "state": {
143
+ "type": "all-properties",
144
+ "state": {
145
+ "sortOrder": "frequency",
146
+ "showSearch": false,
147
+ "searchQuery": ""
148
+ },
149
+ "icon": "lucide-archive",
150
+ "title": "All properties"
151
+ }
152
+ },
153
+ {
154
+ "id": "84f7054df9fc73ed",
155
+ "type": "leaf",
156
+ "state": {
157
+ "type": "outline",
158
+ "state": {
159
+ "file": "README.md",
160
+ "followCursor": false,
161
+ "showSearch": false,
162
+ "searchQuery": ""
163
+ },
164
+ "icon": "lucide-list",
165
+ "title": "Outline of README"
166
+ }
167
+ }
168
+ ]
169
+ }
170
+ ],
171
+ "direction": "horizontal",
172
+ "width": 300,
173
+ "collapsed": true
174
+ },
175
+ "left-ribbon": {
176
+ "hiddenItems": {
177
+ "switcher:Open quick switcher": false,
178
+ "graph:Open graph view": false,
179
+ "canvas:Create new canvas": false,
180
+ "daily-notes:Open today's daily note": false,
181
+ "templates:Insert template": false,
182
+ "command-palette:Open command palette": false,
183
+ "bases:Create new base": false
184
+ }
185
+ },
186
+ "active": "445cbff87fecafda",
187
+ "lastOpenFiles": []
188
+ }
package/dist/index.cjs CHANGED
@@ -38,17 +38,6 @@ __export(index_exports, {
38
38
  });
39
39
  module.exports = __toCommonJS(index_exports);
40
40
 
41
- // src/nodes/helperFunctions.ts
42
- function hasMustacheTags(template) {
43
- return template.includes("{{") || template.includes("}}");
44
- }
45
- function hasDuplicates(arr) {
46
- return new Set(arr).size !== arr.length;
47
- }
48
-
49
- // src/nodes/replaceAllMustaches.ts
50
- var import_mustache = __toESM(require("mustache"), 1);
51
-
52
41
  // src/nodes/VariableView.ts
53
42
  var VariableView = class _VariableView {
54
43
  static _collection = [];
@@ -85,34 +74,41 @@ var VariableView = class _VariableView {
85
74
  }
86
75
  };
87
76
 
77
+ // src/nodes/helperFunctions.ts
78
+ function hasMustacheTags(template) {
79
+ return template.includes("{{") || template.includes("}}");
80
+ }
81
+ function hasDuplicates(arr) {
82
+ return new Set(arr).size !== arr.length;
83
+ }
84
+
88
85
  // src/nodes/replaceAllMustaches.ts
86
+ var import_mustache = __toESM(require("mustache"), 1);
89
87
  function replaceAllMustaches(template, { maxPasses = 20, detectCycles = true } = {}) {
90
88
  let current = template;
91
- const seen = /* @__PURE__ */ new Set();
92
- let pass = 0;
93
- for (pass; pass < maxPasses; pass += 1) {
89
+ let last = "";
90
+ for (let pass = 0; pass < maxPasses; pass += 1) {
94
91
  if (hasMustacheTags(current)) {
95
92
  if (detectCycles) {
96
- if (seen.has(current)) {
93
+ if (last === current) {
97
94
  throw new Error(`Render cycle detected at pass ${pass}: "${current}"`);
98
95
  }
99
96
  ;
100
- seen.add(current);
97
+ last = current;
101
98
  }
102
99
  ;
103
100
  const next = import_mustache.default.render(current, VariableView.all);
104
- if (next === current) {
105
- return next;
101
+ if (next !== "" && next === current) {
102
+ current = next;
103
+ } else {
104
+ return current;
106
105
  }
107
- ;
108
- current = next;
109
106
  } else {
110
107
  console.log("passes:", pass);
111
108
  return current;
112
109
  }
113
110
  }
114
111
  ;
115
- console.log("passes:", pass);
116
112
  return current;
117
113
  }
118
114
 
package/dist/index.d.cts CHANGED
@@ -10,6 +10,12 @@ type MustacheIterationOptions = {
10
10
  maxPasses?: number;
11
11
  detectCycles?: boolean;
12
12
  };
13
+ /**
14
+ * Replaces all mustache tokens recursively until there are none left that can be replaced.
15
+ * @param template
16
+ * @param param1
17
+ * @returns
18
+ */
13
19
  declare function replaceAllMustaches(template: string, { maxPasses, detectCycles }?: MustacheIterationOptions): string;
14
20
 
15
21
  type MustacheValue = string | string[] | Function;
package/dist/index.d.ts CHANGED
@@ -10,6 +10,12 @@ type MustacheIterationOptions = {
10
10
  maxPasses?: number;
11
11
  detectCycles?: boolean;
12
12
  };
13
+ /**
14
+ * Replaces all mustache tokens recursively until there are none left that can be replaced.
15
+ * @param template
16
+ * @param param1
17
+ * @returns
18
+ */
13
19
  declare function replaceAllMustaches(template: string, { maxPasses, detectCycles }?: MustacheIterationOptions): string;
14
20
 
15
21
  type MustacheValue = string | string[] | Function;
package/dist/index.js CHANGED
@@ -1,14 +1,3 @@
1
- // src/nodes/helperFunctions.ts
2
- function hasMustacheTags(template) {
3
- return template.includes("{{") || template.includes("}}");
4
- }
5
- function hasDuplicates(arr) {
6
- return new Set(arr).size !== arr.length;
7
- }
8
-
9
- // src/nodes/replaceAllMustaches.ts
10
- import Mustache from "mustache";
11
-
12
1
  // src/nodes/VariableView.ts
13
2
  var VariableView = class _VariableView {
14
3
  static _collection = [];
@@ -45,34 +34,41 @@ var VariableView = class _VariableView {
45
34
  }
46
35
  };
47
36
 
37
+ // src/nodes/helperFunctions.ts
38
+ function hasMustacheTags(template) {
39
+ return template.includes("{{") || template.includes("}}");
40
+ }
41
+ function hasDuplicates(arr) {
42
+ return new Set(arr).size !== arr.length;
43
+ }
44
+
48
45
  // src/nodes/replaceAllMustaches.ts
46
+ import Mustache from "mustache";
49
47
  function replaceAllMustaches(template, { maxPasses = 20, detectCycles = true } = {}) {
50
48
  let current = template;
51
- const seen = /* @__PURE__ */ new Set();
52
- let pass = 0;
53
- for (pass; pass < maxPasses; pass += 1) {
49
+ let last = "";
50
+ for (let pass = 0; pass < maxPasses; pass += 1) {
54
51
  if (hasMustacheTags(current)) {
55
52
  if (detectCycles) {
56
- if (seen.has(current)) {
53
+ if (last === current) {
57
54
  throw new Error(`Render cycle detected at pass ${pass}: "${current}"`);
58
55
  }
59
56
  ;
60
- seen.add(current);
57
+ last = current;
61
58
  }
62
59
  ;
63
60
  const next = Mustache.render(current, VariableView.all);
64
- if (next === current) {
65
- return next;
61
+ if (next !== "" && next === current) {
62
+ current = next;
63
+ } else {
64
+ return current;
66
65
  }
67
- ;
68
- current = next;
69
66
  } else {
70
67
  console.log("passes:", pass);
71
68
  return current;
72
69
  }
73
70
  }
74
71
  ;
75
- console.log("passes:", pass);
76
72
  return current;
77
73
  }
78
74
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "replace-all-mustaches",
3
- "version": "0.0.7",
3
+ "version": "0.0.9",
4
4
  "description": "Replace all mustache templates in a string, including recursive mustache values",
5
5
  "main": "./dist/index.js",
6
6
  "module": "./dist/index.mjs",
@@ -23,5 +23,13 @@
23
23
  "allowScripts": {
24
24
  "esbuild@0.27.7": true,
25
25
  "fsevents@2.3.3": true
26
- }
26
+ },
27
+ "repository": {
28
+ "type": "git",
29
+ "url": "git+https://github.com/jjkubik/replace-all-mustaches.git"
30
+ },
31
+ "bugs": {
32
+ "url": "https://github.com/jjkubik/replace-all-mustaches/issues"
33
+ },
34
+ "homepage": "https://github.com/jjkubik/replace-all-mustaches#readme"
27
35
  }
@@ -1,12 +1,18 @@
1
+ import { VariableView } from "./VariableView";
2
+
1
3
  /**
2
4
  * Confirm whether there are valid mustache tags remaining in the template string.
3
5
  * @param template
4
6
  * @returns
5
7
  */
6
8
  export function hasMustacheTags(template: string): boolean {
7
- return template.includes("{{") || template.includes("}}");
9
+ return template.includes("{{") || template.includes("}}")
8
10
  };
9
11
 
10
12
  export function hasDuplicates(arr:any[]){
11
13
  return new Set(arr).size !== arr.length;
14
+ };
15
+
16
+ function hasVariable(label:string){
17
+ return VariableView.allNames.includes(label);
12
18
  };
@@ -7,37 +7,42 @@ type MustacheIterationOptions = {
7
7
  detectCycles?: boolean;
8
8
  };
9
9
 
10
+ /**
11
+ * Replaces all mustache tokens recursively until there are none left that can be replaced.
12
+ * @param template
13
+ * @param param1
14
+ * @returns
15
+ */
10
16
  export function replaceAllMustaches(
11
17
  template: string,
12
18
  { maxPasses = 20, detectCycles = true }: MustacheIterationOptions = {},
13
19
  ): string {
14
20
  let current = template;
15
- const seen = new Set<string>();
21
+ let last = ""; // To ensure that the same token isn't replaced twice in a row
16
22
 
17
- let pass = 0
18
- for (pass; pass < maxPasses; pass += 1) {
19
- if (hasMustacheTags(current)){
20
- if (detectCycles) {
21
- if (seen.has(current)) {
23
+ for (let pass = 0; pass < maxPasses; pass += 1) {
24
+ if (hasMustacheTags(current)){ // If any {{}} remain...
25
+ if (detectCycles) { // If you check the number of cycles, which you do by default, throw an error and stop
26
+ if (last === current) {
22
27
  throw new Error(`Render cycle detected at pass ${pass}: "${current}"`);
23
28
  };
24
29
 
25
- seen.add(current);
30
+ last = current; // Now the string it's looping over will be checked next time
26
31
  };
27
32
 
28
33
  const next = Mustache.render(current, VariableView.all);
29
-
30
- if (next === current) {
31
- return next; // no more substitutions happened
32
- };
33
-
34
- current = next;
34
+
35
+ // If the string's not empty and it's not the same as the current string...
36
+ if (next !== "" && next === current){
37
+ current = next;
38
+ } else {
39
+ return current; // no more substitutions happened
40
+ }
35
41
  } else {
36
42
  console.log("passes:",pass)
37
43
  return current;
38
44
  }
39
45
  };
40
46
 
41
- console.log("passes:",pass)
42
47
  return current;
43
48
  };