Added string splitter
parent
92e4ee5cc8
commit
d082b7be70
21
src/Util.ts
21
src/Util.ts
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue