Syntax fixes (#5367)

* Declare return types on functions

And a very few other type related minor fixes

* Minor syntax fixes

* Remove unnecessary escape chars in regexes
* Remove unnecessary awaits
* Replace deprecated req.connection with req.socket
* Replace deprecated upload with uploadOne
* Remove unnecessary eslint-disable-next-line comments
* Comment empty functions / catch or finally clauses
* Fix irregular whitespaces
* Add missing returns (null)
* Remove unreachable code
* A few logical fixes
* Remove / Handle non-null assertions which are certainly unnecessary (e.g. in
tests)
This commit is contained in:
Pascal Jufer
2021-04-29 18:11:43 +02:00
committed by GitHub
parent 40eba791fa
commit acd41eb0be
231 changed files with 646 additions and 527 deletions

View File

@@ -1,21 +1,28 @@
import { computed, Ref } from '@vue/composition-api';
import { computed, ComputedRef, Ref } from '@vue/composition-api';
import { render } from 'micromustache';
import { getFieldsFromTemplate } from './get-fields-from-template';
type StringTemplate = {
fieldsInTemplate: ComputedRef<string[]>;
displayValue: ComputedRef<string | false>;
};
export function renderStringTemplate(
template: Ref<string | null> | string,
item: Ref<Record<string, any> | undefined | null>
) {
): StringTemplate {
const templateString = computed(() => (typeof template === 'string' ? template : template.value));
const fieldsInTemplate = computed(() => getFieldsFromTemplate(templateString.value));
const displayValue = computed(() => {
if (!item.value || !templateString.value || !fieldsInTemplate.value) return;
if (!item.value || !templateString.value || !fieldsInTemplate.value) return false;
try {
return render(templateString.value, item.value, { propsExist: true });
} catch {}
} catch {
return false;
}
});
return { fieldsInTemplate, displayValue };