mirror of
https://github.com/ZeppelinBot/Zeppelin.git
synced 2025-03-18 15:00:00 +00:00
Add template functions: strlen, round (#265)
This commit is contained in:
parent
d5da50c0ed
commit
e73d6d4e1c
1 changed files with 8 additions and 0 deletions
|
@ -388,6 +388,10 @@ const baseValues = {
|
||||||
ucfirst(arg) {
|
ucfirst(arg) {
|
||||||
return baseValues.upperFirst(arg);
|
return baseValues.upperFirst(arg);
|
||||||
},
|
},
|
||||||
|
strlen(arg) {
|
||||||
|
if (typeof arg !== "string") return 0;
|
||||||
|
return [...arg].length;
|
||||||
|
},
|
||||||
rand(from, to, seed = null) {
|
rand(from, to, seed = null) {
|
||||||
if (isNaN(from)) return 0;
|
if (isNaN(from)) return 0;
|
||||||
|
|
||||||
|
@ -406,6 +410,10 @@ const baseValues = {
|
||||||
|
|
||||||
return Math.round(randValue * (to - from) + from);
|
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) {
|
add(...args) {
|
||||||
return args.reduce((result, arg) => {
|
return args.reduce((result, arg) => {
|
||||||
if (isNaN(arg)) return result;
|
if (isNaN(arg)) return result;
|
||||||
|
|
Loading…
Add table
Reference in a new issue