/** * Greps a file by its content, checks if Scenario or Feature text' * matches the grep text. */ const grepFile = (file, grep) => { const contents = fs.readFileSync(file); const pattern = new RegExp(`((Scenario|Feature)\(.*${grep}.*\))`, 'g'); // <- How future proof/solid is this? return !!pattern.exec(contents); }
function isChinese(string) { var req = /[\u4E00-\u9FA5]|[\uFE30-\uFFA0]/gi; if (!req.exec(string)) { return false; } else { return true; } }
api._app.pages.hooks.parseComponent.for('md').tap('VueRemark', source => { const pageQueryRE = /<page-query>([^</]+)<\/page-query>/ const ast = this.remark.processor.parse(source) return { pageQuery: ast.children .filter(node => node.type === 'html' && /^<page-query/.test(node.value)) .map(node => pageQueryRE.exec(node.value)[1]) .pop() } })
const parseReason = function (message) { const regexBecause = /because \[(.*?)(\]|$)/; let parsedMessage = message; if (regexBecause.test(message)) { parsedMessage = regexBecause.exec(message)[1]; } if (regexBecause.test(parsedMessage)) { parsedMessage = parseReason(parsedMessage); } return parsedMessage; }
function getUrlParameter( name: string ): string { if ( typeof window === 'undefined' ) { return ''; } name = name.replace( /[[]/g, '\\[' ).replace( /[\]]/g, '\\]' ); const regex = new RegExp( '[\\?&]' + name + '=([^&#]*)' ); const results = regex.exec( window.location.search ); return results === null ? '' : decodeURIComponent( results[ 1 ].replace( /\+/g, ' ' ) ); }
getQueryText( element ) { if ( ! element.value ) { return null; } const textBeforeCaret = element.value.slice( 0, this.getCaretPosition( element ) ); const match = suggestionMatcher.exec( textBeforeCaret ); if ( ! match ) { return null; } const [ , suggestion ] = match; return escapeRegExp( suggestion ); }
ExtractAnswer(parseTree) { let multiLineAnswer = parseTree.qnaDefinition().qnaAnswerBody().multiLineAnswer().getText().trim(); // trim first and last line let answerRegexp = /^```(markdown)?\r*\n(?<answer>(.|\n|\r\n|\t| )*)\r?\n.*?```$/gim; let answer = answerRegexp.exec(multiLineAnswer); return answer.groups.answer !== undefined ? answer.groups.answer : ''; }
function cleanupLocalCache() { const notes = getAllNotes( store.getState() ); const currentNoteIds = notes.map( property( 'id' ) ); getLocalKeys() .map( ( key ) => obsoleteKeyPattern.exec( key ) ) .filter( ( match ) => match && ! currentNoteIds.includes( match[ 1 ] ) ) .forEach( safelyRemoveKey ); }
ExtractSourceInfo(parseTree) { let srcAssignment = parseTree.qnaDefinition().qnaSourceInfo() if (srcAssignment) { let srcRegExp = /^[ ]*\>[ ]*!#[ ]*@qna.pair.source[ ]*=[ ]*(?<sourceInfo>.*?)$/gmi; let srcParsed = srcRegExp.exec(srcAssignment.getText().trim()); return srcParsed.groups.sourceInfo || QNA_GENERIC_SOURCE; } return QNA_GENERIC_SOURCE }
function fetchChangelogBody (version) { return fetchChangelog(version).then((section) => { const rxSectionBody = /(### Notable [\s\S]*)/ const matches = rxSectionBody.exec(section) return matches ? matches[1] : Promise.reject(new Error(`Could not find changelog body of ${version} release`)) }) }
const matchAll = (pattern, src) => { const matches = []; let match; const regexPatternWithGlobal = RegExp(pattern, 'g'); while ((match = regexPatternWithGlobal.exec(src))) { const [, group] = match; matches.push(_.trim(group)); } return matches; }
/** * @desc Return the function name from a JS function string * @param {String} funcStr - String of JS function to validate * @returns {String} Function name string (if found) */ getFunctionNameFromString(funcStr) { const result = FUNCTION_NAME.exec(funcStr); if (!result || result.length === 0) return null; return result[1].trim(); }
function findAuthorLogin (version, section) { // looking for the @author part of the release header, eg: // ## 2016-03-08, Version 5.8.0 (Stable). @Fishrock123 // ## 2015-10-13, Version 4.2.1 'Argon' (LTS), @jasnell // ## 2015-09-08, Version 4.0.0 (Stable), @rvagg const rxReleaseAuthor = /^## .*? \([^)]+\)[,.] @(\S+)/ const matches = rxReleaseAuthor.exec(section) return matches ? matches[1] : Promise.reject(new Error(`Couldn't find @author of ${version} release :(`)) }
api._app.pages.hooks.parseComponent.for('md').tap('VueRemark', source => { const pageQueryRE = /<page-query>([^</]+)<\/page-query>/ const ast = this.remark.processor.parse(source) return { pageQuery: ast.children .filter(node => node.type === 'html' && /^<page-query/.test(node.value)) .map(node => pageQueryRE.exec(node.value)[1]) .pop() } })
function fetchVersionPolicy (version) { return fetchChangelog(version).then((section) => { // matches the policy for a given version (Stable, LTS etc) in the changelog // ## 2015-10-07, Version 4.2.0 'Argon' (LTS), @jasnell // ## 2015-12-04, Version 0.12.9 (LTS), @rvagg const rxPolicy = /^## ?\d{4}-\d{2}-\d{2}, Version [^(].*\(([^)]+)\)/ const matches = rxPolicy.exec(section) return matches ? matches[1] : Promise.reject(new Error(`Could not find version policy of ${version} in its changelog`)) }) }