dokkie
Version:
Create good looking documentation from your Readme
33 lines • 1.07 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.splice = exports.findIndexAfter = exports.nthIndex = exports.lastIndex = exports.getIndexes = void 0;
exports.getIndexes = (source, find) => {
const result = [];
let i = 0;
while (i < source.length) {
if (source.substring(i, i + find.length) === find) {
result.push(i);
i += find.length;
}
else {
i++;
}
}
return result;
};
exports.lastIndex = (source, find) => {
const result = exports.getIndexes(source, find);
return Math.max(...result) - 1;
};
exports.nthIndex = (source, find, nth) => {
const result = exports.getIndexes(source, find);
return result[nth];
};
exports.findIndexAfter = (source, find, after) => {
const result = exports.getIndexes(source, find).filter((i) => i > after);
return result[0];
};
exports.splice = (insert, idx, rem, str) => {
return insert.slice(0, idx) + str + insert.slice(idx + Math.abs(rem));
};
//# sourceMappingURL=helpers.js.map