replace-all-mustaches 0.0.6 → 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 +15 -16
- package/dist/index.d.cts +12 -6
- package/dist/index.d.ts +12 -6
- package/dist/index.js +15 -16
- package/package.json +10 -2
- package/src/nodes/helperFunctions.ts +7 -1
- package/src/nodes/replaceAllMustaches.ts +11 -6
|
@@ -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,8 +74,17 @@ 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
|
|
89
|
-
|
|
86
|
+
var import_mustache = __toESM(require("mustache"), 1);
|
|
87
|
+
function replaceAllMustaches(template, { maxPasses = 20, detectCycles = true } = {}) {
|
|
90
88
|
let current = template;
|
|
91
89
|
const seen = /* @__PURE__ */ new Set();
|
|
92
90
|
let pass = 0;
|
|
@@ -101,11 +99,12 @@ function replaceAllMustaches(template, view, { maxPasses = 20, detectCycles = tr
|
|
|
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
|
@@ -6,6 +6,18 @@
|
|
|
6
6
|
declare function hasMustacheTags(template: string): boolean;
|
|
7
7
|
declare function hasDuplicates(arr: any[]): boolean;
|
|
8
8
|
|
|
9
|
+
type MustacheIterationOptions = {
|
|
10
|
+
maxPasses?: number;
|
|
11
|
+
detectCycles?: boolean;
|
|
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
|
+
*/
|
|
19
|
+
declare function replaceAllMustaches(template: string, { maxPasses, detectCycles }?: MustacheIterationOptions): string;
|
|
20
|
+
|
|
9
21
|
type MustacheValue = string | string[] | Function;
|
|
10
22
|
/**
|
|
11
23
|
* A key-value pair for a variable name and its value.
|
|
@@ -30,10 +42,4 @@ declare class VariableView {
|
|
|
30
42
|
replace(variableKey: string, value: string | Function): void;
|
|
31
43
|
}
|
|
32
44
|
|
|
33
|
-
type MustacheIterationOptions = {
|
|
34
|
-
maxPasses?: number;
|
|
35
|
-
detectCycles?: boolean;
|
|
36
|
-
};
|
|
37
|
-
declare function replaceAllMustaches(template: string, view: VariableView, { maxPasses, detectCycles }?: MustacheIterationOptions): string;
|
|
38
|
-
|
|
39
45
|
export { type MustacheValue, Variable, VariableView, hasDuplicates, hasMustacheTags, replaceAllMustaches };
|
package/dist/index.d.ts
CHANGED
|
@@ -6,6 +6,18 @@
|
|
|
6
6
|
declare function hasMustacheTags(template: string): boolean;
|
|
7
7
|
declare function hasDuplicates(arr: any[]): boolean;
|
|
8
8
|
|
|
9
|
+
type MustacheIterationOptions = {
|
|
10
|
+
maxPasses?: number;
|
|
11
|
+
detectCycles?: boolean;
|
|
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
|
+
*/
|
|
19
|
+
declare function replaceAllMustaches(template: string, { maxPasses, detectCycles }?: MustacheIterationOptions): string;
|
|
20
|
+
|
|
9
21
|
type MustacheValue = string | string[] | Function;
|
|
10
22
|
/**
|
|
11
23
|
* A key-value pair for a variable name and its value.
|
|
@@ -30,10 +42,4 @@ declare class VariableView {
|
|
|
30
42
|
replace(variableKey: string, value: string | Function): void;
|
|
31
43
|
}
|
|
32
44
|
|
|
33
|
-
type MustacheIterationOptions = {
|
|
34
|
-
maxPasses?: number;
|
|
35
|
-
detectCycles?: boolean;
|
|
36
|
-
};
|
|
37
|
-
declare function replaceAllMustaches(template: string, view: VariableView, { maxPasses, detectCycles }?: MustacheIterationOptions): string;
|
|
38
|
-
|
|
39
45
|
export { type MustacheValue, Variable, VariableView, hasDuplicates, hasMustacheTags, replaceAllMustaches };
|
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,8 +34,17 @@ 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
|
|
49
|
-
|
|
46
|
+
import Mustache from "mustache";
|
|
47
|
+
function replaceAllMustaches(template, { maxPasses = 20, detectCycles = true } = {}) {
|
|
50
48
|
let current = template;
|
|
51
49
|
const seen = /* @__PURE__ */ new Set();
|
|
52
50
|
let pass = 0;
|
|
@@ -61,11 +59,12 @@ function replaceAllMustaches(template, view, { maxPasses = 20, detectCycles = tr
|
|
|
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,9 +7,14 @@ 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
|
-
view: VariableView,
|
|
13
18
|
{ maxPasses = 20, detectCycles = true }: MustacheIterationOptions = {},
|
|
14
19
|
): string {
|
|
15
20
|
let current = template;
|
|
@@ -28,11 +33,11 @@ export function replaceAllMustaches(
|
|
|
28
33
|
|
|
29
34
|
const next = Mustache.render(current, VariableView.all);
|
|
30
35
|
|
|
31
|
-
if (next
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
+
if (next !== ""){
|
|
37
|
+
if (next === current) {
|
|
38
|
+
return current; // no more substitutions happened
|
|
39
|
+
};
|
|
40
|
+
}
|
|
36
41
|
} else {
|
|
37
42
|
console.log("passes:",pass)
|
|
38
43
|
return current;
|