lodash#invert TypeScript Examples

The following examples show how to use lodash#invert. 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: analysis-utils.ts    From prism-frontend with MIT License 7 votes vote down vote up
export function getAnalysisTableColumns(
  analysisResult?: AnalysisResult,
  withLocalName = false,
): Column[] {
  if (!analysisResult || analysisResult instanceof ExposedPopulationResult) {
    return [];
  }
  if ('tableColumns' in analysisResult) {
    return (analysisResult as PolygonAnalysisResult).tableColumns;
  }
  const { statistic } = analysisResult;
  const baselineLayerTitle = analysisResult.getBaselineLayer().title;

  return [
    {
      id: withLocalName ? 'localName' : 'name',
      label: 'Name',
    },
    {
      id: statistic,
      label: invert(AggregationOperations)[statistic], // invert maps from computer name to display name.
      format: value => getRoundedData(value as number),
    },
    {
      id: 'baselineValue',
      label: baselineLayerTitle,
      format: (value: number | string) => value.toLocaleString('en-US'),
    },
  ];
}
Example #2
Source File: sql-formatter.ts    From querybook with Apache License 2.0 6 votes vote down vote up
function tokensToText(tokens: IToken[]) {
    let statementText = '';
    const templateTagToId = {};
    let lastToken: IToken = null;

    for (const token of tokens) {
        if (lastToken) {
            if (token.line !== lastToken.line) {
                statementText += '\n';
            } else if (token.start > lastToken.end) {
                statementText += ' ';
            }
        }

        if (skipTokenType.has(token.type)) {
            if (!(token.text in templateTagToId)) {
                templateTagToId[token.text] = uniqueId('__TEMPLATED_TAG_');
            }
            statementText += templateTagToId[token.text];
        } else {
            statementText += token.text;
        }
        lastToken = token;
    }

    return {
        statementText,
        idToTemplateTag: invert(templateTagToId),
    };
}
Example #3
Source File: keycodes.ts    From roam-toolkit with MIT License 5 votes vote down vote up
CODE_TO_KEY: {[key: string]: string} = invert(KEY_TO_CODE)