css-time-sort
v2.0.2
Published
Sort an array of CSS <time> values
Downloads
131
Maintainers
Readme
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 toNumber.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