Add template functions: strlen, round (#265)

This commit is contained in:
metal 2021-09-04 17:14:33 +01:00 committed by GitHub
parent d5da50c0ed
commit e73d6d4e1c
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -388,6 +388,10 @@ const baseValues = {
ucfirst(arg) {
return baseValues.upperFirst(arg);
},
strlen(arg) {
if (typeof arg !== "string") return 0;
return [...arg].length;
},
rand(from, to, seed = null) {
if (isNaN(from)) return 0;
@ -406,6 +410,10 @@ const baseValues = {
return Math.round(randValue * (to - from) + from);
},
round(arg, decimals = 0) {
if (isNaN(arg)) return 0;
return decimals === 0 ? Math.round(arg) : arg.toFixed(decimals);
},
add(...args) {
return args.reduce((result, arg) => {
if (isNaN(arg)) return result;