css-time-sort
TypeScript icon, indicating that this package has built-in type declarations

2.0.1 • Public • Published

css-time-sort

Sort an array of CSS <time> values.

Installation

npm install css-time-sort

Usage

import { convert, compare } from "css-time-sort";

// Using `compare` will sort an array from short to long times:
let result = ["3s", "2ms"].sort(compare); // ["2ms", "3s"]

// Converting time-like values converts the input to ms:
convert("1s"); // 1000
convert("1ms"); // 1
convert("+2ms"); // 2
convert("var(--foo)"); // Number.MAX_SAFE_INTEGER - 1
convert("bars"); // Number.MAX_SAFE_INTEGER

Notes

  • var(--my-duration) will be converted to Number.MAX_SAFE_INTEGER - 1 so they will end up send-to-last when sorting an array
  • Values that can not be converted to a number properly are converted to Number.MAX_SAFE_INTEGER so they will end up last when sorting an array

Related projects

  • css-unit-sort - Sort css values no matter the unit, by CSSStats
  • CSS Analyzer - A CSS analyzer that goes through your CSS to find all kinds of relevant statistics.
  • CSS Code Quality Analyzer - A Code Quality analyzer that tells you how maintainable, complex and performant your CSS is
  • Wallace CLI - CLI tool for @projectwallace/css-analyzer
  • Color Sorter - Sort CSS colors by hue, saturation, lightness and opacity

Dependents (0)

Package Sidebar

Install

npm i css-time-sort

Weekly Downloads

123

Version

2.0.1

License

MIT

Unpacked Size

12.6 kB

Total Files

12

Last publish

Collaborators

  • bartveneman