lodash#takeWhile TypeScript Examples

The following examples show how to use lodash#takeWhile. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: bitrise_analyzer.ts    From CIAnalyzer with MIT License 6 votes vote down vote up
parseBuildLog(BuildLogResponse: BuildLogResponse): StepLog[] {
    // Extract chunk that include summary table 
    const chunks = dropWhile(BuildLogResponse.log_chunks, (chunk) => !chunk.chunk.includes('bitrise summary'))
    if (!chunks) return []

    let rows = chunks.flatMap((chunk) => chunk.chunk.split('\n'))

    // Filter summary table rows only
    rows = dropWhile(rows, (row) => !row.includes('bitrise summary'))
    rows = takeWhile(rows, (row) => !row.includes('Total runtime'))

    const steps = rows
      // Filter row that include name and step
      .filter((row) => row.match(/\d+\s(sec|min)/))
      .map((row) => {
        // Step name
        const names = [...row.matchAll(/;1m(?<name>.+?)\u001b/g)].map((match) => match.groups?.name ?? '')
        const name = maxBy(names, (name) => name.length)
        // Duration
        const duration = row.match(/\d+(\.\d+)?\s(sec|min)/)

        return {
          name: name ? name.trim() : '',
          duration: duration ? duration[0].trim() : ''
        }
      })

    return steps
  }