1.0.7 • Published 3 years ago
jsmp-infra-wecreus v1.0.7
This is a dummy npm package for training purposes.
Features
Split array into chunks with specified length.
Replace any character or sequence of characters in a string.
Installation
Install via Node.js:
$ npm install jsmp-infra-wecreus
Import as Node.js module:
const { splitArray, stringReplace } = require('jsmp-infra-wecreus');
Use
splitArray(array, size, [preserve = true]);
Function returns an array of elements split into groups the length of size
Preserve
indicates if uneven chunk should be included in the result. Defaults to true
;
Example:
const resultPreserve = splitArray(["sample1", "sample2", "sample3", "sample4", "sample5"], 2); // [["sample1", "sample2"], ["sample3", "sample4"], ["sample5"]]
const result = splitArray(["sample1", "sample2", "sample3", "sample4", "sample5"], 2, false); // [["sample1", "sample2"], ["sample3", "sample4"]]
stringReplace(string, stringToReplace, [replacement = '']);
Function replaces stringToReplace
found in string
with replacement
Example:
const result = stringReplace('test', 'es'); // "tt"
const resultReplace = stringReplace('test', 'st', 'sting'); // "testing"