English
File size: 544 Bytes
a1b5703
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
const fs = require('fs');

function tokenizeText(text) {
  return text.split(/([\s,.!?:;()*-])/).filter(token => token.trim() !== '');
}


fs.readFile('text.txt', 'utf8', (err, data) => {
  if (err) {
    console.error('Error reading file:', err);
    return;
  }

  const tokens = tokenizeText(data);

  const jsonData = JSON.stringify(tokens);

  fs.writeFile('tokens.json', jsonData, (err) => {
    if (err) {
      console.error('Error writing file:', err);
    } else {
      console.log('Tokens written to tokens.json');
    }
  });
});