https://github.com/projectwallace/css-time-sort
Sort an array of CSS <time> values.
https://github.com/projectwallace/css-time-sort
Last synced: 10 months ago
JSON representation
Sort an array of CSS <time> values.
- Host: GitHub
- URL: https://github.com/projectwallace/css-time-sort
- Owner: projectwallace
- License: mit
- Created: 2019-12-14T20:54:38.000Z (over 6 years ago)
- Default Branch: master
- Last Pushed: 2024-05-05T08:26:30.000Z (about 2 years ago)
- Last Synced: 2024-05-22T14:08:14.199Z (about 2 years ago)
- Language: JavaScript
- Homepage: https://www.projectwallace.com/oss
- Size: 76.2 KB
- Stars: 2
- Watchers: 3
- Forks: 1
- Open Issues: 1
-
Metadata Files:
- Readme: readme.md
- License: license
Awesome Lists containing this project
README
## Installation
```sh
npm install css-time-sort
```
## Usage
```js
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](https://github.com/cssstats/cssstats/tree/master/packages/css-unit-sort) - Sort css values no matter the unit, by CSSStats
- [CSS Analyzer](https://github.com/projectwallace/css-analyzer) - A CSS analyzer that goes through your CSS to find all kinds of relevant statistics.
- [CSS Code Quality Analyzer](https://github.com/projectwallace/css-code-quality) -
A Code Quality analyzer that tells you how maintainable, complex and performant your CSS is
- [Wallace CLI](https://github.com/projectwallace/wallace-cli) - CLI tool for
@projectwallace/css-analyzer
- [Color Sorter](https://github.com/projectwallace/color-sorter) - Sort CSS colors
by hue, saturation, lightness and opacity