You can easily modify, add, check for a specific text or delete the entire txt file content, without complications.
npm i simple-txt
const stxt = require("simple-txt")
const txt = new stxt('test'); // file name
index.js
txt.set('hello world'); // true
index.js
txt.get(); // hello world
index.js
txt.add('hello');
txt.add('world');
test.txt
hello
world
index.js
txt.add('hello');
txt.add('world', 'no');
test.txt
hello world
index.js
txt.add('hello');
txt.add('world', 'top');
test.txt
world
hello
test.txt
world
hello
index.js
txt.has('world'); // true
test.txt
world
hello
index.js
txt.has('world','index'); // 7
or
txt.has('world','i'); // 7
test.txt
hello tomas
index.js
txt.replace('tomas','world'); // true
test.txt
hello world
Replace (regex flags, click here to learn javaScript RegExp)
test.txt
hello ToMAs
hi tomas
txt.replace('tomas','world', 'gi');
test.txt
hello world
hi world
test.txt
hello world
index.js
txt.length(); // 11
test.txt
hello world
index.js
txt.length('word'); // 2
or
txt.length('w'); // 2
test.txt
1| hello
2| world
3| ..
4| bye
index.js
txt.length('line'); // 4
or
txt.length('l'); // 4
index.js
txt.clear(); // true
Copyright © 2023 Mustafa ALGhanim - Mr Dark