From e615ff7cf7a07f224a4f542422b1c3bbd20179f7 Mon Sep 17 00:00:00 2001 From: Denys Date: Wed, 29 Jun 2022 14:26:03 +0300 Subject: [PATCH] build: Add standard-version updater for README --- scripts/standardVersionUpdater.js | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) create mode 100644 scripts/standardVersionUpdater.js diff --git a/scripts/standardVersionUpdater.js b/scripts/standardVersionUpdater.js new file mode 100644 index 0000000..de45abb --- /dev/null +++ b/scripts/standardVersionUpdater.js @@ -0,0 +1,22 @@ +const START_KEY_SENTENCE = 'https://img.shields.io/badge/version-'; +const END_KEY_SENTENCE = '-green.svg'; + +function getVersion(content) { + const startIndex = content.indexOf(START_KEY_SENTENCE) + START_KEY_SENTENCE.length; + const endIndex = content.indexOf(END_KEY_SENTENCE); + + return content.slice(startIndex, endIndex); +} + +module.exports.readVersion = function (content) { + return getVersion(content); +}; + +module.exports.writeVersion = function (content, newVersion) { + const oldVersion = getVersion(content); + + return content.replace( + `${START_KEY_SENTENCE}${oldVersion}${END_KEY_SENTENCE}`, + `${START_KEY_SENTENCE}${newVersion}${END_KEY_SENTENCE}`, + ); +};