replace-all-mustaches 0.0.7 → 0.0.8
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/.obsidian/app.json +1 -0
- package/.obsidian/appearance.json +1 -0
- package/.obsidian/core-plugins.json +33 -0
- package/.obsidian/workspace.json +188 -0
- package/dist/index.cjs +14 -15
- package/dist/index.d.cts +6 -0
- package/dist/index.d.ts +6 -0
- package/dist/index.js +14 -15
- package/package.json +10 -2
- package/src/nodes/helperFunctions.ts +7 -1
- package/src/nodes/replaceAllMustaches.ts +11 -5
|
@@ -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,7 +74,16 @@ 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
89
|
const seen = /* @__PURE__ */ new Set();
|
|
@@ -101,11 +99,12 @@ function replaceAllMustaches(template, { maxPasses = 20, detectCycles = true } =
|
|
|
101
99
|
}
|
|
102
100
|
;
|
|
103
101
|
const next = import_mustache.default.render(current, VariableView.all);
|
|
104
|
-
if (next
|
|
105
|
-
|
|
102
|
+
if (next !== "") {
|
|
103
|
+
if (next === current) {
|
|
104
|
+
return current;
|
|
105
|
+
}
|
|
106
|
+
;
|
|
106
107
|
}
|
|
107
|
-
;
|
|
108
|
-
current = next;
|
|
109
108
|
} else {
|
|
110
109
|
console.log("passes:", pass);
|
|
111
110
|
return current;
|
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,7 +34,16 @@ 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
49
|
const seen = /* @__PURE__ */ new Set();
|
|
@@ -61,11 +59,12 @@ function replaceAllMustaches(template, { maxPasses = 20, detectCycles = true } =
|
|
|
61
59
|
}
|
|
62
60
|
;
|
|
63
61
|
const next = Mustache.render(current, VariableView.all);
|
|
64
|
-
if (next
|
|
65
|
-
|
|
62
|
+
if (next !== "") {
|
|
63
|
+
if (next === current) {
|
|
64
|
+
return current;
|
|
65
|
+
}
|
|
66
|
+
;
|
|
66
67
|
}
|
|
67
|
-
;
|
|
68
|
-
current = next;
|
|
69
68
|
} else {
|
|
70
69
|
console.log("passes:", pass);
|
|
71
70
|
return current;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "replace-all-mustaches",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.8",
|
|
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,6 +7,12 @@ 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 = {},
|
|
@@ -27,11 +33,11 @@ export function replaceAllMustaches(
|
|
|
27
33
|
|
|
28
34
|
const next = Mustache.render(current, VariableView.all);
|
|
29
35
|
|
|
30
|
-
if (next
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
36
|
+
if (next !== ""){
|
|
37
|
+
if (next === current) {
|
|
38
|
+
return current; // no more substitutions happened
|
|
39
|
+
};
|
|
40
|
+
}
|
|
35
41
|
} else {
|
|
36
42
|
console.log("passes:",pass)
|
|
37
43
|
return current;
|