simple-txt
v8.1.3
Published
You can easily modify, add, check for a specific text or delete the entire txt file content, without complications.
Downloads
11
Maintainers
Readme
You can easily modify, add, check for a specific text or delete the entire txt file content, without complications.
Installation
npm i simple-txt
Setup
const stxt = require("simple-txt")
const txt = new stxt('test'); // file name
Set:
index.js
txt.set('hello world'); // true
Get:
index.js
txt.get(); // hello world
Add (default)
index.js
txt.add('hello');
txt.add('world');
Result:
test.txt
hello
world
Add (no)
index.js
txt.add('hello');
txt.add('world', 'no');
Result:
test.txt
hello world
Add (top)
index.js
txt.add('hello');
txt.add('world', 'top');
Result:
test.txt
world
hello
Has (default)
test.txt
world
hello
index.js
txt.has('world'); // true
Has (index)
test.txt
world
hello
index.js
txt.has('world','index'); // 7
or
txt.has('world','i'); // 7
Replace (default)
test.txt
hello tomas
index.js
txt.replace('tomas','world'); // true
Result:
test.txt
hello world
Replace (regex flags, click here to learn javaScript RegExp)
test.txt
hello ToMAs
hi tomas
txt.replace('tomas','world', 'gi');
Result:
test.txt
hello world
hi world
Length (default)
test.txt
hello world
index.js
txt.length(); // 11
Length (word)
test.txt
hello world
index.js
txt.length('word'); // 2
or
txt.length('w'); // 2
Length (line)
test.txt
1| hello
2| world
3| ..
4| bye
index.js
txt.length('line'); // 4
or
txt.length('l'); // 4
Clear
index.js
txt.clear(); // true
Support
Click here to suggestion or report bug.
Copyright © 2023 Mustafa ALGhanim - Mr Dark