UNPKG

filetyperjs

Version:
29 lines (20 loc) 982 B
function remove(string,partToRemove,options){ var partUppercase = partToRemove.toUpperCase(); var occurenceCount = (string.toUpperCase().match(/partUppercase/g) || []).length; var result; if(typeof options == "string"){ console.error("The options parameter only accepts integers. You can use the integer to remove a specific occurence of the part you want to remove. \n For example, if you provide a string which contains a substring 4 times and specify the options parameter to be 1, only the first occurence of the substring will be deleted. \n Defaults to removing all occurences." ); }else{ result = string.split(partToRemove).join(''); return result; } } function toNumber(string){ try{ return parseInt(string); }catch(err){ console.log("An unexpected error occured! \n" +err); } } module.exports.remove = remove; module.exports.toNumber = toNumber;