-
Notifications
You must be signed in to change notification settings - Fork 36
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Add possibility to provide onSuccess function (#53)
- Loading branch information
1 parent
be18847
commit 1cb7fab
Showing
10 changed files
with
1,426 additions
and
448 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
const chunkifyArray = (messageLines, maxLength, delimiter) => { | ||
delimiter = delimiter || '\n' | ||
|
||
let message = '' | ||
const resultLines = [] | ||
messageLines.forEach(line => { | ||
// the next chunk is made up of the (next) line and the delimiter | ||
let nextChunk = line + delimiter | ||
// if the message plus the next chunk puts us over the maxLength limit... | ||
if ((message + nextChunk).length > maxLength) { | ||
// ...we add the message to the result array... | ||
resultLines.push(message.trimEnd()) | ||
// ...and "reset" the message with the next chunk. | ||
message = nextChunk | ||
} else { | ||
// if not, we add the next chunk to the message | ||
message += nextChunk | ||
} | ||
}) | ||
|
||
// handle the case where we have a trailing message | ||
if (message.length > 0) { | ||
resultLines.push(message.trimEnd()) | ||
} | ||
|
||
return resultLines | ||
} | ||
|
||
const chunkifyString = (messageText, maxLength, delimiter) => { | ||
if (messageText.length <= maxLength) { | ||
return [messageText] | ||
} | ||
|
||
delimiter = delimiter || '\n' | ||
const messageLines = messageText.split(delimiter) | ||
|
||
return chunkifyArray(messageLines, maxLength, delimiter) | ||
} | ||
|
||
module.exports = { | ||
chunkifyArray, | ||
chunkifyString | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.