All Downloads are FREE. Search and download functionalities are using the official Maven repository.

node_modules.apollo-codegen.src.utilities.printing.ts Maven / Gradle / Ivy

There is a newer version: 3.3.1
Show newest version
// Code generation helper functions copied from graphql-js (https://github.com/graphql/graphql-js)

/**
 * Given maybeArray, print an empty string if it is null or empty, otherwise
 * print all items together separated by separator if provided
 */
export function join(maybeArray?: any[], separator?: string) {
  return maybeArray ? maybeArray.filter(x => x).join(separator || '') : '';
}

/**
 * Given array, print each item on its own line, wrapped in an
 * indented "{ }" block.
 */
export function block(array: any[]) {
  return array && array.length !== 0 ?
    indent('{\n' + join(array, '\n')) + '\n}' :
    '{}';
}

/**
 * If maybeString is not null or empty, then wrap with start and end, otherwise
 * print an empty string.
 */
export function wrap(start: string, maybeString?: string, end?: string) {
  return maybeString ?
    start + maybeString + (end || '') :
    '';
}

export function indent(maybeString?: string) {
  return maybeString && maybeString.replace(/\n/g, '\n  ');
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy