Skip to content

Instantly share code, notes, and snippets.

Avatar
🏠
Working from home

Lewis LE lewisle

🏠
Working from home
View GitHub Profile
View strictEquals.js
/**
* Reinvent ===
* @ref [Equality comparisons and sameness](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Equality_comparisons_and_sameness)
* @ref [JavaScript Equality Table](https://dorey.github.io/JavaScript-Equality-Table/)
*/
export const strictEquals = (a, b) => {
if (typeof a == 'number' && typeof b == 'number') {
if (isNaN(a) && isNaN(b)) {
return false;
} else if ((Object.is(a, 0) && Object.is(b, -0)) || (Object.is(a, -0) && Object.is(b, 0))) {
View serializeCSS.ts
function serializeCSS(cssProperties: CSSProperties | undefined): string {
if (!cssProperties) return '';
let cssString = '';
for (const [key, value] of Object.entries(cssProperties)) {
cssString += key.replace(/([A-Z])/g, (g) => `-${g[0].toLowerCase()}`) + ':' + value + ';';
}
return cssString;
}