nspragg / filesurgeon Goto Github PK
View Code? Open in Web Editor NEWManipulate text files the easy way
License: MIT License
Manipulate text files the easy way
License: MIT License
Add error handling for input that does not contain newlines i.e breaks newline stream reader
Is it possible to add .get(line)
to retrieve a specific line?
Cool module.
It seems that the documentation is not up to date in regards to edit, as edit is not static.
The current edit examples look like this:
import FileSurgeon from 'FileSurgeon';
const contents = FileSurgeon.edit(filename)
.set(1, line)
.filter(fn)
.map(fn)
.preview(); // writes changes to stdout
They should be like this:
import FileSurgeon from 'FileSurgeon';
const fileSurgeon = new FileSurgeon(filename)
const contents = fileSurgeon.edit()
.set(1, line)
.filter(fn)
.map(fn)
.preview(); // writes changes to stdout
Alternatively the call can be handled as follows:
import FileSurgeon from 'FileSurgeon';
const fileSurgeon = FileSurgeon.create(filename)
fileSurgeon
.edit()
.set(1, line)
.filter(fn)
.map(fn)
.preview(); // writes changes to stdout
As a matter of interest, why is edit the only method that is not static? Why are the other methods static?
When using FileSurgeon to create a new file an error is thrown when .save()
is called.
If the file does not exist it is created.
The following error is thrown:
Error: ENOENT: no such file or directory, open 'C:\dev\wtf\vue-msal\dist\index.js'
Emitted 'error' event at:
at lazyFs.open (internal/fs/streams.js:115:12)
at FSReqWrap.oncomplete (fs.js:139:20)
A temp file is created, but it is empty.
const destPath = 'my-tet-file.txt';
const fileSurgeon = FileSurgeon.create(destPath).edit();
fileSurgeon.append('Line 1');
fileSurgeon.append('Line 2');
fileSurgeon.save();
As a workaround I have created an empty file with the following function:
function createEmptyFile (filePath) {
fs.closeSync(fs.openSync(filePath, 'w'))
}
If the function is called before .save()
it works.
I also tried using .saveAs(destPath)
and it throw the same error.
Windows 10
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.