Home / File/ compare-breakpoints.ts — tailwindcss Source File

compare-breakpoints.ts — tailwindcss Source File

Architecture documentation for compare-breakpoints.ts, a typescript file in the tailwindcss codebase. 0 imports, 3 dependents.

File typescript Oxide Scanner 3 dependents 1 functions

Entity Profile

Dependency Diagram

graph LR
  c05975bc_af4f_b1a7_fc10_2de6cfa57ccd["compare-breakpoints.ts"]
  7a8b38fe_f674_f253_e4c8_9043c8b072e0["container.ts"]
  7a8b38fe_f674_f253_e4c8_9043c8b072e0 --> c05975bc_af4f_b1a7_fc10_2de6cfa57ccd
  ffde8eb7_7def_91ee_918c_be4f250f76a2["utilities.ts"]
  ffde8eb7_7def_91ee_918c_be4f250f76a2 --> c05975bc_af4f_b1a7_fc10_2de6cfa57ccd
  b638ddb2_c057_1f3c_8a1a_4993ad80cd58["variants.ts"]
  b638ddb2_c057_1f3c_8a1a_4993ad80cd58 --> c05975bc_af4f_b1a7_fc10_2de6cfa57ccd
  style c05975bc_af4f_b1a7_fc10_2de6cfa57ccd fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

export function compareBreakpoints(a: string, z: string, direction: 'asc' | 'desc') {
  if (a === z) return 0

  // Assumption: when a `(` exists, we are dealing with a CSS function.
  //
  // E.g.: `calc(100% - 1rem)`
  let aIsCssFunction = a.indexOf('(')
  let zIsCssFunction = z.indexOf('(')

  let aBucket =
    aIsCssFunction === -1
      ? // No CSS function found, bucket by unit instead
        a.replace(/[\d.]+/g, '')
      : // CSS function found, bucket by function name
        a.slice(0, aIsCssFunction)

  let zBucket =
    zIsCssFunction === -1
      ? // No CSS function found, bucket by unit
        z.replace(/[\d.]+/g, '')
      : // CSS function found, bucket by function name
        z.slice(0, zIsCssFunction)

  let order =
    // Compare by bucket name
    (aBucket === zBucket ? 0 : aBucket < zBucket ? -1 : 1) ||
    // If bucket names are the same, compare by value
    (direction === 'asc' ? parseInt(a) - parseInt(z) : parseInt(z) - parseInt(a))

  // If the groups are the same, and the contents are not numbers, the
  // `order` will result in `NaN`. In this case, we want to make sorting
  // stable by falling back to a string comparison.
  //
  // This can happen when using CSS functions such as `calc`.
  //
  // E.g.:
  //
  // - `min-[calc(100%-1rem)]` and `min-[calc(100%-2rem)]`
  // - `@[calc(100%-1rem)]` and `@[calc(100%-2rem)]`
  //
  // In this scenario, we want to alphabetically sort `calc(100%-1rem)` and
  // `calc(100%-2rem)` to make it deterministic.
  if (Number.isNaN(order)) {
    return a < z ? -1 : 1
  }

  return order
}

Domain

Subdomains

Frequently Asked Questions

What does compare-breakpoints.ts do?
compare-breakpoints.ts is a source file in the tailwindcss codebase, written in typescript. It belongs to the Oxide domain, Scanner subdomain.
What functions are defined in compare-breakpoints.ts?
compare-breakpoints.ts defines 1 function(s): compareBreakpoints.
What files import compare-breakpoints.ts?
compare-breakpoints.ts is imported by 3 file(s): container.ts, utilities.ts, variants.ts.
Where is compare-breakpoints.ts in the architecture?
compare-breakpoints.ts is located at packages/tailwindcss/src/utils/compare-breakpoints.ts (domain: Oxide, subdomain: Scanner, directory: packages/tailwindcss/src/utils).

Analyze Your Own Codebase

Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.

Try Supermodel Free