or run

npx @tessl/cli init
Log in

Version

Tile

Overview

Evals

Files

docs

compatibility-analysis.mdcompatibility-data.mdentry-points.mdindex.mdversion-utilities.md
tile.json

compatibility-analysis.mddocs/

Compatibility Analysis

Core compatibility analysis functionality that determines which core-js modules are needed for specified browser targets.

Capabilities

Main Compatibility Function

Analyzes browser targets and returns required core-js modules with detailed target information.

/**
 * Analyze browser targets and return required core-js modules
 * @param options - Configuration options for compatibility analysis
 * @returns Object containing required modules list and target details
 */
function compat(options?: CompatOptions): CompatOutput;

interface CompatOptions {
  /** Entry/module/namespace filter - string, RegExp, or array of them */
  modules?: Modules;
  /** Blacklist filter - string, RegExp, or array of them */
  exclude?: Modules;
  /** Browserslist query or target environment object */
  targets?: Targets | BrowserslistQuery;
  /** Core-js version to use (default: latest) */
  version?: string;
  /** Show modules NOT required for targets (default: false) */
  inverse?: boolean;
  /** @deprecated Use modules instead */
  filter?: Modules;
}

interface CompatOutput {
  /** Array of required module names */
  list: ModuleName[];
  /** Target versions for each required module */
  targets: {
    [module: ModuleName]: {
      [target in Target]?: TargetVersion
    }
  };
}

Usage Examples:

const compat = require('core-js-compat');

// Basic usage with browserslist query
const result = compat({
  targets: '> 1%, not IE 11'
});

// Filter specific modules
const filtered = compat({
  targets: 'defaults',
  modules: ['es.array.at', 'es.object.has-own']
});

// Exclude certain modules  
const excluded = compat({
  targets: '> 0.25%',
  exclude: [/^web\./, 'es.symbol.async-dispose']
});

// Use specific core-js version
const versioned = compat({
  targets: 'chrome >= 90',
  version: '3.30.0'
});

// Inverse analysis (modules NOT needed)
const inverse = compat({
  targets: 'chrome >= 100',
  inverse: true
});

Module Filtering

Supports flexible module filtering using strings, regular expressions, and arrays.

Filter Types:

  • String: Matches entry points or module name prefixes

    • 'core-js/actual' - matches entry point
    • 'es.array' - matches all modules starting with 'es.array'
  • RegExp: Matches module names by pattern

    • /^es\./ - matches all ES standard modules
    • /async|await/ - matches modules containing 'async' or 'await'
  • Array: Combines multiple filters

    • ['es.array.at', /^web\./, 'esnext.array']

Usage Examples:

// Entry point filtering
const entryResult = compat({
  targets: '> 1%',
  modules: ['core-js/actual', 'core-js/stable']
});

// Prefix filtering  
const prefixResult = compat({
  targets: 'defaults',
  modules: ['es.array', 'es.object']
});

// Pattern filtering
const patternResult = compat({
  targets: '> 0.5%',
  modules: [/^esnext\./, /\.prototype\./]
});

// Combined filtering
const combinedResult = compat({
  targets: 'last 2 versions',
  modules: ['core-js/actual', /^web\./, 'es.promise']
});

Target Specification

Supports both browserslist queries and detailed target environment objects.

Browserslist Queries:

// Single query
const result1 = compat({ targets: '> 1%' });

// Multiple queries  
const result2 = compat({ targets: ['> 1%', 'not IE 11'] });

// Named queries
const result3 = compat({ targets: 'defaults' });

Environment Objects:

// Basic environment targets
const envResult = compat({
  targets: {
    chrome: '90',
    firefox: '88',
    safari: '14.0',
    node: 'current'
  }
});

// Advanced targeting with esmodules
const esModulesResult = compat({
  targets: {
    chrome: '80',
    esmodules: true  // Use ES modules baseline
  }
});

// Intersect with browserslist  
const intersectResult = compat({
  targets: {
    browsers: '> 1%',
    esmodules: 'intersect'
  }
});

Supported Target Environments:

interface Environments {
  android?: string | number;          // Android WebView
  bun?: string | number;             // Bun runtime
  chrome?: string | number;          // Chrome browser
  'chrome-android'?: string | number; // Chrome for Android
  deno?: string | number;            // Deno runtime
  edge?: string | number;            // Microsoft Edge
  electron?: string | number;        // Electron framework
  firefox?: string | number;         // Firefox browser
  'firefox-android'?: string | number; // Firefox for Android
  hermes?: string | number;          // Hermes JS engine
  ie?: string | number;              // Internet Explorer
  ios?: string | number;             // iOS Safari
  node?: string | number | 'current'; // Node.js
  opera?: string | number;           // Opera browser
  'opera-android'?: string | number;  // Opera for Android
  phantom?: string | number;         // PhantomJS
  quest?: string | number;           // Meta Quest Browser
  'react-native'?: string | number;  // React Native
  rhino?: string | number;           // Rhino JS engine
  safari?: string | number;          // Safari browser
  samsung?: string | number;         // Samsung Internet
}

Output Processing

The compat function returns detailed information about required modules and their target constraints.

Output Structure:

const result = compat({ targets: '> 1%' });

// result.list - Array of module names
console.log(result.list);
// ['es.array.at', 'es.object.has-own', 'es.array.find-last', ...]

// result.targets - Target constraints per module  
console.log(result.targets);
// {
//   'es.array.at': { ios: '14.5-14.8' },
//   'es.object.has-own': { ios: '14.5-14.8' },
//   'es.array.find-last': { firefox: '100', ios: '14.5-14.8' }
// }

Processing Examples:

const compat = require('core-js-compat');

const result = compat({
  targets: 'last 2 versions',
  modules: ['core-js/actual']
});

// Count required modules
console.log(`${result.list.length} modules required`);

// Find modules for specific targets
const iosModules = result.list.filter(module => 
  result.targets[module] && result.targets[module].ios
);

// Group by target
const byTarget = {};
result.list.forEach(module => {
  const moduleTargets = result.targets[module] || {};
  Object.keys(moduleTargets).forEach(target => {
    if (!byTarget[target]) byTarget[target] = [];
    byTarget[target].push(module);
  });
});

Error Handling

// Invalid core-js version
try {
  compat({ version: '2.6.0' }); // Only 3.x supported
} catch (error) {
  console.log(error); // RangeError: This version works only with core-js@3
}

// Invalid module filter
try {
  compat({ modules: 123 }); // Invalid type
} catch (error) {
  console.log(error); // TypeError: Specified invalid module name or pattern
}