Sha256: 9d5cbee8050b580d28fc1de92987ee0237cf609415da8dc781920074f278c016

Contents?: true

Size: 1.01 KB

Versions: 165

Compression:

Stored size: 1.01 KB

Contents

'use strict';

const stringReplaceAll = (string, substring, replacer) => {
	let index = string.indexOf(substring);
	if (index === -1) {
		return string;
	}

	const substringLength = substring.length;
	let endIndex = 0;
	let returnValue = '';
	do {
		returnValue += string.substr(endIndex, index - endIndex) + substring + replacer;
		endIndex = index + substringLength;
		index = string.indexOf(substring, endIndex);
	} while (index !== -1);

	returnValue += string.substr(endIndex);
	return returnValue;
};

const stringEncaseCRLFWithFirstIndex = (string, prefix, postfix, index) => {
	let endIndex = 0;
	let returnValue = '';
	do {
		const gotCR = string[index - 1] === '\r';
		returnValue += string.substr(endIndex, (gotCR ? index - 1 : index) - endIndex) + prefix + (gotCR ? '\r\n' : '\n') + postfix;
		endIndex = index + 1;
		index = string.indexOf('\n', endIndex);
	} while (index !== -1);

	returnValue += string.substr(endIndex);
	return returnValue;
};

module.exports = {
	stringReplaceAll,
	stringEncaseCRLFWithFirstIndex
};

Version data entries

165 entries across 123 versions & 8 rubygems

Version Path
immosquare-cleaner-0.1.68 node_modules/chalk/source/util.js
immosquare-cleaner-0.1.67 node_modules/chalk/source/util.js
immosquare-cleaner-0.1.66 node_modules/chalk/source/util.js
immosquare-cleaner-0.1.65 node_modules/chalk/source/util.js
immosquare-cleaner-0.1.64 node_modules/chalk/source/util.js
immosquare-cleaner-0.1.63 node_modules/chalk/source/util.js
rapid_stack-0.2.0 templates/frontend/node_modules/chalk/source/util.js
rapid_stack-0.1.1 templates/FrontEnd/node_modules/chalk/source/util.js
rapid_stack-0.1.0 templates/FrontEnd/node_modules/chalk/source/util.js
immosquare-cleaner-0.1.62 node_modules/chalk/source/util.js
immosquare-cleaner-0.1.61 node_modules/chalk/source/util.js
immosquare-cleaner-0.1.60 node_modules/chalk/source/util.js
immosquare-cleaner-0.1.59 node_modules/chalk/source/util.js
immosquare-cleaner-0.1.58 node_modules/chalk/source/util.js
immosquare-cleaner-0.1.57 node_modules/chalk/source/util.js
immosquare-cleaner-0.1.56 node_modules/chalk/source/util.js
immosquare-cleaner-0.1.55 node_modules/chalk/source/util.js
immosquare-cleaner-0.1.54 node_modules/chalk/source/util.js
immosquare-cleaner-0.1.53 node_modules/chalk/source/util.js
immosquare-cleaner-0.1.52 node_modules/chalk/source/util.js