How to use the ts-api-guardian.publicApi function in ts-api-guardian

To help you get started, we’ve selected a few ts-api-guardian examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github angular / angular / tools / public_api_guard / public_api_spec.ts View on Github external
function checkPublicApi(file: string, expected: string[]) {
  const sortedActual = publicApi('modules/' + file).sort();
  const sortedExpected = expected.slice().sort((a: string, b: string) => a.localeCompare(b));
  const unsorted = expected.find((element, index) => element !== sortedExpected[index]);
  const missing = sortedActual.filter((i) => sortedExpected.indexOf(i) < 0);
  const extra = sortedExpected.filter((i) => sortedActual.indexOf(i) < 0);

  // console.log(sortedActual.join('\',\n  \''));
  if (unsorted) {
    fail(
        `The array of expected APIs is incorrectly sorted starting at element:\n    ${unsorted}` +
        `\n\nexpected: ${sortedActual.join("\n")}`);
  }


  if (missing.length > 0) {
    console.log('=================================================================');
    console.log('=================================================================');

ts-api-guardian

Guards the API of TypeScript libraries!

MIT
Latest version published 4 years ago

Package Health Score

62 / 100
Full package analysis

Popular ts-api-guardian functions