UNPKG

@mikezimm/npmfunctions

Version:
46 lines 2.05 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.splitByHashNumbers = void 0; /** * 2022-01-19 * getStringArrayWithHashNumbers was originally built for Help Panel in Drilldown webpart. * The basic purpose is to be able to just type text and use #xx and have it create link to github repo. * If you pass in a string, it will break it into an array of strings split by any #23 like github issues references. * * @param testString - string to parse * @param matches - strings to parse the string by (like: ['#2','#23','#122']) */ function splitByHashNumbers(testString, matches) { //Replace any # with link to issue //First find all instances of # and digits // console.log('getStringArrayWithHashNumbers matches: ', matches); //Removed 2022-02-08 var subSpans = []; if (matches === null) { subSpans.push(testString); return subSpans; } var partialString = testString + ''; matches.map(function (thisMatch, i) { // console.log('getStringArrayWithHashNumbers partialString: ',partialString); //Removed 2022-02-08 var idx = partialString.indexOf(thisMatch); if (idx === 0) { //This found string at beginning subSpans.push("".concat(thisMatch)); partialString = partialString.substring(thisMatch.length); // console.log( `${i} ${thisMatch}`, subSpans, 'idx===0'); //Removed 2022-02-08 } else if (idx > 0) { //This found string after beginning subSpans.push(partialString.substring(0, idx)); subSpans.push("".concat(thisMatch)); // console.log( `${i} ${thisMatch}`, subSpans, 'idx>0 '); //Removed 2022-02-08 partialString = partialString.substring(idx + thisMatch.length); } }); if (partialString) { subSpans.push(partialString); } return subSpans; } exports.splitByHashNumbers = splitByHashNumbers; //# sourceMappingURL=functions.js.map