/*! For license information please see 244167f1.8e071c9c.js.LICENSE.txt */
"use strict";(self.webpackChunkweb_totals=self.webpackChunkweb_totals||[]).push([[2731],{84757:(e,t,n)=>{n.r(t),n.d(t,{assets:()=>l,contentTitle:()=>a,default:()=>u,frontMatter:()=>i,metadata:()=>o,toc:()=>p});var s=n(85893),r=n(11151);const i={sidebar_position:2,title:"Split Text Utils",comment:!0,tags:["Javascript","Utils","Discord"]},a=void 0,o={id:"javascripts/split-text-utils",title:"Split Text Utils",description:"",source:"@site/issues/javascripts/split-text-utils.md",sourceDirName:"javascripts",slug:"/javascripts/split-text-utils",permalink:"/issues/javascripts/split-text-utils",draft:!1,unlisted:!1,editUrl:"https://github.com/hunghg255/web-totals/tree/main/issues/javascripts/split-text-utils.md",tags:[{label:"Javascript",permalink:"/issues/tags/javascript"},{label:"Utils",permalink:"/issues/tags/utils"},{label:"Discord",permalink:"/issues/tags/discord"}],version:"current",sidebarPosition:2,frontMatter:{sidebar_position:2,title:"Split Text Utils",comment:!0,tags:["Javascript","Utils","Discord"]},sidebar:"tutorialSidebar",previous:{title:"Random",permalink:"/issues/javascripts/1loc/random"},next:{title:"Sleep Sort",permalink:"/issues/javascripts/sort/sleep-sort"}},l={},p=[];function c(e){const t={code:"code",pre:"pre",...(0,r.a)(),...e.components};return(0,s.jsx)(t.pre,{children:(0,s.jsx)(t.code,{className:"language-js",children:"function verifyString(\n  data,\n  error = Error,\n  errorMessage = `Expected a string, got ${data} instead.`,\n  allowEmpty = true,\n) {\n  if (typeof data !== 'string') throw new error(errorMessage);\n  if (!allowEmpty && data.length === 0) throw new error(errorMessage);\n  return data;\n}\n\nlet deprecationEmittedForSplitMessage = false;\nfunction splitMessage(text, { maxLength = 2_000, char = '\\n', prepend = '', append = '' } = {}) {\n  if (!deprecationEmittedForSplitMessage) {\n    process.emitWarning(\n      'The Util.splitMessage method is deprecated and will be removed in the next major version.',\n      'DeprecationWarning',\n    );\n\n    deprecationEmittedForSplitMessage = true;\n  }\n\n  text = verifyString(text);\n  if (text.length <= maxLength) return [text];\n  let splitText = [text];\n  if (Array.isArray(char)) {\n    while (char.length > 0 && splitText.some((elem) => elem.length > maxLength)) {\n      const currentChar = char.shift();\n      if (currentChar instanceof RegExp) {\n        splitText = splitText.flatMap((chunk) => chunk.match(currentChar));\n      } else {\n        splitText = splitText.flatMap((chunk) => chunk.split(currentChar));\n      }\n    }\n  } else {\n    splitText = text.split(char);\n  }\n  if (splitText.some((elem) => elem.length > maxLength)) throw new RangeError('SPLIT_MAX_LEN');\n  const messages = [];\n  let msg = '';\n  for (const chunk of splitText) {\n    if (msg && (msg + char + chunk + append).length > maxLength) {\n      messages.push(msg + append);\n      msg = prepend;\n    }\n    msg += (msg && msg !== prepend ? char : '') + chunk;\n  }\n  return messages.concat(msg).filter((m) => m);\n}\n"})})}function u(e={}){const{wrapper:t}={...(0,r.a)(),...e.components};return t?(0,s.jsx)(t,{...e,children:(0,s.jsx)(c,{...e})}):c(e)}},75251:(e,t,n)=>{var s=n(67294),r=Symbol.for("react.element"),i=Symbol.for("react.fragment"),a=Object.prototype.hasOwnProperty,o=s.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED.ReactCurrentOwner,l={key:!0,ref:!0,__self:!0,__source:!0};function p(e,t,n){var s,i={},p=null,c=null;for(s in void 0!==n&&(p=""+n),void 0!==t.key&&(p=""+t.key),void 0!==t.ref&&(c=t.ref),t)a.call(t,s)&&!l.hasOwnProperty(s)&&(i[s]=t[s]);if(e&&e.defaultProps)for(s in t=e.defaultProps)void 0===i[s]&&(i[s]=t[s]);return{$$typeof:r,type:e,key:p,ref:c,props:i,_owner:o.current}}t.Fragment=i,t.jsx=p,t.jsxs=p},85893:(e,t,n)=>{e.exports=n(75251)},11151:(e,t,n)=>{n.d(t,{Z:()=>o,a:()=>a});var s=n(67294);const r={},i=s.createContext(r);function a(e){const t=s.useContext(i);return s.useMemo((function(){return"function"==typeof e?e(t):{...t,...e}}),[t,e])}function o(e){let t;return t=e.disableParentContext?"function"==typeof e.components?e.components(r):e.components||r:a(e.components),s.createElement(i.Provider,{value:t},e.children)}}}]);