topkat-utils 1.0.45 → 1.0.46
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 +3 -0
- package/package.json +1 -1
- package/utils.ts +4 -2
package/CHANGELOG.md
CHANGED
package/package.json
CHANGED
package/utils.ts
CHANGED
|
@@ -125,6 +125,7 @@ function sortUrlsByDeepnessInArrayOrObject(urlObjOrArr, propInObjectOrIndexInArr
|
|
|
125
125
|
type MiniTemplaterOptions = {
|
|
126
126
|
valueWhenNotSet?: string
|
|
127
127
|
regexp?: RegExp
|
|
128
|
+
valueWhenContentUndefined?: string
|
|
128
129
|
}
|
|
129
130
|
/** Replace variables in a string like: `Hello {{userName}}!`
|
|
130
131
|
* @param {String} content
|
|
@@ -133,13 +134,14 @@ type MiniTemplaterOptions = {
|
|
|
133
134
|
* * valueWhenNotSet => replacer for undefined values. Default: ''
|
|
134
135
|
* * regexp => must be 'g' and first capturing group matching the value to replace. Default: /{{\s*([^}]*)\s*}}/g
|
|
135
136
|
*/
|
|
136
|
-
function miniTemplater(content: string, varz: ObjectGeneric, options: MiniTemplaterOptions = {}) {
|
|
137
|
+
function miniTemplater(content: string, varz: ObjectGeneric, options: MiniTemplaterOptions = {}): string {
|
|
137
138
|
options = {
|
|
138
139
|
valueWhenNotSet: '',
|
|
139
140
|
regexp: /{{\s*([^}]*)\s*}}/g,
|
|
141
|
+
valueWhenContentUndefined: '',
|
|
140
142
|
...options,
|
|
141
143
|
};
|
|
142
|
-
return content.replace(options.regexp, (m, $1) => isset(varz[$1]) ? varz[$1] : options.valueWhenNotSet)
|
|
144
|
+
return isset(content) ? content.replace(options.regexp, (m, $1) => isset(varz[$1]) ? varz[$1] : options.valueWhenNotSet) : options.valueWhenContentUndefined
|
|
143
145
|
}
|
|
144
146
|
|
|
145
147
|
/**
|