Splitting Text
This commit is contained in:
1 parent
3152f26760
commit
ce2237c73d
1 file changed
+27
-3
+27
-3
@@ -14,7 +14,7 @@ function dynamicDecimals(value, minDecimals) {
|
||||
}
|
||||
let decimals = 0
|
||||
if (value < 1) { decimals = 2 }
|
||||
|
||||
|
||||
if (Math.abs(Math.trunc(value * 10)) < 1) { decimals = 4 }
|
||||
if (Math.abs(Math.trunc(value * 100)) < 1) { decimals = 5 }
|
||||
if (Math.abs(Math.trunc(value * 1000)) < 1) { decimals = 6 }
|
||||
@@ -24,8 +24,8 @@ function dynamicDecimals(value, minDecimals) {
|
||||
if (Math.abs(Math.trunc(value * 10000000)) < 1) { decimals = 10 }
|
||||
if (Math.abs(Math.trunc(value * 100000000000)) < 1) { value = 0; decimals = 0 }
|
||||
|
||||
if (decimals < minDecimals) {decimals = minDecimals}
|
||||
|
||||
if (decimals < minDecimals) { decimals = minDecimals }
|
||||
|
||||
let returnValue = Number(value).toFixed(decimals)
|
||||
return returnValue
|
||||
}
|
||||
@@ -99,3 +99,27 @@ function newUniqueId() {
|
||||
return v.toString(16)
|
||||
})
|
||||
}
|
||||
|
||||
function splitTextIntoPhrases(text, wordsPerLine) {
|
||||
let splittedLabel = text.split(' ')
|
||||
let phrases = []
|
||||
let phrase = ''
|
||||
let wordCount = 0
|
||||
for (let i = 0; i < splittedLabel.length; i++) {
|
||||
phrase = phrase + splittedLabel[i]
|
||||
wordCount++
|
||||
|
||||
if (i < splittedLabel.length - 1 && wordCount < wordsPerLine) {
|
||||
phrase = phrase + ' '
|
||||
}
|
||||
if (wordCount >= wordsPerLine) {
|
||||
phrases.push(phrase)
|
||||
phrase = ''
|
||||
wordCount = 0
|
||||
}
|
||||
}
|
||||
if (wordCount > 0) {
|
||||
phrases.push(phrase)
|
||||
}
|
||||
return phrases
|
||||
}
|
||||
Reference in new issue
Block a user