Socket
Socket
Sign inDemoInstall

update-section

Package Overview
Dependencies
Maintainers
1
Versions
8
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

update-section - npm Package Compare versions

Comparing version 0.2.0 to 0.3.0

2

package.json
{
"name": "update-section",
"version": "0.2.0",
"version": "0.3.0",
"description": "Updates a section inside a file with newer content while removing the old content.",

@@ -5,0 +5,0 @@ "main": "update-section.js",

@@ -105,3 +105,3 @@ # update-section [![build status](https://secure.travis-ci.org/thlorenz/update-section.png)](http://travis-ci.org/thlorenz/update-section)

<dt>
<h4 class="name" id="updateSection"><span class="type-signature"></span>updateSection<span class="signature">(content, section, matchesStart, matchesEnd)</span><span class="type-signature"> &rarr; {String}</span></h4>
<h4 class="name" id="updateSection"><span class="type-signature"></span>updateSection<span class="signature">(content, section, matchesStart, matchesEnd, top)</span><span class="type-signature"> &rarr; {String}</span></h4>
</dt>

@@ -152,2 +152,9 @@ <dd>

</tr>
<tr>
<td class="name"><code>top</code></td>
<td class="type">
<span class="param-type">boolean</span>
</td>
<td class="description last"><p>forces the section to be added at the top of the content if a replacement couldn't be made</p></td>
</tr>
</tbody>

@@ -154,0 +161,0 @@ </table>

@@ -169,2 +169,34 @@ 'use strict';

test('\nno start or end force top', function (t) {
var original = [
'# Some Project'
, ''
, 'Does a bunch of things'
, ''
, '#The End'
, ''
, 'Til next time'
].join('\n');
var expected = [
'START -- GENERATED GOODNESS',
'this was painstakingly re-generated',
'and we added another line',
'here',
'END -- GENERATED GOODNESS',
'',
'# Some Project',
'',
'Does a bunch of things',
'',
'#The End',
'',
'Til next time']
var updated = updateSection(original, update, matchesStart, matchesEnd, true);
t.deepEqual(expected, updated.split('\n'))
t.end()
})
test('\nempty string', function (t) {

@@ -171,0 +203,0 @@ var original = '';

@@ -56,5 +56,6 @@ 'use strict';

* @param {Function} matchesEnd when called with a line needs to return true iff it is the section end line
* @param {boolean} top forces the section to be added at the top of the content if a replacement couldn't be made
* @return {String} content with updated section
*/
exports = module.exports = function updateSection(content, section, matchesStart, matchesEnd) {
exports = module.exports = function updateSection(content, section, matchesStart, matchesEnd, top) {
if (!content) return section;

@@ -68,3 +69,3 @@

// no previous section found in content not just append
if (!info.hasStart) return content + '\n\n' + section;
if (!info.hasStart) return top ? section + '\n\n' + content : content + '\n\n' + section;

@@ -71,0 +72,0 @@ var sectionLines = section.split('\n')

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc