Created
May 13, 2025 15:53
-
-
Save nikoheikkila/069de0693a8d7ce436eb32478b2cc549 to your computer and use it in GitHub Desktop.
node:assert example
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* Requires '@types/node' to be installed */ | |
import { deepEqual as equal } from 'node:assert'; | |
const test = () => { | |
equal(pixels(), ''); | |
equal(pixels(0), '0'); | |
equal(pixels(1), '1px'); | |
equal(pixels(-1), '-1px'); | |
equal(pixels(0.5), '1px'); | |
equal(pixels(0.4), '0'); | |
equal(pixels(0, 1), '0 1px'); | |
equal(pixels(0, 1, 2), '0 1px 2px'); | |
equal(pixels(1, 2, 3, 4), '1px 2px 3px 4px'); | |
} | |
const pixels = (...values: number[]): string => | |
values | |
.map(Math.round) | |
.map(toPixel) | |
.join(" "); | |
const toPixel = (value: number): string => | |
value === 0 | |
? '0' | |
: `${value}px`; | |
test(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment