New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

split-md

Package Overview
Dependencies
Maintainers
2
Versions
5
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

split-md - npm Package Compare versions

Comparing version 0.2.0 to 0.3.0

tests/splitterWithCounter.test.js

6

package.json
{
"name": "split-md",
"version": "0.2.0",
"description": "split up Markdown file into smallers files",

@@ -53,3 +52,4 @@ "main": "src/index.js",

"split-md": "src/index.js"
}
}
},
"version": "0.3.0"
}

@@ -25,2 +25,3 @@ [![travis build](https://img.shields.io/travis/accraze/split-md.svg)](https://travis-ci.org/accraze/split-md)

* limit (optionally limit the number of files created)
* hasCounter (optionally have the outputted files names be numbered)

@@ -30,6 +31,6 @@ #### Example

```
$ split-md 'tests/testdata.md' '### v' '###' '' 10
$ split-md 'tests/testdata.md' '### v' '###' '' 10 true
```
In the above example we are reading in `tests/testdata.md`. Our delimiter is whenever we see a line start with the pattern `### v`. We want to use this line for our new markdown file's name, however we want to remove the `###` by setting it as the cleanName variable. Lastly, we are setting the `writePath` to our current working directory by giving an empty string as the last variable. Also note that we are setting our limit to only create 10 files before exiting.
In the above example we are reading in `tests/testdata.md`. Our delimiter is whenever we see a line start with the pattern `### v`. We want to use this line for our new markdown file's name, however we want to remove the `###` by setting it as the cleanName variable. Next, we are setting the `writePath` to our current working directory by giving an empty string as this variable. Also note that we are setting our limit to only create 10 files before exiting. Lastly, we have `true` to show that we want the file names to be ordered.

@@ -36,0 +37,0 @@ ## License:

@@ -5,2 +5,2 @@ #!/usr/bin/env node

splitter(cli.args[0],cli.args[1],cli.args[2],cli.args[3],cli.args[4])
splitter(cli.args[0],cli.args[1],cli.args[2],cli.args[3],cli.args[4],cli.args[5])

@@ -5,3 +5,3 @@ var fs = require('fs');

function splitter(readPath, pattern, cleanName, writePath, limit){
function splitter(readPath, pattern, cleanName, writePath, limit, hasCounter){
try {

@@ -15,2 +15,3 @@ var array = fs.readFileSync(readPath).toString().split("\n");

var counter = 1;
for(var i=0; i < array.length; i++) {

@@ -30,5 +31,10 @@ if (first) {

}
title = writePath + array[i].replace(cleanName, "").trim()
var fileName = array[i].replace(cleanName, "").trim();
if (fileName.length <= 0) {
fileName = "<empty-filename>";
}
title = hasCounter ? writePath + counter + "-" + fileName : title = writePath + fileName;
title = title.replace(":", "").replace(" ", "") + ".md"
console.log(title)
file += array[i];

@@ -48,3 +54,1 @@ first = false;

}
### v0.0.1
Hey bro! Whats up...
Hey friend! Whats up...
not much. you?

@@ -15,1 +15,6 @@

is the best song by R Kelly.
###
Some more text,
in an empty file name.

Sorry, the diff of this file is not supported yet

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