-
Notifications
You must be signed in to change notification settings - Fork 2
Add(concat): prefix and suffix options (fix #48) #57
base: master
Are you sure you want to change the base?
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
{ | ||
"git.ignoreLimitWarning": true | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
console.log("this is opts js") |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -18,7 +18,35 @@ export const config = { | |
|
||
/** | ||
* We don't need to do any real transformation. | ||
* | ||
* suffix and prefix features | ||
* @param suffix || null @param prefix || null | ||
* appending additional suffix and prefix to each data. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This JSDoc comment is incorrect:
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. So if i add the comment like: /**
* options assign
* @param suffix adding string at the end of the each file
* @param prefix adding string at the beginning of the first packet
*/
var opts = Object.assign({}, ctx.args[0] || {}) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The opts i will fix it |
||
*/ | ||
export default async (ctx, data) => { | ||
/** | ||
* unexpected num of arguments handling | ||
*/ | ||
if (ctx.args.length > 1) { | ||
throw new Error('Unexpected numbers of arguments.') | ||
} | ||
|
||
/** | ||
* options assign | ||
*/ | ||
var opts = Object.assign({}, ctx.args[0] || {}) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is only necessary if you are going to modify the opts object, which you aren't. Since you are not modifying the opts, you can just do this: Also avoid using There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If i changed to There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. (y) |
||
|
||
// suffix | ||
if (opts.suffix) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Prefix should only be added if this data packet is the first packet (which it will not always be). Check if it is the first data piece before adding a prefix. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. How do i know how many packets are coming, can i modified the ctx which will store a count? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There's no way to know how many packets but you don't need a count. You just need to know what the first one is & what the last one is. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I feel stupid, which props i can check is the first or the last? |
||
data.size += opts.suffix.length | ||
data.body = Buffer.from(opts.suffix + data.body.toString()) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Providing a Buffer is unnecessary. You can just provide a string like this:
|
||
} | ||
|
||
// prefix | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Prefix should be before data and suffix should be after. |
||
if (opts.prefix) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Suffix should only be added if |
||
data.size += opts.prefix.length | ||
data.body = Buffer.from(data.body.toString() + opts.prefix) | ||
} | ||
|
||
return data | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The
.vscode
folder should not be pushed to git. Remove this & add it to the .gitignore in the root directory.