@ulisesgascon/text-tags-manager
v2.0.0
Published
Utils to manage text tags more easy to use, you know what I mean
Downloads
16
Maintainers
Readme
About
Utils to manage text tags more easy to use, you know what I mean
❤️ Awesome Features:
- Simple and easy to use 🔥
- Typescript support 💪
- Zero dependencies 🚀
- Easy to use and great test coverage ✅
Installation
npm install @ulisesgascon/text-tags-manager
Usage
Simple example
Importation
const { updateOrCreateSegment } = require("@ulisesgascon/text-tags-manager");
import { updateOrCreateSegment } from "@ulisesgascon/text-tags-manager";
Replace content
Original state:
sample_file.md
This text should remind the same...
<!-- MY-TAG:START -->
The old text
<!-- MY-TAG:END -->
This text will be also unaffected
Transformation:
const { readFile, writeFile } = require("fs").promises;
const replacementSegment =
"This is my new text, you know... the same but more cool!";
const startTag = "<!-- MY-TAG:START -->";
const endTag = "<!-- MY-TAG:END -->";
// Update
const originalText = await readFile("./sample_file.md");
const updatedContent = updateOrCreateSegment({
original: originalText,
replacementSegment,
startTag,
endTag,
});
await writeFile("./sample_file.md", updatedContent);
// Create
const newContent = updateOrCreateSegment({
original: "", // Simulate empty content with an empty string
replacementSegment,
startTag,
endTag,
});
await writeFile("./new_file.md", newContent);
Output:
new_file.md
<!-- MY-TAG:START -->
This is my new text, you know... the same but more cool!
<!-- MY-TAG:END -->
sample_file.md
This text should remind the same...
<!-- MY-TAG:START -->
This is my new text, you know... the same but more cool!
<!-- MY-TAG:END -->
This text will be also unaffected
Contributing
Please read CONTRIBUTING.md for details on our code of conduct, and the process for submitting pull requests to us.
Versioning
We use SemVer for versioning. For the versions available, see the tags on this repository.
Authors
- Ulises Gascón - Initial work- - @ulisesGascon
See also the list of contributors who participated in this project.
License
This project is licensed under the MIT License - see the LICENSE.md file for details
Acknowledgments
- This project is under development, but you can help us to improve it! We :heart: FOSS!