Added string splitter

merge-requests/1/merge
Bsian 2019-10-22 00:58:20 +01:00
parent 92e4ee5cc8
commit d082b7be70
No known key found for this signature in database
GPG Key ID: 097FB9A291026091
1 changed files with 20 additions and 1 deletions

View File

@ -1,7 +1,9 @@
import { promisify } from 'util';
/* eslint-disable no-param-reassign */
import { promisify, isArray } from 'util';
import childProcess from 'child_process';
import nodemailer from 'nodemailer';
import { Message, TextChannel, PrivateChannel } from 'eris';
import { outputFile } from 'fs-extra';
import { Client } from '.';
import { Command, RichEmbed } from './class';
@ -74,4 +76,21 @@ export default class Util {
}
return array;
}
public splitString(string: string, length: number): string[] {
if (!string) return [];
if (Array.isArray(string)) string = string.join('\n');
if (string.length <= length) return [string];
const arrayString: string[] = [];
let str: string = '';
let pos: number;
while (string.length > 0) {
pos = string.length > length ? string.lastIndexOf('\n', length) : outputFile.length;
if (pos > length) pos = length;
str = string.substr(0, pos);
string = string.substr(pos);
arrayString.push(str);
}
return arrayString;
}
}