-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgenerateTextFile.ts
More file actions
34 lines (28 loc) · 903 Bytes
/
generateTextFile.ts
File metadata and controls
34 lines (28 loc) · 903 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
import fs from "fs";
export default class GenerateTextFile {
constructor() {
}
public splitTextFile(): string[] {
const str = fs.readFileSync(`./whole-story-text/${this.getLatestStory()}/1.txt`);
return this.yourSplit(10, str.toString().replace(/\'/g, ''))
}
public getLatestStory(): number {
return fs.readdirSync('./whole-story-text').length;
}
public yourSplit (N,string) {
var app=string.split(' '),
arrayApp=[],
stringApp="";
app.forEach(function(sentence,index){
stringApp+=sentence+' ';
if((index+1)%N===0){
arrayApp.push(stringApp);
stringApp='';
}else if(app.length===index+1 && stringApp!==''){
arrayApp.push(stringApp);
stringApp='';
}
});
return arrayApp;
};
}