JT

Feed

snippet

Zip two arrays together into an array of pairs, stopping at the shorter one.

const zip = <A, B>(a: A[], b: B[]): [A, B][] =>
Array.from({ length: Math.min(a.length, b.length) }, (\_, i) => [a[i], b[i]]);
typescript
snippet

A utility class that clamps text to a set number of lines with an ellipsis.

.line-clamp {
display: -webkit-box;
-webkit-box-orient: vertical;
-webkit-line-clamp: var(--lines, 3);
overflow: hidden;
}
css
snippet

Group an array of objects by a key. Returns a Map to preserve insertion order.

const groupBy = <T, K extends PropertyKey>(
items: T[],
key: (item: T) => K,
): Map<K, T[]> =>
items.reduce((map, item) => {
const k = key(item);
map.set(k, [...(map.get(k) ?? []), item]);
return map;
}, new Map<K, T[]>());
typescript
link

Schema-validatie met uitstekende TypeScript-ondersteuning. Onmisbaar voor type-veilige content collections in Astro.