Tengo dificultades para crear una función genérica donde una entrada sería una cadena que contiene un volumen de texto grande o pequeño y la salida es una matriz y tengo muchos problemas con esta complejidad, pero cada posición de la matriz debe contener 125 caracteres como máximo y no puede tener una palabra rota, por ejemplo, si hay alguna palabra final con la que se debe pasar 125 caracteres a la siguiente posición de la matriz.
Ejemplo:
Valor de entrada: `var text =" Lorem Ipsum is simply a text simulation of the printing and printing industry, and has been in use since the 16th century, when an unknown printer took a tray of typefaces and shuffled them together to make a type model book Lorem Ipsum survived not only five centuries but also the leap into desktop publishing, remaining essentially unchanged It became popular in the 1960s when Letraset launched decals containing passages of Lorem Ipsum, and more recently when is now integrated with desktop editing software like Aldus PageMaker." `
Valor de salida incorrecto: `[ "Lorem Ipsum is simply a text simulation of the printing and printing industry, and it has been in use since the century," "XVI, when a printer discovered a type tray and shuffled them together to make a typeface template book."] `
Tenga en cuenta que la posición 0 de la matriz ha pasado de 125 debido a la palabra "siglo".
Valor de salida correcto: `[" Lorem Ipsum is simply a text simulation of the printing and printing industry, and has been in use since the "," 16th century, when an unknown printer took a tray of typefaces and shuffled them to make a book of models of "," types. Lorem Ipsum survived not only five centuries, but also the leap into desktop publishing, remaining ", ...]`
Puede usar la expresión regular .{1,125}\b que busca con avidez entre 1 y 125 caracteres seguidos de un límite de palabra:
const regex = /.{1,125}\b/g; var text =" Lorem Ipsum is simply a text simulation of the printing and printing industry, and has been in use since the 16th century, when an unknown printer took a tray of typefaces and shuffled them together to make a type model book Lorem Ipsum survived not only five centuries but also the leap into desktop publishing, remaining essentially unchanged It became popular in the 1960s when Letraset launched decals containing passages of Lorem Ipsum, and more recently when is now integrated with desktop editing software like Aldus PageMaker."; console.log(text.match(regex));