lodash#result TypeScript Examples

The following examples show how to use lodash#result. 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: project-stats.component.ts    From barista with Apache License 2.0 5 votes vote down vote up
ngOnInit() {
    this.isLoadingLicenseData = true;
    this.isLoadingSeverityData = true;
    this.isLoadingVulnerabilityData = true;
    if (this.licenseData$) {
      this.licenseData$
        .pipe(
          first(),
          map(items => {
            const data: ChartElementDto[] = _.map(items, (item: any) => {
              return {'name': item.license.name, 'value': Number(item.count)};
            });
            data.sort((x, y) => {
              // inverted so that higher numbers are first
              return -(x.value - y.value);
            });
            return data;
          }),
        )
        .subscribe(data => {
          this.licenseData = data;
          this.isLoadingLicenseData = false;
        });
    }

    if (this.vulnerabilityData$) {
      this.vulnerabilityData$
        .pipe(
          first(),
          map(items => {
            const data: ChartElementDto[] = _.map(items, (item: any) => {
              return {'name': item.path, 'value': Number(item.count)};
            });
            data.sort((x, y) => {
              // inverted so that higher numbers are first
              return -(x.value - y.value);
            });
            return data;
          }),
        )
        .subscribe(data => {
          this.vulnerabilityData = data;
          this.isLoadingVulnerabilityData = false;
        });
    }

    let severityLabels: string[] = ['LOW', 'MODERATE', 'MEDIUM', 'HIGH', 'CRITICAL'];
    if (this.severityData$) {
      this.severityData$
        .pipe(
          first(),
          map(items => {
            var data: ChartElementDto[] = _.map(items, (item: any) => {
              return {'name': item.severity, 'value': Number(item.count)};
            });
            if(data.length !== 0){
              let dataNames: string[] = data.map((item) => item.name.toUpperCase());
              let result: string[] = severityLabels.filter(item => dataNames.indexOf(item) < 0);
                return data 
              .concat(result.map((item) => {
                return {'name': item.toUpperCase(), 'value': 0}
              }))
              .sort((a, b) => {
                return -(severityLabels.indexOf(a.name) - severityLabels.indexOf(b.name))
              });
            }
          }),
        )
        .subscribe(data => {
          this.severityData = data;
          this.isLoadingSeverityData = false;
        });
    }
  }
Example #2
Source File: common-commands.ts    From kliveide with MIT License 4 votes vote down vote up
compileCodeCommand: IKliveCommand = {
  commandId: "klive.compileCode",
  title: "Compiles the code",
  icon: "combine",
  execute: async (context) => {
    if (!context.resource) {
      return;
    }
    switch (context.process) {
      case "main":
      case "emu":
        signInvalidContext(context);
        break;
      case "ide":
        // --- Display compiler output in the Build output pane
        const outputPaneService = getOutputPaneService();
        const buildPane = outputPaneService.getPaneById(BUILD_OUTPUT_PANE_ID);

        // --- Switch to the output pane
        const toolAreaService = getToolAreaService();
        const outputTool = toolAreaService.getToolPanelById(OUTPUT_TOOL_ID);
        if (outputTool) {
          toolAreaService.setActiveTool(outputTool);
          if (buildPane) {
            await new Promise((r) => setTimeout(r, 20));
            outputPaneService.setActivePane(buildPane);
          }
        }

        // --- Start the compilation process
        const buffer = buildPane.buffer;
        buffer.clear();
        buffer.resetColor();
        buffer.writeLine(`Compiling ${context.resource}`);
        const start = new Date().valueOf();

        // --- Get the language
        const language = await getDocumentService().getCodeEditorLanguage(
          context.resource
        );

        // --- Invoke the compiler
        try {
          const response = await sendFromIdeToEmu<CompileFileResponse>({
            type: "CompileFile",
            filename: context.resource,
            language,
          });
          if (response.failed) {
            buffer.color("bright-red");
            buffer.writeLine(`Compilation failed: ${response.failed}`);
            buffer.resetColor();
            break;
          }
          if ((response.result?.errors?.length ?? 0) !== 0) {
            for (const item of response.result.errors) {
              buffer.color(item.isWarning ? "bright-yellow" : "bright-red");
              buffer.write(item.errorCode);
              buffer.resetColor();
              buffer.write(`: ${item.message} `);
              buffer.color("cyan");
              const location =
                item.startColumn === 0 && item.endColumn === 0
                  ? `${item.fileName}:[${item.line}]`
                  : `${item.fileName}:[${item.line}:${item.startColumn}-${item.endColumn}]`;
              buffer.writeLine(location, <IHighlightable>{
                highlight: true,
                title: `Click to locate the error\n${item.message}`,
                errorItem: item,
              });
              buffer.resetColor();
            }
          }

          const output = response.result;

          // --- Summary
          const errorCount = output.errors.length;
          if (!response.failed && errorCount === 0) {
            const debugOut = (response.result as SimpleAssemblerOutput)
              .debugMessages;
            if (debugOut) {
              buffer.color("bright-yellow");
              debugOut.forEach((i) => buffer.writeLine(i));
            }
            buffer.bold(true);
            buffer.color("bright-green");
            buffer.writeLine("Compiled successfully.");
            buffer.bold(false);
            buffer.resetColor();
          } else {
            buffer.bold(true);
            buffer.color("bright-red");
            if (response.failed) {
              buffer.writeLine(`Compilation failed: ${response.failed}`);
            } else {
              buffer.writeLine(
                `Compiled with ${errorCount} error${errorCount > 1 ? "s" : ""}.`
              );
            }
            buffer.bold(false);
            buffer.resetColor();
          }
          // --- Execution time
          buffer.writeLine(`Compile time: ${new Date().valueOf() - start}ms`);

          // --- Take care to resolve source code breakpoints
          resolveBreakpoints();
          break;
        } catch (err) {
          buffer.color("bright-red");
          buffer.writeLine(`Unexpected error: ${err}`);
        }
    }
  },
}