Skip to content
Snippets Groups Projects
utils.js 340 B
Newer Older
// utils.js

/**
 * Split long string into several chunks based on given size
 * @param {string} str string to chunk
 * @param {number} size newly created string max length
 * @returns {Array<string>}
 */
export const chunkString = (str, size) => {
  if (!str) {
    return []
  }
  return str.match(new RegExp('.{1,' + size + '}', 'g'))
}